public class Transaction
extends java.lang.Object
Connection
. This class is not required for
most sormula programming and is only used by Database
as a convenience. Other
transaction mechanisms are compatible with sormula. This is required for cached tables.Constructor and Description |
---|
Transaction(java.sql.Connection connection)
Constructs for a connection.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(TransactionListener listener)
Adds a listener that will be notified of
Transaction events. |
void |
begin()
Starts the transaction.
|
protected void |
cleanUp()
Sets
isActive() to false and restores auto commit to the original state. |
void |
commit()
Commits the transaction by invoking
Connection.commit() . |
java.sql.Connection |
getConnection()
Gets the connection supplied in the constructor.
|
protected java.util.List<TransactionListener> |
getListeners()
Gets list of listeners that were added with
addListener(TransactionListener) . |
boolean |
isActive()
Reports if transaction is ongoing.
|
protected void |
notifyBegin()
Invokes
TransactionListener.begin(Transaction) for all listeners. |
protected void |
notifyCommit()
Invokes
TransactionListener.commit(Transaction) for all listeners. |
protected void |
notifyRollback()
Invokes
TransactionListener.rollback(Transaction) for all listeners. |
void |
removeListener(TransactionListener listener)
Removes a transaction listener.
|
void |
rollback()
Aborts the transaction by invoking
Connection.rollback() . |
protected void |
setActive(boolean active)
Sets the active indicator.
|
void |
setConnection(java.sql.Connection connection)
Sets new connection for transaction.
|
public Transaction(java.sql.Connection connection)
connection
- JDBC connectionpublic java.sql.Connection getConnection()
public void setConnection(java.sql.Connection connection) throws SormulaException
Typically invoked by Database
when a new connection is obtained. New connection
is obtained after Database.close()
is used followed by invoking a method that accesses
the database.
connection
- JDBC connection to use; null if connection has been closedSormulaException
- if errorpublic boolean isActive()
begin()
has been invoked but not commit()
or rollback()
protected void setActive(boolean active)
active
- true if begin()
was invoked but neither commit()
nor
rollback()
has been invokedpublic void begin() throws SormulaException
SormulaException
- if errorpublic void commit() throws SormulaException
Connection.commit()
.SormulaException
- if errorpublic void rollback() throws SormulaException
Connection.rollback()
.SormulaException
- if errorpublic void addListener(TransactionListener listener)
Transaction
events.listener
- notify this class of transaction eventspublic void removeListener(TransactionListener listener)
listener
- listener to removeprotected java.util.List<TransactionListener> getListeners()
addListener(TransactionListener)
.protected void cleanUp()
isActive()
to false and restores auto commit to the original state.protected void notifyBegin()
TransactionListener.begin(Transaction)
for all listeners.protected void notifyCommit()
TransactionListener.commit(Transaction)
for all listeners.protected void notifyRollback()
TransactionListener.rollback(Transaction)
for all listeners.