Package org.apache.cayenne.tx
Class BaseTransaction
java.lang.Object
org.apache.cayenne.tx.BaseTransaction
- All Implemented Interfaces:
Transaction
- Direct Known Subclasses:
CayenneTransaction,ExternalTransaction
A Cayenne transaction. Currently supports managing JDBC connections.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<String, Connection> protected intprotected TransactionDescriptorprotected Collection<TransactionListener> protected intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseTransaction(TransactionDescriptor descriptor) Creates new inactive transaction. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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) Returns all connections associated with the transaction.protected ConnectiongetExistingConnection(String name) getOrCreateConnection(String connectionName, DataSource dataSource) Retrieves a connection for the given symbolic name.static TransactionReturns a Transaction associated with the current thread, or null if there is no such Transaction.booleanprotected abstract voidprotected abstract voidvoidrollback()voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cayenne.tx.Transaction
isExternal
-
Field Details
-
STATUS_ACTIVE
protected static final int STATUS_ACTIVE- See Also:
-
STATUS_COMMITTING
protected static final int STATUS_COMMITTING- See Also:
-
STATUS_COMMITTED
protected static final int STATUS_COMMITTED- See Also:
-
STATUS_ROLLEDBACK
protected static final int STATUS_ROLLEDBACK- See Also:
-
STATUS_ROLLING_BACK
protected static final int STATUS_ROLLING_BACK- See Also:
-
STATUS_NO_TRANSACTION
protected static final int STATUS_NO_TRANSACTION- See Also:
-
STATUS_MARKED_ROLLEDBACK
protected static final int STATUS_MARKED_ROLLEDBACK- See Also:
-
connections
-
listeners
-
status
protected int status -
defaultIsolationLevel
protected int defaultIsolationLevel -
descriptor
-
-
Constructor Details
-
BaseTransaction
Creates new inactive transaction.
-
-
Method Details
-
bindThreadTransaction
Binds a Transaction to the current thread. -
getThreadTransaction
Returns a Transaction associated with the current thread, or null if there is no such Transaction. -
setRollbackOnly
public void setRollbackOnly()- Specified by:
setRollbackOnlyin interfaceTransaction
-
isRollbackOnly
public boolean isRollbackOnly()- Specified by:
isRollbackOnlyin interfaceTransaction
-
addListener
- Specified by:
addListenerin interfaceTransaction
-
begin
public void begin()Starts a Transaction. If Transaction is not started explicitly, it will be started when the first connection is added.- Specified by:
beginin interfaceTransaction
-
commit
public void commit()- Specified by:
commitin interfaceTransaction
-
processCommit
protected abstract void processCommit() -
rollback
public void rollback()- Specified by:
rollbackin interfaceTransaction
-
processRollback
protected abstract void processRollback() -
getConnections
Description copied from interface:TransactionReturns all connections associated with the transaction.- Specified by:
getConnectionsin interfaceTransaction- Returns:
- connections associated with the transaction.
-
getOrCreateConnection
public Connection getOrCreateConnection(String connectionName, DataSource dataSource) throws SQLException Description 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 interfaceTransaction- 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
-
close
protected void close()Closes all connections associated with transaction.
-