public class NoOpTransaction extends Transaction
Transaction
that does not perform Connection.commit()
or
Connection.rollback()
. It does notify TransactionListener
objects
for begin()
, commit()
, and rollback()
.
This class is useful for cached operations when connection autocommit is true (that is when no sql transaction is used).
Set on existing database:
Database database = new Database(...); database.setTransaction(new NoOpTransaction(database.getConnection()));
Use through inheritance:
public class MyDatabase extends Database { public MyDatabase(...) throws SormulaException { super(...); } @Override protected Transaction initTransaction(Connection connection) throws SormulaException { return new NoOpTransaction(connection); } }
Constructor and Description |
---|
NoOpTransaction(java.sql.Connection connection)
Constructs for a connection.
|
Modifier and Type | Method and Description |
---|---|
void |
begin()
Starts the transaction.
|
void |
commit()
Commits the transaction by invoking
Connection.commit() . |
void |
rollback()
Aborts the transaction by invoking
Connection.rollback() . |
addListener, cleanUp, getConnection, getListeners, isActive, notifyBegin, notifyCommit, notifyRollback, removeListener, setActive, setConnection
public NoOpTransaction(java.sql.Connection connection)
connection
- JDBC connectionpublic void begin() throws SormulaException
begin
in class Transaction
SormulaException
- if errorpublic void commit() throws SormulaException
Connection.commit()
.commit
in class Transaction
SormulaException
- if errorpublic void rollback() throws SormulaException
Connection.rollback()
.rollback
in class Transaction
SormulaException
- if error