Package org.apache.cayenne.tx
Class BaseTransaction
java.lang.Object
org.apache.cayenne.tx.BaseTransaction
- All Implemented Interfaces:
- Transaction
- Direct Known Subclasses:
- CayenneTransaction,- ExternalTransaction
public abstract class BaseTransaction extends Object implements Transaction
A Cayenne transaction. Currently supports managing JDBC connections.
- Since:
- 4.0
- 
Field SummaryFields Modifier and Type Field Description protected Map<String,Connection>connectionsprotected intdefaultIsolationLevelprotected TransactionDescriptordescriptorprotected Collection<TransactionListener>listenersprotected intstatusprotected static intSTATUS_ACTIVEprotected static intSTATUS_COMMITTEDprotected static intSTATUS_COMMITTINGprotected static intSTATUS_MARKED_ROLLEDBACKprotected static intSTATUS_NO_TRANSACTIONprotected static intSTATUS_ROLLEDBACKprotected static intSTATUS_ROLLING_BACK
- 
Constructor SummaryConstructors Modifier Constructor Description protectedBaseTransaction(TransactionDescriptor descriptor)Creates new inactive transaction.
- 
Method SummaryModifier and Type Method Description protected ConnectionaddConnection(String connectionName, Connection connection)voidaddListener(TransactionListener listener)voidbegin()Starts a Transaction.static voidbindThreadTransaction(Transaction transaction)Binds a Transaction to the current thread.protected voidclose()Closes all connections associated with transaction.voidcommit()protected voidconnectionAdded(Connection connection)Map<String,Connection>getConnections()Returns all connections associated with the transaction.protected ConnectiongetExistingConnection(String name)ConnectiongetOrCreateConnection(String connectionName, DataSource dataSource)Retrieves a connection for the given symbolic name.static TransactiongetThreadTransaction()Returns a Transaction associated with the current thread, or null if there is no such Transaction.booleanisRollbackOnly()protected abstract voidprocessCommit()protected abstract voidprocessRollback()voidrollback()voidsetRollbackOnly()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cayenne.tx.TransactionisExternal
- 
Field Details- 
STATUS_ACTIVEprotected static final int STATUS_ACTIVE- See Also:
- Constant Field Values
 
- 
STATUS_COMMITTINGprotected static final int STATUS_COMMITTING- See Also:
- Constant Field Values
 
- 
STATUS_COMMITTEDprotected static final int STATUS_COMMITTED- See Also:
- Constant Field Values
 
- 
STATUS_ROLLEDBACKprotected static final int STATUS_ROLLEDBACK- See Also:
- Constant Field Values
 
- 
STATUS_ROLLING_BACKprotected static final int STATUS_ROLLING_BACK- See Also:
- Constant Field Values
 
- 
STATUS_NO_TRANSACTIONprotected static final int STATUS_NO_TRANSACTION- See Also:
- Constant Field Values
 
- 
STATUS_MARKED_ROLLEDBACKprotected static final int STATUS_MARKED_ROLLEDBACK- See Also:
- Constant Field Values
 
- 
connections
- 
listeners
- 
statusprotected int status
- 
defaultIsolationLevelprotected int defaultIsolationLevel
- 
descriptor
 
- 
- 
Constructor Details- 
BaseTransactionCreates new inactive transaction.
 
- 
- 
Method Details- 
bindThreadTransactionBinds a Transaction to the current thread.
- 
getThreadTransactionReturns a Transaction associated with the current thread, or null if there is no such Transaction.
- 
setRollbackOnlypublic void setRollbackOnly()- Specified by:
- setRollbackOnlyin interface- Transaction
 
- 
isRollbackOnlypublic boolean isRollbackOnly()- Specified by:
- isRollbackOnlyin interface- Transaction
 
- 
addListener- Specified by:
- addListenerin interface- Transaction
 
- 
beginpublic void begin()Starts a Transaction. If Transaction is not started explicitly, it will be started when the first connection is added.- Specified by:
- beginin interface- Transaction
 
- 
commitpublic void commit()- Specified by:
- commitin interface- Transaction
 
- 
processCommitprotected abstract void processCommit()
- 
rollbackpublic void rollback()- Specified by:
- rollbackin interface- Transaction
 
- 
processRollbackprotected abstract void processRollback()
- 
getConnectionsDescription copied from interface:TransactionReturns all connections associated with the transaction.- Specified by:
- getConnectionsin interface- Transaction
- Returns:
- connections associated with the transaction.
 
- 
getOrCreateConnectionpublic Connection getOrCreateConnection(String connectionName, DataSource dataSource) throws SQLExceptionDescription copied from interface:TransactionRetrieves a connection for the given symbolic name. If it does not exists, creates a new connection using provided DataSource, and registers it internally.- Specified by:
- getOrCreateConnectionin interface- Transaction
- Parameters:
- connectionName- a symbolic name of the connection. Cayenne DataNodes generate a name in the form of "DataNode.Connection.nodename".
- dataSource- DataSource that provides new connections.
- Returns:
- a connection that participates in the current transaction.
- Throws:
- SQLException
 
- 
getExistingConnection
- 
addConnection
- 
connectionAdded
- 
closeprotected void close()Closes all connections associated with transaction.
 
-