Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2010-2011. Axon Framework
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.axonframework.eventsourcing;
Implementation of a snapshotter that uses the actual aggregate and its state to create a snapshot event. The motivation is that an aggregate always contains all relevant state. Therefore, storing the aggregate itself inside an event should capture all necessary information.

Author(s):
Allard Buijze
Since:
0.6
public class AggregateSnapshotter extends AbstractSnapshotter {
    @Override
    protected DomainEvent createSnapshot(String typeIdentifierDomainEventStream eventStream) {
        AggregateFactory<?> aggregateFactory = .get(typeIdentifier);
        DomainEvent firstEvent = eventStream.peek();
        AggregateIdentifier aggregateIdentifier = firstEvent.getAggregateIdentifier();
        EventSourcedAggregateRoot aggregate;
        if (firstEvent instanceof AggregateSnapshot) {
            aggregate = ((AggregateSnapshotfirstEvent).getAggregate();
        } else {
            aggregate = aggregateFactory.createAggregate(aggregateIdentifierfirstEvent);
        }
        aggregate.initializeState(eventStream);
        return new AggregateSnapshot<EventSourcedAggregateRoot>(aggregate);
    }

    
Sets the aggregate factory to use. The aggregate factory is responsible for creating the aggregates that should be stored within the AggegateSnapshots.

Parameters:
aggregateFactories The list of aggregate factories creating the aggregates to store. May not be null or contain any null values.
Throws:
java.lang.NullPointerException if aggregateFactories is null or if contains any null values.
    @Resource
    public void setAggregateFactories(List<AggregateFactory<?>> aggregateFactories) {
        for (AggregateFactory<?> factory : aggregateFactories) {
            this..put(factory.getTypeIdentifier(), factory);
        }
    }
New to GrepCode? Check out our FAQ X