T
- The type of aggregate the repository provides access topublic class GenericJpaRepository<T> extends LockingRepository<T,AnnotatedAggregate<T>>
Constructor and Description |
---|
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
AggregateModel<T> aggregateModel,
EventBus eventBus)
Initialize a repository for storing aggregates whose structure is defined by given
aggregateModel . |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
AggregateModel<T> aggregateModel,
EventBus eventBus,
LockFactory lockFactory)
Initialize a repository for storing aggregates described by the given
aggregateModel with an additional
LockFactory . |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
AggregateModel<T> aggregateModel,
EventBus eventBus,
LockFactory lockFactory,
Function<String,?> identifierConverter)
Initialize a repository for storing aggregates described by the given
AggregateModel , with an additional
LockFactory and allowing for a custom identifierConverter to convert a String based identifier to
an Identifier Object. |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
EventBus eventBus)
Initialize a repository for storing aggregates of the given
aggregateType . |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
EventBus eventBus,
Function<String,?> identifierConverter)
Initialize a repository for storing aggregates of the given
aggregateType . |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
EventBus eventBus,
LockFactory lockFactory)
Initialize a repository for storing aggregates of the given
aggregateType with an additional LockFactory . |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
EventBus eventBus,
LockFactory lockFactory,
Function<String,?> identifierConverter)
Initialize a repository for storing aggregates of the given
aggregateType with an additional LockFactory and allowing for a custom identifierConverter to convert a String based identifier to an
Identifier Object. |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
EventBus eventBus,
LockFactory lockFactory,
ParameterResolverFactory parameterResolverFactory)
Initialize a repository for storing aggregates of the given
aggregateType with an additional LockFactory . |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
EventBus eventBus,
LockFactory lockFactory,
ParameterResolverFactory parameterResolverFactory,
Function<String,?> identifierConverter)
Initialize a repository for storing aggregates of the given
aggregateType with an additional LockFactory and allowing for a custom identifierConverter to convert a String based identifier to an
Identifier Object. |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
EventBus eventBus,
ParameterResolverFactory parameterResolverFactory)
Initialize a repository for storing aggregates of the given
aggregateType . |
Modifier and Type | Method and Description |
---|---|
protected AnnotatedAggregate<T> |
doCreateNewForLock(Callable<T> factoryMethod)
Creates a new aggregate instance using the given
factoryMethod . |
protected void |
doDeleteWithLock(AnnotatedAggregate<T> aggregate)
Perform the actual deleting of the aggregate.
|
protected AnnotatedAggregate<T> |
doLoadWithLock(String aggregateIdentifier,
Long expectedVersion)
Loads the aggregate with the given aggregateIdentifier.
|
protected void |
doSaveWithLock(AnnotatedAggregate<T> aggregate)
Perform the actual saving of the aggregate.
|
void |
setForceFlushOnSave(boolean forceFlushOnSave)
Indicates whether the EntityManager's state should be flushed each time an aggregate is saved.
|
doCreateNew, doDelete, doLoad, doSave, prepareForCommit
aggregateModel, getAggregateType, load, load, managedAggregates, newInstance, postDelete, postSave, reportIllegalState, validateOnLoad
public GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, EventBus eventBus)
aggregateType
. No additional locking
will be used.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreaggregateType
- the aggregate type this repository manageseventBus
- the event bus to which new events are publishedpublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, AggregateModel<T> aggregateModel, EventBus eventBus)
aggregateModel
.
No additional locking will be used.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreaggregateModel
- the model describing the structure of the aggregateeventBus
- the event bus to which new events are publishedpublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, EventBus eventBus, Function<String,?> identifierConverter)
aggregateType
. No additional locking
will be used and allowing for a custom identifierConverter
to convert a String based identifier to an
Identifier Object.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreaggregateType
- the aggregate type this repository manageseventBus
- the event bus to which new events are publishedidentifierConverter
- the function that converts the String based identifier to the Identifier object
used in the Entitypublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, EventBus eventBus, ParameterResolverFactory parameterResolverFactory)
aggregateType
. No additional locking
will be used.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreaggregateType
- the aggregate type this repository manageseventBus
- the event bus to which new events are publishedparameterResolverFactory
- the component to resolve parameter values of annotated message handlers withpublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, EventBus eventBus, LockFactory lockFactory)
aggregateType
with an additional LockFactory
.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this repositoryaggregateType
- the aggregate type this repository manageseventBus
- the event bus to which new events are publishedlockFactory
- the additional locking strategy for this repositorypublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, AggregateModel<T> aggregateModel, EventBus eventBus, LockFactory lockFactory)
aggregateModel
with an additional
LockFactory
.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this repositoryaggregateModel
- the model describing the structure of the aggregateeventBus
- the event bus to which new events are publishedlockFactory
- the additional locking strategy for this repositorypublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, EventBus eventBus, LockFactory lockFactory, Function<String,?> identifierConverter)
aggregateType
with an additional LockFactory
and allowing for a custom identifierConverter
to convert a String based identifier to an
Identifier Object.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this repositoryaggregateType
- the aggregate type this repository manageseventBus
- the event bus to which new events are publishedlockFactory
- the additional locking strategy for this repositoryidentifierConverter
- the function that converts the String based identifier to the Identifier object
used in the Entitypublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, AggregateModel<T> aggregateModel, EventBus eventBus, LockFactory lockFactory, Function<String,?> identifierConverter)
AggregateModel
, with an additional
LockFactory
and allowing for a custom identifierConverter
to convert a String based identifier to
an Identifier Object.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this repositoryaggregateModel
- the model describing the structure of the aggregateeventBus
- the event bus to which new events are publishedlockFactory
- the additional locking strategy for this repositoryidentifierConverter
- the function that converts the String based identifier to the Identifier object
used in the Entitypublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, EventBus eventBus, LockFactory lockFactory, ParameterResolverFactory parameterResolverFactory)
aggregateType
with an additional LockFactory
.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this repositoryaggregateType
- the aggregate type this repository manageseventBus
- the event bus to which new events are publishedlockFactory
- the additional locking strategy for this repositoryparameterResolverFactory
- the component to resolve parameter values of annotated message handlers withpublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, EventBus eventBus, LockFactory lockFactory, ParameterResolverFactory parameterResolverFactory, Function<String,?> identifierConverter)
aggregateType
with an additional LockFactory
and allowing for a custom identifierConverter
to convert a String based identifier to an
Identifier Object.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this repositoryaggregateType
- the aggregate type this repository manageseventBus
- the event bus to which new events are publishedlockFactory
- the additional locking strategy for this repositoryparameterResolverFactory
- the component to resolve parameter values of annotated message handlers withidentifierConverter
- the function that converts the String based identifier to the Identifier object
used in the Entityprotected AnnotatedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion)
LockingRepository
doLoadWithLock
in class LockingRepository<T,AnnotatedAggregate<T>>
aggregateIdentifier
- the identifier of the aggregate to loadexpectedVersion
- The expected version of the aggregate to loadprotected AnnotatedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception
LockingRepository
factoryMethod
. Implementations should assume that this
method is only called if a UnitOfWork is currently active.doCreateNewForLock
in class LockingRepository<T,AnnotatedAggregate<T>>
factoryMethod
- The method to create the aggregate's root instanceException
- when the factoryMethod throws an exceptionprotected void doSaveWithLock(AnnotatedAggregate<T> aggregate)
LockingRepository
doSaveWithLock
in class LockingRepository<T,AnnotatedAggregate<T>>
aggregate
- the aggregate to storeprotected void doDeleteWithLock(AnnotatedAggregate<T> aggregate)
LockingRepository
doDeleteWithLock
in class LockingRepository<T,AnnotatedAggregate<T>>
aggregate
- the aggregate to deletepublic void setForceFlushOnSave(boolean forceFlushOnSave)
true
.
Flushing the EntityManager will force JPA to send state changes to the database. Any key violations and failing
optimistic locks will be identified in an early stage.forceFlushOnSave
- whether or not to flush the EntityManager after each save. Defaults to true
.EntityManager.flush()
Copyright © 2010–2017. All rights reserved.