Class ContextSourceTransactionManager
- java.lang.Object
-
- org.springframework.transaction.support.AbstractPlatformTransactionManager
-
- org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager
-
- All Implemented Interfaces:
java.io.Serializable,org.springframework.beans.factory.InitializingBean,org.springframework.transaction.PlatformTransactionManager,org.springframework.transaction.TransactionManager
public class ContextSourceTransactionManager extends org.springframework.transaction.support.AbstractPlatformTransactionManager implements org.springframework.beans.factory.InitializingBeanTransactionManager for managing LDAP transactions. Since transactions are not supported in the LDAP protocol, this class and its collaborators aim to provide compensating transactions instead. Should a transaction need to be rolled back, this TransactionManager will try to restore the original state using information recorded prior to each operation. The operation where the original state is restored is called a compensating operation.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.:
- Should the transaction failure be caused by a network failure, there is no way whatsoever that this TransactionManager can restore the database state. In this case, all possibilities for rollback will be utterly lost.
- Transaction isolation is not provided, i.e. entries participating in a transaction for one client may very well participate in another transaction for another client at the same time. Should one of these transactions be rolled back, the outcome of this is undetermined, and may in the worst case result in total failure.
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 thesetContextSource(ContextSource)method. While the actual ContextSource used by the target LdapTemplate instance needs to be of the typeTransactionAwareContextSourceProxy, 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 correspondingCompensatingTransactionOperationRecorder, which collects the information necessary to perform a rollback and produces aCompensatingTransactionOperationExecutorwhich 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
UnbindOperationExecutorwill 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 aTempEntryRenamingStrategy(defaultDefaultTempEntryRenamingStrategy), specified insetRenamingStrategy(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.
-
-
Constructor Summary
Constructors Constructor Description ContextSourceTransactionManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected voiddoBegin(java.lang.Object transaction, org.springframework.transaction.TransactionDefinition definition)protected voiddoCleanupAfterCompletion(java.lang.Object transaction)protected voiddoCommit(org.springframework.transaction.support.DefaultTransactionStatus status)protected java.lang.ObjectdoGetTransaction()protected voiddoRollback(org.springframework.transaction.support.DefaultTransactionStatus status)ContextSourcegetContextSource()Get the ContextSource.protected booleanisExistingTransaction(java.lang.Object transaction)voidsetContextSource(ContextSource contextSource)Set the ContextSource.voidsetRenamingStrategy(TempEntryRenamingStrategy renamingStrategy)Set theTempEntryRenamingStrategy.-
Methods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
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
-
-
-
-
Method Detail
-
doBegin
protected void doBegin(java.lang.Object transaction, org.springframework.transaction.TransactionDefinition definition)- Specified by:
doBeginin classorg.springframework.transaction.support.AbstractPlatformTransactionManager
-
doCleanupAfterCompletion
protected void doCleanupAfterCompletion(java.lang.Object transaction)
- Overrides:
doCleanupAfterCompletionin classorg.springframework.transaction.support.AbstractPlatformTransactionManager
-
doCommit
protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
- Specified by:
doCommitin classorg.springframework.transaction.support.AbstractPlatformTransactionManager
-
doGetTransaction
protected java.lang.Object doGetTransaction()
- Specified by:
doGetTransactionin classorg.springframework.transaction.support.AbstractPlatformTransactionManager
-
doRollback
protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
- Specified by:
doRollbackin classorg.springframework.transaction.support.AbstractPlatformTransactionManager
-
getContextSource
public ContextSource getContextSource()
Get the ContextSource.- Returns:
- the contextSource.
- See Also:
ContextSourceTransactionManagerDelegate.getContextSource()
-
setContextSource
public void setContextSource(ContextSource contextSource)
Set the ContextSource.- Parameters:
contextSource- the ContextSource.- See Also:
ContextSourceTransactionManagerDelegate.setContextSource(ContextSource)
-
setRenamingStrategy
public void setRenamingStrategy(TempEntryRenamingStrategy renamingStrategy)
Set theTempEntryRenamingStrategy.- Parameters:
renamingStrategy- the Renaming Strategy.- See Also:
ContextSourceTransactionManagerDelegate.setRenamingStrategy(TempEntryRenamingStrategy)
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception
-
isExistingTransaction
protected boolean isExistingTransaction(java.lang.Object transaction) throws org.springframework.transaction.TransactionException- Overrides:
isExistingTransactionin classorg.springframework.transaction.support.AbstractPlatformTransactionManager- Throws:
org.springframework.transaction.TransactionException
-
-