Class PermazenTransactionManager
- All Implemented Interfaces:
Serializable
,InitializingBean
,ConfigurableTransactionManager
,PlatformTransactionManager
,ResourceTransactionManager
,TransactionManager
PlatformTransactionManager
interface,
allowing methods annotated with Spring's @Transactional
annotation to perform transactions on a Permazen
database.
Properly integrates with PermazenTransaction.getCurrent()
to participate in
existing transactions when appropriate.
For some key/value stores, the value of
@Transactional.isolation()
is significant; see the documentation for your specific KVDatabase
for details.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Adapter class that wraps a SpringTransactionSynchronization
in theTransaction.Callback
interface.Nested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
AbstractPlatformTransactionManager.SuspendedResourcesHolder
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ValidationMode
The defaultValidationMode
to use for transactions (ValidationMode.AUTOMATIC
).static final String
The name of the transaction option passed toKVDatabase.createTransaction()
containing the isolation level from the transaction definition.protected Permazen
The configuredPermazen
from which transactions are created.protected ValidationMode
TheValidationMode
to use for transactions.Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
Configure a new transaction.protected PermazenTransaction
createTransaction
(Map<String, Object> options) Create the underlyingPermazenTransaction
for a new transaction.protected void
doBegin
(Object txObj, TransactionDefinition txDef) protected void
doCleanupAfterCompletion
(Object txObj) protected void
doCommit
(DefaultTransactionStatus status) protected Object
protected void
Resume a previously suspended transaction.protected void
doRollback
(DefaultTransactionStatus status) protected void
protected Object
Suspend the current transaction.protected PermazenTransaction
LikePermazenTransaction.getCurrent()
, but returns null instead of throwingIllegalStateException
.protected boolean
isExistingTransaction
(Object txObj) protected void
populateOptions
(Map<String, Object> options, TransactionDefinition txDef) Populate the given options map for a new transaction.protected void
protected void
registerAfterCompletionWithExistingTransaction
(Object txObj, List<TransactionSynchronization> synchronizations) void
setCreateBranchedTransactions
(boolean createBranchedTransactions) Configure whether to create branched transactions instead of normal transactions.void
setPermazen
(Permazen pdb) Configure thePermazen
that this instance will operate on.void
setValidateBeforeCommit
(boolean validateBeforeCommit) Configure whether to invokePermazenTransaction.validate()
just prior to commit (and prior to any synchronization callbacks).void
setValidationMode
(ValidationMode validationMode) Configure theValidationMode
to use for transactions.Methods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionExecutionListeners, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, prepareSynchronization, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionExecutionListeners, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.transaction.ConfigurableTransactionManager
addListener
Methods inherited from interface org.springframework.transaction.PlatformTransactionManager
commit, getTransaction, rollback
-
Field Details
-
ISOLATION_OPTION
The name of the transaction option passed toKVDatabase.createTransaction()
containing the isolation level from the transaction definition. Some key/value databases may interpret this option. The value of this option is anIsolation
instance. -
DEFAULT_VALIDATION_MODE
The defaultValidationMode
to use for transactions (ValidationMode.AUTOMATIC
). -
pdb
The configuredPermazen
from which transactions are created. -
validationMode
TheValidationMode
to use for transactions.
-
-
Constructor Details
-
PermazenTransactionManager
public PermazenTransactionManager()
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Throws:
Exception
-
setPermazen
Configure thePermazen
that this instance will operate on.Required property.
- Parameters:
pdb
- associated database
-
setValidationMode
Configure theValidationMode
to use for transactions.Default value is
ValidationMode.AUTOMATIC
.- Parameters:
validationMode
- validation mode for transactions
-
setValidateBeforeCommit
public void setValidateBeforeCommit(boolean validateBeforeCommit) Configure whether to invokePermazenTransaction.validate()
just prior to commit (and prior to any synchronization callbacks). This also causes validation to be performed at the end of each inner transaction that is participating in an outer transaction. If set to false, validation still occurs, but only when the outermost transaction commits.Default false.
- Parameters:
validateBeforeCommit
- whether to validate after inner transactions
-
setCreateBranchedTransactions
public void setCreateBranchedTransactions(boolean createBranchedTransactions) Configure whether to create branched transactions instead of normal transactions.Default false.
- Parameters:
createBranchedTransactions
- true to create branched transactions- See Also:
-
getResourceFactory
- Specified by:
getResourceFactory
in interfaceResourceTransactionManager
-
doGetTransaction
- Specified by:
doGetTransaction
in classAbstractPlatformTransactionManager
-
isExistingTransaction
- Overrides:
isExistingTransaction
in classAbstractPlatformTransactionManager
-
doBegin
- Specified by:
doBegin
in classAbstractPlatformTransactionManager
-
populateOptions
Populate the given options map for a new transaction.The implementation in
PermazenTransactionManager
populates options based on the transaction isolation level as described above.- Parameters:
options
- options maptxDef
- transaction definition
-
createTransaction
Create the underlyingPermazenTransaction
for a new transaction.The implementation in
PermazenTransactionManager
just delegates toPermazen.createTransaction(ValidationMode, Map)
(orPermazen.createBranchedTransaction(ValidationMode, Map, Map)
if so configured) using this instance's configured settings for validation mode and allowing new schema versions.- Parameters:
options
- transaction options- Returns:
- newly created
PermazenTransaction
- Throws:
DatabaseException
- if an error occurs
-
doSuspend
Suspend the current transaction.- Overrides:
doSuspend
in classAbstractPlatformTransactionManager
-
doResume
Resume a previously suspended transaction.- Overrides:
doResume
in classAbstractPlatformTransactionManager
-
configureTransaction
Configure a new transaction.The implementation in
PermazenTransactionManager
sets the transaction's timeout and read-only properties.- Parameters:
jtx
- transaction to configuretxDef
- transaction definition- Throws:
DatabaseException
- if an error occurs
-
prepareForCommit
- Overrides:
prepareForCommit
in classAbstractPlatformTransactionManager
-
doCommit
- Specified by:
doCommit
in classAbstractPlatformTransactionManager
-
doRollback
- Specified by:
doRollback
in classAbstractPlatformTransactionManager
-
doSetRollbackOnly
- Overrides:
doSetRollbackOnly
in classAbstractPlatformTransactionManager
-
doCleanupAfterCompletion
- Overrides:
doCleanupAfterCompletion
in classAbstractPlatformTransactionManager
-
registerAfterCompletionWithExistingTransaction
protected void registerAfterCompletionWithExistingTransaction(Object txObj, List<TransactionSynchronization> synchronizations) - Overrides:
registerAfterCompletionWithExistingTransaction
in classAbstractPlatformTransactionManager
-
getCurrent
LikePermazenTransaction.getCurrent()
, but returns null instead of throwingIllegalStateException
.- Returns:
- the transaction associated with the current thread, or null if there is none
-