T
- The type of aggregate the repository provides access topublic class GenericJpaRepository<T> extends LockingRepository<T,AnnotatedAggregate<T>>
Modifier and Type | Class and Description |
---|---|
static class |
GenericJpaRepository.Builder<T>
Builder class to instantiate a
GenericJpaRepository for aggregate type T . |
Modifier | Constructor and Description |
---|---|
protected |
GenericJpaRepository(GenericJpaRepository.Builder<T> builder)
Instantiate a
GenericJpaRepository based on the fields contained in the GenericJpaRepository.Builder . |
Modifier and Type | Method and Description |
---|---|
static <T> GenericJpaRepository.Builder<T> |
builder(Class<T> aggregateType)
Instantiate a Builder to be able to create a
GenericJpaRepository for aggregate type T . |
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, canResolve, getAggregateType, load, load, managedAggregates, newInstance, postDelete, postSave, reportIllegalState, send, validateOnLoad
protected GenericJpaRepository(GenericJpaRepository.Builder<T> builder)
GenericJpaRepository
based on the fields contained in the GenericJpaRepository.Builder
.
A goal of the provided Builder is to create an AggregateModel
specifying generic T
as the
aggregate type to be stored. All aggregates in this repository must be instanceOf
this aggregate type.
To instantiate this AggregateModel, either an AggregateModel
can be provided directly or an
aggregateType
of type Class
can be used. The latter will internally resolve to an
AggregateModel. Thus, either the AggregateModel or the aggregateType
should be provided. An
AxonConfigurationException
is thrown if this criteria is not met.
Additionally will assert that the LockFactory
, EntityManagerProvider
, EventBus
and
identifierConverter
are not null
, resulting in an AxonConfigurationException if for any of these
this is the case.
builder
- the GenericJpaRepository.Builder
used to instantiate a GenericJpaRepository
instancepublic static <T> GenericJpaRepository.Builder<T> builder(Class<T> aggregateType)
GenericJpaRepository
for aggregate type T
.
The LockFactory
is defaulted to an NullLockFactory
, thus providing no additional locking, and
the identifierConverter
to Function.identity()
.
A goal of this Builder goal is to create an AggregateModel
specifying generic T
as the aggregate
type to be stored. All aggregates in this repository must be instanceOf
this aggregate type. To
instantiate this AggregateModel, either an AggregateModel
can be provided directly or an
aggregateType
of type Class
can be used. The latter will internally resolve to an AggregateModel.
Thus, either the AggregateModel or the aggregateType
should be provided.
Additionally, the EntityManagerProvider
and EventBus
are hard requirements and as such
should be provided.
T
- The type of aggregate to build the repository foraggregateType
- The type of aggregate to build the repository forGenericJpaRepository
protected 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–2019. All rights reserved.