T
- The type of aggregate the repository provides access toGenericJpaRepository
which moved to jakarta.@Deprecated public class GenericJpaRepository<T> extends LockingRepository<T,AnnotatedAggregate<T>>
By default, this repository implementation will generate sequences for the events published by the aggregate. In
doing so, the user is capable of querying the events based on the aggregate identifier and order them based on the
aforementioned sequence number. The downside of this, is that even if the stored aggregate is removed, the aggregate
identifier cannot be reused. This follows from the uniqueness constraint on the Event Store defining that the
combination of aggregate identifier to sequence number should be unique. However, sequence number generation can be
disabled, through GenericJpaRepository.Builder.disableSequenceNumberGeneration()
. When disabled, published events will no
longer hold the sequence number nor the aggregate identifier. As such, the aggregate identifier can be reused
(after removal of the previous aggregate referring to that identifier). The obvious downside of this is that the
events in the store can no longer be queried based on the aggregate identifier.
Modifier and Type | Class and Description |
---|---|
static class |
GenericJpaRepository.Builder<T>
Deprecated.
Builder class to instantiate a
GenericJpaRepository for aggregate type T . |
spanFactory
Modifier | Constructor and Description |
---|---|
protected |
GenericJpaRepository(GenericJpaRepository.Builder<T> builder)
Deprecated.
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)
Deprecated.
Instantiate a Builder to be able to create a
GenericJpaRepository for aggregate type T . |
protected AnnotatedAggregate<T> |
doCreateNewForLock(Callable<T> factoryMethod)
Deprecated.
Creates a new aggregate instance using the given
factoryMethod . |
protected void |
doDeleteWithLock(AnnotatedAggregate<T> aggregate)
Deprecated.
Perform the actual deleting of the aggregate.
|
protected AnnotatedAggregate<T> |
doLoadWithLock(String aggregateIdentifier,
Long expectedVersion)
Deprecated.
Loads the aggregate with the given aggregateIdentifier.
|
protected void |
doSaveWithLock(AnnotatedAggregate<T> aggregate)
Deprecated.
Perform the actual saving of the aggregate.
|
void |
setForceFlushOnSave(boolean forceFlushOnSave)
Deprecated.
Indicates whether the EntityManager's state should be flushed each time an aggregate is saved.
|
doCreateNew, doDelete, doLoad, doLoadOrCreate, doSave, prepareForCommit
aggregateModel, canResolve, getAggregateType, load, load, loadOrCreate, managedAggregates, newInstance, 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()
. The RepositorySpanFactory
is defaulted to a
DefaultRepositorySpanFactory
backed by a
NoOpSpanFactory
. 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–2024. All rights reserved.