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
  * 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;
Base class for Event Sourced entities that are not at the root of the aggregate. Instead of keeping track of uncommitted events themselves, these entities refer to their aggregate root to do that for them. A DomainEvent published in any of the entities in an Aggregate is published to all entities in the entire aggregate.

Allard Buijze
 public abstract class AbstractEventSourcedEntity {
     private volatile AbstractEventSourcedAggregateRoot aggregateRoot;

Returns a list of event sourced entities directly referenced by this entity.

The default implementation uses reflection to find references to AbstractEventSourcedEntity implementations.

It will look for them in the following locations:

a list of event sourced entities contained in this aggregate
         return ReflectionUtils.findFieldValuesOfType(thisAbstractEventSourcedEntity.class);

Register the aggregate root with this entity. The entity uses this aggregate root to report applied Domain Events. The aggregate root is responsible for tracking all applied events.

A parent entity is responsible for invoking this method on its child entities prior to propagating events to it. Typically, this means all entities have their aggregate root set before any actions are taken on it.

aggregateRootToRegister the root of the aggregate this entity is part of.
     protected void registerAggregateRoot(AbstractEventSourcedAggregateRoot aggregateRootToRegister) {
         if (this. != null && this. != aggregateRootToRegister) {
             throw new IllegalStateException("Cannot register new aggregate. "
                                                     + "This entity is already part of another aggregate");
         this. = aggregateRootToRegister;

Report the given event for handling in the current instance (this), as well as all the entities referenced by this instance.

event The event to handle
     void handleRecursively(DomainEvent event) {
         Collection<AbstractEventSourcedEntitychildEntities = getChildEntities();
         if (childEntities != null) {
             for (AbstractEventSourcedEntity entity : childEntities) {

Apply state changes based on the given event.

Note: Implementations of this method should *not* perform validation.

event The event to handle
     protected abstract void handle(DomainEvent event);

Apply the provided event. Applying events means they are added to the uncommitted event queue and forwarded to the handle(org.axonframework.domain.DomainEvent) event handler method} for processing.

Note that all entities part of the aggregate that this entity is part of are notified of the event.

event The event to apply
    protected void apply(DomainEvent event) {
New to GrepCode? Check out our FAQ X