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;
 
Repository that stores both a (JPA based) relational model of the current state of an aggregate and the events produced by that aggregate. When an aggregate is loaded, only the relational model is used to reconstruct the aggregate state.

As events are not used for reconstructing the aggregate state, there is no need for snapshots or upcasters. In some scenario's that could be a sensible choice.

Parameters:
<T> The type of aggregate stored in this repository. Must implement EventSourcedAggregateRoot.
Author(s):
Allard Buijze
Since:
1.0
 
 public class HybridJpaRepository<T extends EventSourcedAggregateRootextends GenericJpaRepository<T> {
 
     private EventStore eventStore;
     private String aggregateTypeIdentifier;

    
Initializes a Hybrid Repository that stored entities of the given aggregateType and the locking mechanism provided by the backend storage.

Parameters:
aggregateType The type of aggregate stored in this repository.
 
     public HybridJpaRepository(Class<T> aggregateType) {
         this(aggregateTypeaggregateType.getSimpleName());
     }

    
Initializes a Hybrid Repository that stored entities of the given aggregateType without locking. The events are appended to the event store under the given aggregateTypeIdentifier.

Parameters:
aggregateType The type of aggregate stored in this repository.
aggregateTypeIdentifier The type identifier to store events with
 
     public HybridJpaRepository(Class<T> aggregateTypeString aggregateTypeIdentifier) {
         this(aggregateTypeaggregateTypeIdentifier.);
     }

    
Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockingStrategy.

Parameters:
aggregateType The type of aggregate stored in this repository.
lockingStrategy The locking strategy to use when loading and storing aggregates
 
     public HybridJpaRepository(Class<T> aggregateTypeLockingStrategy lockingStrategy) {
         this(aggregateTypeaggregateType.getSimpleName(), lockingStrategy);
     }

    
Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockingStrategy.

Parameters:
aggregateType The type of aggregate stored in this repository.
aggregateTypeIdentifier The type identifier to store events with
lockingStrategy The locking strategy to use when loading and storing aggregates
 
     public HybridJpaRepository(Class<T> aggregateTypeString aggregateTypeIdentifier,
                                LockingStrategy lockingStrategy) {
         super(aggregateTypelockingStrategy);
         this. = aggregateTypeIdentifier;
     }
 
     @Override
     protected void doDeleteWithLock(T aggregate) {
         if ( != null) {
             .appendEvents(getTypeIdentifier(), aggregate.getUncommittedEvents());
         }
         super.doDeleteWithLock(aggregate);
     }
 
     @Override
     protected void doSaveWithLock(T aggregate) {
         if ( != null) {
             .appendEvents(getTypeIdentifier(), aggregate.getUncommittedEvents());
         }
        super.doSaveWithLock(aggregate);
    }

    
Returns the type identifier to use when appending events in the event store. Default to the simple class name of the aggregateType provided in the constructor.

Returns:
the type identifier to use when appending events in the event store.
    protected String getTypeIdentifier() {
        return ;
    }

    
The event store to which events are appended. This event store is not used to load events, as the aggregate's state is loaded from a relational model.

If no event store is configured, events are not appended.

Parameters:
eventStore The event store where events should be appended
    public void setEventStore(EventStore eventStore) {
        this. = eventStore;
    }
New to GrepCode? Check out our FAQ X