public class ContextSourceTransactionManager extends AbstractPlatformTransactionManager implements InitializingBean
NOTE: The transactions provided by this TransactionManager are all client side and are by no means 'real' transactions, in the sense that we know them in the ordinary database world, e.g.:
While the points above should be noted and considered, the compensating transaction approach will be perfectly sufficient for all but the most unfortunate of circumstances. Considering that there currently is a total absence of server-side transaction support in the LDAP world, being able to mark operations as transactional in the same way as for relational database operations is surely a step forward.
An LDAP transaction is tied to a ContextSource
, to be supplied to
the setContextSource(ContextSource)
method. While the actual
ContextSource used by the target LdapTemplate instance needs to be of the
type TransactionAwareContextSourceProxy
, the ContextSource supplied
to this class should be the actual target ContextSource.
Using this TransactionManager along with
TransactionAwareContextSourceProxy
, all modifying operations (bind,
unbind, rebind, rename, modifyAttributes) in a transaction will be
intercepted. Each modification has its corresponding
CompensatingTransactionOperationRecorder
, which collects the
information necessary to perform a rollback and produces a
CompensatingTransactionOperationExecutor
which is then used to
execute the actual operation and is later called for performing the commit or
rollback.
For several of the operations, performing a rollback is pretty
straightforward. For example, in order to roll back a rename operation, it
will only be required to rename the entry back to its original position. For
other operations, however, it's a bit more complicated. An unbind operation
is not possible to roll back by simply binding the entry back with the
attributes retrieved from the original entry. It might not be possible to get
all the information from the original entry. Consequently, the
UnbindOperationExecutor
will move the original entry to a temporary
location in its performOperation() method. The commit() method will know that
everything went well, so it will be OK to unbind the entry. The rollback
operation will be to rename the entry back to its original location. The same
behaviour is used for rebind() operations. The operation of calculating a
temporary location for an entry is delegated to a
TempEntryRenamingStrategy
(default
DefaultTempEntryRenamingStrategy
), specified in
setRenamingStrategy(TempEntryRenamingStrategy)
.
The actual work of this Transaction Manager is delegated to a
ContextSourceTransactionManagerDelegate
. This is because the exact
same logic needs to be used if we want to wrap a JDBC and LDAP transaction in
the same logical transaction.
ContextSourceAndDataSourceTransactionManager
,
ContextSourceTransactionManagerDelegate
,
DefaultCompensatingTransactionOperationManager
,
TempEntryRenamingStrategy
,
TransactionAwareContextSourceProxy
,
Serialized FormAbstractPlatformTransactionManager.SuspendedResourcesHolder
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
Constructor and Description |
---|
ContextSourceTransactionManager() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
doBegin(Object transaction,
TransactionDefinition definition) |
protected void |
doCleanupAfterCompletion(Object transaction) |
protected void |
doCommit(DefaultTransactionStatus status) |
protected Object |
doGetTransaction() |
protected void |
doRollback(DefaultTransactionStatus status) |
ContextSource |
getContextSource()
Get the ContextSource.
|
protected boolean |
isExistingTransaction(Object transaction) |
void |
setContextSource(ContextSource contextSource)
Set the ContextSource.
|
void |
setRenamingStrategy(TempEntryRenamingStrategy renamingStrategy)
Set the
TempEntryRenamingStrategy . |
commit, determineTimeout, doResume, doSetRollbackOnly, doSuspend, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction
protected void doBegin(Object transaction, TransactionDefinition definition)
doBegin
in class AbstractPlatformTransactionManager
protected void doCleanupAfterCompletion(Object transaction)
doCleanupAfterCompletion
in class AbstractPlatformTransactionManager
protected void doCommit(DefaultTransactionStatus status)
doCommit
in class AbstractPlatformTransactionManager
protected Object doGetTransaction()
doGetTransaction
in class AbstractPlatformTransactionManager
protected void doRollback(DefaultTransactionStatus status)
doRollback
in class AbstractPlatformTransactionManager
public ContextSource getContextSource()
ContextSourceTransactionManagerDelegate.getContextSource()
public void setContextSource(ContextSource contextSource)
contextSource
- the ContextSource.ContextSourceTransactionManagerDelegate.setContextSource(ContextSource)
public void setRenamingStrategy(TempEntryRenamingStrategy renamingStrategy)
TempEntryRenamingStrategy
.renamingStrategy
- the Renaming Strategy.ContextSourceTransactionManagerDelegate.setRenamingStrategy(TempEntryRenamingStrategy)
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
protected boolean isExistingTransaction(Object transaction) throws TransactionException
isExistingTransaction
in class AbstractPlatformTransactionManager
TransactionException