Package org.apache.cayenne.tx
Class ReadOnlyTransaction
java.lang.Object
org.apache.cayenne.tx.ReadOnlyTransaction
- All Implemented Interfaces:
Transaction
A minimal
Transaction for read-only (selecting) queries that run outside a managed
transaction. It is not a real transaction - it exists only so that a DataNode has a thread-bound
transaction to acquire and release its connection through, and it keeps that connection in
autocommit mode (each select commits on its own, which is optimal for reads). It never commits or
rolls back, and fires no TransactionListener events.
Reads that require a real transaction (e.g. materializing PostgreSQL oid/BLOB large
objects) are not routed here - they use a CayenneTransaction.
- Since:
- 5.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(TransactionListener listener) voidbegin()Starts a Transaction.voidcommit()Returns all connections associated with the transaction.getOrCreateConnection(String connectionName, DataSource dataSource) Retrieves a connection for the given symbolic name.booleanIs this transaction managed by external transaction managerbooleanvoidrollback()void
-
Constructor Details
-
ReadOnlyTransaction
public ReadOnlyTransaction()
-
-
Method Details
-
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
-
commit
public void commit()- Specified by:
commitin interfaceTransaction
-
rollback
public void rollback()- Specified by:
rollbackin interfaceTransaction
-
getConnections
Description copied from interface:TransactionReturns all connections associated with the transaction.- Specified by:
getConnectionsin interfaceTransaction- Returns:
- connections associated with the transaction.
-
begin
public void begin()Description copied from interface:TransactionStarts a Transaction. If Transaction is not started explicitly, it will be started when the first connection is added.- Specified by:
beginin interfaceTransaction
-
setRollbackOnly
public void setRollbackOnly()- Specified by:
setRollbackOnlyin interfaceTransaction
-
isRollbackOnly
public boolean isRollbackOnly()- Specified by:
isRollbackOnlyin interfaceTransaction
-
addListener
- Specified by:
addListenerin interfaceTransaction
-
isExternal
public boolean isExternal()Description copied from interface:TransactionIs this transaction managed by external transaction manager- Specified by:
isExternalin interfaceTransaction
-