org.axonframework.eventsourcing
Class HybridJpaRepository<T extends AggregateRoot>

java.lang.Object
  extended by org.axonframework.repository.AbstractRepository<T>
      extended by org.axonframework.repository.LockingRepository<T>
          extended by org.axonframework.repository.GenericJpaRepository<T>
              extended by org.axonframework.eventsourcing.HybridJpaRepository<T>
Type Parameters:
T - The type of aggregate stored in this repository. Must implement EventSourcedAggregateRoot.
All Implemented Interfaces:
Repository<T>

public class HybridJpaRepository<T extends AggregateRoot>
extends GenericJpaRepository<T>

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.

Since:
1.0
Author:
Allard Buijze

Constructor Summary
HybridJpaRepository(javax.persistence.EntityManager entityManager, Class<T> aggregateType, LockManager lockManager)
          Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.
HybridJpaRepository(javax.persistence.EntityManager entityManager, Class<T> aggregateType, String aggregateTypeIdentifier, LockManager lockManager)
          Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.
HybridJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType)
          Initializes a Hybrid Repository that stored entities of the given aggregateType and the locking mechanism provided by the backend storage.
HybridJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, LockManager lockManager)
          Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.
HybridJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, String aggregateTypeIdentifier)
          Initializes a Hybrid Repository that stored entities of the given aggregateType without locking.
HybridJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, String aggregateTypeIdentifier, LockManager lockManager)
          Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.
 
Method Summary
protected  void doDeleteWithLock(T aggregate)
          Perform the actual deleting of the aggregate.
protected  void doSaveWithLock(T aggregate)
          Perform the actual saving of the aggregate.
protected  String getTypeIdentifier()
          Returns the type identifier to use when appending events in the event store.
 void setEventStore(EventStore eventStore)
          The event store to which events are appended.
 
Methods inherited from class org.axonframework.repository.GenericJpaRepository
doLoad, setForceFlushOnSave
 
Methods inherited from class org.axonframework.repository.LockingRepository
add, doDelete, doSave, load
 
Methods inherited from class org.axonframework.repository.AbstractRepository
getAggregateType, load, postDelete, postSave, setEventBus, validateOnLoad
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HybridJpaRepository

public HybridJpaRepository(EntityManagerProvider entityManagerProvider,
                           Class<T> aggregateType)
Initializes a Hybrid Repository that stored entities of the given aggregateType and the locking mechanism provided by the backend storage.

Parameters:
entityManagerProvider - The EntityManagerProvider providing the EntityManager instance for this repository
aggregateType - The type of aggregate stored in this repository.

HybridJpaRepository

public HybridJpaRepository(EntityManagerProvider entityManagerProvider,
                           Class<T> aggregateType,
                           String aggregateTypeIdentifier)
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:
entityManagerProvider - The EntityManagerProvider providing the EntityManager instance for this repository
aggregateType - The type of aggregate stored in this repository.
aggregateTypeIdentifier - The type identifier to store events with

HybridJpaRepository

public HybridJpaRepository(EntityManagerProvider entityManagerProvider,
                           Class<T> aggregateType,
                           LockManager lockManager)
Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.

Parameters:
entityManagerProvider - The EntityManagerProvider providing the EntityManager instance for this repository
aggregateType - The type of aggregate stored in this repository.
lockManager - The locking strategy to use when loading and storing aggregates

HybridJpaRepository

public HybridJpaRepository(javax.persistence.EntityManager entityManager,
                           Class<T> aggregateType,
                           LockManager lockManager)
Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.

Parameters:
entityManager - The EntityManager instance for this repository
aggregateType - The type of aggregate stored in this repository.
lockManager - The locking strategy to use when loading and storing aggregates

HybridJpaRepository

public HybridJpaRepository(EntityManagerProvider entityManagerProvider,
                           Class<T> aggregateType,
                           String aggregateTypeIdentifier,
                           LockManager lockManager)
Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.

Parameters:
entityManagerProvider - The EntityManagerProvider providing the EntityManager instance for this repository
aggregateType - The type of aggregate stored in this repository.
aggregateTypeIdentifier - The type identifier to store events with
lockManager - The locking strategy to use when loading and storing aggregates

HybridJpaRepository

public HybridJpaRepository(javax.persistence.EntityManager entityManager,
                           Class<T> aggregateType,
                           String aggregateTypeIdentifier,
                           LockManager lockManager)
Initializes a Hybrid Repository that stored entities of the given aggregateType and a locking mechanism based on the given lockManager.

Parameters:
entityManager - The EntityManager instance for this repository
aggregateType - The type of aggregate stored in this repository.
aggregateTypeIdentifier - The type identifier to store events with
lockManager - The locking strategy to use when loading and storing aggregates
Method Detail

doDeleteWithLock

protected void doDeleteWithLock(T aggregate)
Description copied from class: LockingRepository
Perform the actual deleting of the aggregate. All necessary locks have been verified.

Overrides:
doDeleteWithLock in class GenericJpaRepository<T extends AggregateRoot>
Parameters:
aggregate - the aggregate to delete

doSaveWithLock

protected void doSaveWithLock(T aggregate)
Description copied from class: LockingRepository
Perform the actual saving of the aggregate. All necessary locks have been verified.

Overrides:
doSaveWithLock in class GenericJpaRepository<T extends AggregateRoot>
Parameters:
aggregate - the aggregate to store

getTypeIdentifier

protected String getTypeIdentifier()
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.

setEventStore

public void setEventStore(EventStore eventStore)
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


Copyright © 2010-2016. All Rights Reserved.