public class PermazenTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, InitializingBean
PlatformTransactionManager
interface,
allowing methods annotated with Spring's @Transactional
annotation to perform transactions on a Permazen
database.
Properly integrates with JTransaction.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.
io.permazen.spring
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
PermazenTransactionManager.TransactionSynchronizationCallback
Adapter class that wraps a Spring
TransactionSynchronization in the
Transaction.Callback interface. |
AbstractPlatformTransactionManager.SuspendedResourcesHolder
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowNewSchema
Whether a new schema version is allowed.
|
static ValidationMode |
DEFAULT_VALIDATION_MODE
The default
ValidationMode to use for transactions (ValidationMode.AUTOMATIC ). |
static String |
ISOLATION_OPTION
The name of the transaction option passed to
KVDatabase.createTransaction()
containing the isolation level from the
transaction definition. |
protected Permazen |
jdb
The configured
Permazen from which transactions are created. |
protected ValidationMode |
validationMode
The
ValidationMode to use for transactions. |
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
Constructor and Description |
---|
PermazenTransactionManager() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
configureTransaction(JTransaction jtx,
TransactionDefinition txDef)
Configure a new transaction.
|
protected JTransaction |
createTransaction(Map<String,Object> options)
Create the underlying
JTransaction for a new transaction. |
protected void |
doBegin(Object txObj,
TransactionDefinition txDef) |
protected void |
doCleanupAfterCompletion(Object txObj) |
protected void |
doCommit(DefaultTransactionStatus status) |
protected Object |
doGetTransaction() |
protected void |
doResume(Object txObj,
Object suspendedResources)
Resume a previously suspended transaction.
|
protected void |
doRollback(DefaultTransactionStatus status) |
protected void |
doSetRollbackOnly(DefaultTransactionStatus status) |
protected Object |
doSuspend(Object txObj)
Suspend the current transaction.
|
protected JTransaction |
getCurrent()
Like
JTransaction.getCurrent() , but returns null instead of throwing IllegalStateException . |
Object |
getResourceFactory() |
protected boolean |
isExistingTransaction(Object txObj) |
protected void |
prepareForCommit(DefaultTransactionStatus status) |
protected void |
registerAfterCompletionWithExistingTransaction(Object txObj,
List<TransactionSynchronization> synchronizations) |
void |
setAllowNewSchema(boolean allowNewSchema)
Configure whether a new schema version may be created.
|
void |
setPermazen(Permazen jdb)
Configure the
Permazen that this instance will operate on. |
void |
setValidateBeforeCommit(boolean validateBeforeCommit)
Configure whether to invoke
JTransaction.validate() just prior to commit (and prior to any
synchronization callbacks). |
void |
setValidationMode(ValidationMode validationMode)
Configure the
ValidationMode to use for transactions. |
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareSynchronization, prepareTransactionStatus, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
commit, getTransaction, rollback
public static final String ISOLATION_OPTION
KVDatabase.createTransaction()
containing the isolation level from the
transaction definition. Some key/value databases may interpret this option.
The value of this option is an Isolation
instance.public static final ValidationMode DEFAULT_VALIDATION_MODE
ValidationMode
to use for transactions (ValidationMode.AUTOMATIC
).protected boolean allowNewSchema
protected ValidationMode validationMode
ValidationMode
to use for transactions.public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
public void setPermazen(Permazen jdb)
Permazen
that this instance will operate on.
Required property.
jdb
- associated databasepublic void setAllowNewSchema(boolean allowNewSchema)
Default value is false.
allowNewSchema
- whether to allow recording new schema versionspublic void setValidationMode(ValidationMode validationMode)
ValidationMode
to use for transactions.
Default value is ValidationMode.AUTOMATIC
.
validationMode
- validation mode for transactionspublic void setValidateBeforeCommit(boolean validateBeforeCommit)
JTransaction.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.
validateBeforeCommit
- whether to validate after inner transactionspublic Object getResourceFactory()
getResourceFactory
in interface ResourceTransactionManager
protected Object doGetTransaction()
doGetTransaction
in class AbstractPlatformTransactionManager
protected boolean isExistingTransaction(Object txObj)
isExistingTransaction
in class AbstractPlatformTransactionManager
protected void doBegin(Object txObj, TransactionDefinition txDef)
doBegin
in class AbstractPlatformTransactionManager
protected JTransaction createTransaction(Map<String,Object> options)
JTransaction
for a new transaction.
The implementation in PermazenTransactionManager
just delegates to
Permazen.createTransaction(boolean, ValidationMode, Map)
using this instance's configured
settings for validation mode and allowing new schema versions.
options
- transaction optionsJTransaction
DatabaseException
- if an error occursprotected Object doSuspend(Object txObj)
doSuspend
in class AbstractPlatformTransactionManager
protected void doResume(Object txObj, Object suspendedResources)
doResume
in class AbstractPlatformTransactionManager
protected void configureTransaction(JTransaction jtx, TransactionDefinition txDef)
The implementation in PermazenTransactionManager
sets the transaction's timeout and read-only properties.
jtx
- transaction to configuretxDef
- transaction definitionDatabaseException
- if an error occursprotected void prepareForCommit(DefaultTransactionStatus status)
prepareForCommit
in class AbstractPlatformTransactionManager
protected void doCommit(DefaultTransactionStatus status)
doCommit
in class AbstractPlatformTransactionManager
protected void doRollback(DefaultTransactionStatus status)
doRollback
in class AbstractPlatformTransactionManager
protected void doSetRollbackOnly(DefaultTransactionStatus status)
doSetRollbackOnly
in class AbstractPlatformTransactionManager
protected void doCleanupAfterCompletion(Object txObj)
doCleanupAfterCompletion
in class AbstractPlatformTransactionManager
protected void registerAfterCompletionWithExistingTransaction(Object txObj, List<TransactionSynchronization> synchronizations)
registerAfterCompletionWithExistingTransaction
in class AbstractPlatformTransactionManager
protected JTransaction getCurrent()
JTransaction.getCurrent()
, but returns null instead of throwing IllegalStateException
.Copyright © 2022. All rights reserved.