com.interface21.orm.jdo
Class JdoTransactionManager

java.lang.Object
  |
  +--com.interface21.transaction.support.AbstractPlatformTransactionManager
        |
        +--com.interface21.orm.jdo.JdoTransactionManager
All Implemented Interfaces:
InitializingBean, PlatformTransactionManager

public class JdoTransactionManager
extends AbstractPlatformTransactionManager
implements InitializingBean

PlatformTransactionManager implementation for single JDO persistence manager factories. Binds a JDO PersistenceManager from the specified factory to the thread, potentially allowing for one thread PersistenceManager per factory. PersistenceManagerFactoryUtils and JdoTemplate are aware of thread-bound persistence managers and take part in such transactions automatically. Using either is required for JDO access code supporting this transaction handling mechanism.

This implementation is appropriate for applications that solely use JDO for transactional data access. JTA resp. JtaTransactionManager is necessary for accessing multiple transactional resources. Unfortunately, there is no way of using JTA with a local JDO PersistenceManagerFactory, at least not with popular implementations like Kodo and Lido. One needs to deploy the respective JCA connector to be able to take part in JTA transactions.

Note that Hibernate can take part in JTA transactions even with a local Hibernate SessionFactory. Due to Spring's transaction synchronization support, this doesn't even involve container-specific setup when using Hibernate's transactional JVM-level cache.

Since:
03.06.2003
Author:
Juergen Hoeller
See Also:
PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean), PersistenceManagerFactoryUtils.closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager, javax.jdo.PersistenceManagerFactory), JdoTemplate.execute(com.interface21.orm.jdo.JdoCallback), HibernateTransactionManager

Fields inherited from class com.interface21.transaction.support.AbstractPlatformTransactionManager
logger
 
Constructor Summary
JdoTransactionManager()
          Create a new JdoTransactionManager instance.
JdoTransactionManager(javax.jdo.PersistenceManagerFactory pmf)
          Create a new JdoTransactionManager instance.
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied.
protected  void doBegin(java.lang.Object transaction, int isolationLevel, int timeout)
          Begin a new transaction with the given isolation level.
protected  void doCommit(TransactionStatus status)
          Perform an actual commit on the given transaction.
protected  java.lang.Object doGetTransaction()
          Return a current transaction object, i.e. a JTA UserTransaction.
protected  void doRollback(TransactionStatus status)
          Perform an actual rollback on the given transaction.
protected  void doSetRollbackOnly(TransactionStatus status)
          Set the given transaction rollback-only.
 javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
          Return the PersistenceManagerFactory that this instance should manage transactions for.
protected  boolean isExistingTransaction(java.lang.Object transaction)
          Check if the given transaction object indicates an existing, i.e. already begun, transaction.
 void setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory pmf)
          Set the PersistenceManagerFactory that this instance should manage transactions for.
 
Methods inherited from class com.interface21.transaction.support.AbstractPlatformTransactionManager
commit, getAllowNonTransactionalExecution, getTransaction, getTransactionSynchronization, rollback, setAllowNonTransactionalExecution, setTransactionSynchronization
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdoTransactionManager

public JdoTransactionManager()
Create a new JdoTransactionManager instance. A PersistenceManagerFactory has to be set to be able to use it.
See Also:
setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)

JdoTransactionManager

public JdoTransactionManager(javax.jdo.PersistenceManagerFactory pmf)
Create a new JdoTransactionManager instance.
Parameters:
pmf - PersistenceManagerFactory to manage transactions for
Method Detail

setPersistenceManagerFactory

public void setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory pmf)
Set the PersistenceManagerFactory that this instance should manage transactions for.

getPersistenceManagerFactory

public javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
Return the PersistenceManagerFactory that this instance should manage transactions for.

afterPropertiesSet

public void afterPropertiesSet()
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied.
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
Specified by:
afterPropertiesSet in interface InitializingBean
Following copied from interface: com.interface21.beans.factory.InitializingBean
Throws:
java.lang.Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.

doGetTransaction

protected java.lang.Object doGetTransaction()
                                     throws CannotCreateTransactionException,
                                            TransactionException
Description copied from class: AbstractPlatformTransactionManager
Return a current transaction object, i.e. a JTA UserTransaction.
Overrides:
doGetTransaction in class AbstractPlatformTransactionManager
Following copied from class: com.interface21.transaction.support.AbstractPlatformTransactionManager
Returns:
the current transaction object
Throws:
CannotCreateTransactionException - if transaction support is not available (e.g. no JTA UserTransaction retrievable from JNDI)
TransactionException - in case of lookup or system errors

isExistingTransaction

protected boolean isExistingTransaction(java.lang.Object transaction)
                                 throws TransactionException
Description copied from class: AbstractPlatformTransactionManager
Check if the given transaction object indicates an existing, i.e. already begun, transaction.
Overrides:
isExistingTransaction in class AbstractPlatformTransactionManager
Following copied from class: com.interface21.transaction.support.AbstractPlatformTransactionManager
Parameters:
transaction - transaction object returned by doGetTransaction()
Returns:
if there is an existing transaction
Throws:
TransactionException - in case of system errors

doBegin

protected void doBegin(java.lang.Object transaction,
                       int isolationLevel,
                       int timeout)
                throws TransactionException
Description copied from class: AbstractPlatformTransactionManager
Begin a new transaction with the given isolation level.
Overrides:
doBegin in class AbstractPlatformTransactionManager
Following copied from class: com.interface21.transaction.support.AbstractPlatformTransactionManager
Parameters:
transaction - transaction object returned by doGetTransaction()
isolationLevel - desired isolation level
timeout - transaction timeout (in seconds)
Throws:
TransactionException - in case of creation or system errors

doCommit

protected void doCommit(TransactionStatus status)
                 throws TransactionException
Description copied from class: AbstractPlatformTransactionManager
Perform an actual commit on the given transaction. An implementation does not need to check the rollback-only flag.
Overrides:
doCommit in class AbstractPlatformTransactionManager
Following copied from class: com.interface21.transaction.support.AbstractPlatformTransactionManager
Parameters:
status - status representation of the transaction
Throws:
TransactionException - in case of commit or system errors

doRollback

protected void doRollback(TransactionStatus status)
                   throws TransactionException
Description copied from class: AbstractPlatformTransactionManager
Perform an actual rollback on the given transaction. An implementation does not need to check the new transaction flag.
Overrides:
doRollback in class AbstractPlatformTransactionManager
Following copied from class: com.interface21.transaction.support.AbstractPlatformTransactionManager
Parameters:
status - status representation of the transaction
Throws:
TransactionException - in case of system errors

doSetRollbackOnly

protected void doSetRollbackOnly(TransactionStatus status)
                          throws TransactionException
Description copied from class: AbstractPlatformTransactionManager
Set the given transaction rollback-only. Only called on rollback if the current transaction takes part in an existing one.
Overrides:
doSetRollbackOnly in class AbstractPlatformTransactionManager
Following copied from class: com.interface21.transaction.support.AbstractPlatformTransactionManager
Parameters:
status - status representation of the transaction
Throws:
TransactionException - in case of system errors


Rod Johnson and Spring contributors 2001-2003.