T
- The type of aggregate the repository provides access topublic class GenericJpaRepository<T extends AggregateRoot> extends LockingRepository<T>
AggregateRoot
and have the proper JPA Annotations.
Optionally, the repository may be configured with a locking scheme. The repository will always force optimistic
locking in the backing data store. The optional lock in the repository is in addition to this optimistic lock. Note
that locks on this repository will not be shared with other repository instances.
When this repository is requested to persist changes to an aggregate, it will also flush the EntityManager, to
enforce checking of database constraints and optimistic locks.Constructor and Description |
---|
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType)
Initialize a repository for storing aggregates of the given
aggregateType . |
GenericJpaRepository(EntityManagerProvider entityManagerProvider,
Class<T> aggregateType,
LockManager lockManager)
Initialize a repository for storing aggregates of the given
aggregateType with an additional
lockManager . |
Modifier and Type | Method and Description |
---|---|
protected void |
doDeleteWithLock(T aggregate)
Perform the actual deleting of the aggregate.
|
protected T |
doLoad(Object aggregateIdentifier,
Long expectedVersion)
Perform the actual loading of an aggregate.
|
protected void |
doSaveWithLock(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.
|
add, doDelete, doSave, load
getAggregateType, load, postDelete, postSave, setEventBus, validateOnLoad
public GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType)
aggregateType
. No additional locking
will be used.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreaggregateType
- the aggregate type this repository managespublic GenericJpaRepository(EntityManagerProvider entityManagerProvider, Class<T> aggregateType, LockManager lockManager)
aggregateType
with an additional
lockManager
.entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this repositoryaggregateType
- the aggregate type this repository manageslockManager
- the additional locking strategy for this repositoryprotected void doSaveWithLock(T aggregate)
LockingRepository
doSaveWithLock
in class LockingRepository<T extends AggregateRoot>
aggregate
- the aggregate to storeprotected void doDeleteWithLock(T aggregate)
LockingRepository
doDeleteWithLock
in class LockingRepository<T extends AggregateRoot>
aggregate
- the aggregate to deleteprotected T doLoad(Object aggregateIdentifier, Long expectedVersion)
LockingRepository
doLoad
in class LockingRepository<T extends AggregateRoot>
aggregateIdentifier
- the identifier of the aggregate to loadexpectedVersion
- The expected version of the aggregatepublic 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-2014. All Rights Reserved.