public class ActiveTransaction
extends java.lang.Object
Only one instance of an ActiveTransaction may be in use for an instance of an ActiveDatabase at one time. Create one instance of an ActiveDatabase for each possible transaction that may occur at that same time.ActiveTransaction transaction = new ActiveTransaction(new ActiveDatabase(dataSource)); try { transaction.begin(); // ...some active operations... transaction.commit(); } catch (ActiveException e) { transaction.rollback(); }
Constructor and Description |
---|
ActiveTransaction()
Constructs for the default active database.
|
ActiveTransaction(ActiveDatabase activeDatabase)
Constructs an
ActiveDatabase . |
Modifier and Type | Method and Description |
---|---|
void |
begin()
Starts the transaction.
|
protected void |
close()
Cleans up resources that are used by this transaction.
|
void |
commit()
Completes the transaction.
|
ActiveDatabase |
getActiveDatabase()
Gets the active database associated with this transaction.
|
OperationTransaction |
getOperationTransaction()
Gets the operation transaction created by this transaction.
|
void |
rollback()
Rolls back the transaction.
|
public ActiveTransaction() throws ActiveException
ActiveDatabase.setDefault(ActiveDatabase)
prior to using
this constructor.
Use this constructor only if no other thread may be using it at the same time. This is
the case since there is only one default ActiveDatabase
per classloader and only one
transaction may be in use per ActiveDatabase
.
ActiveException
- if errorpublic ActiveTransaction(ActiveDatabase activeDatabase) throws ActiveException
ActiveDatabase
.activeDatabase
- active database associated with transactionActiveException
- if errorpublic ActiveDatabase getActiveDatabase()
ActiveTransaction()
was used or the one supplied in
ActiveTransaction(ActiveDatabase)
.public OperationTransaction getOperationTransaction()
public void begin() throws ActiveException
commit()
or rollback()
to close the transaction.
This method invokes ActiveDatabase.setActiveTransaction(ActiveTransaction)
to indicate
that this transaction is in use for the active database.ActiveException
- if errorpublic void commit() throws ActiveException
Connection.commit()
on the underlying
JDBC connection. This method invokes ActiveDatabase.setActiveTransaction(ActiveTransaction)
with a null parameter to indicate that no transaction is in use for the active database.ActiveException
- if errorpublic void rollback() throws ActiveException
Connection.rollback()
on the underlying
JDBC connection. This method invokes ActiveDatabase.setActiveTransaction(ActiveTransaction)
with a null parameter to indicate that no transaction is in use for the active database.ActiveException
- if errorprotected void close() throws ActiveException
ActiveException
- if error