|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sqlg2.db.TransactionRunnable<R>
R
- type of a value computed by the transactional blockpublic abstract class TransactionRunnable<R>
Utility class to run ITransaction
s safely.
Constructor Summary | |
---|---|
TransactionRunnable()
|
Method Summary | ||
---|---|---|
protected void |
commit()
Commits transaction |
|
|
getInterface(java.lang.Class<T> cls)
Returns data access interface generated by preprocessor running in the transaction. |
|
protected void |
rollback()
Rolls back transaction |
|
protected abstract R |
run()
Implement this method to define which block to run in transaction. |
|
static
|
runInTransaction(IDBInterface db,
TransactionRunnable<T> runnable)
Run block in transaction atomically: block is either committed or rolled back. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TransactionRunnable()
Method Detail |
---|
protected final void commit() throws java.sql.SQLException, java.rmi.RemoteException
java.sql.SQLException
java.rmi.RemoteException
protected final void rollback() throws java.sql.SQLException, java.rmi.RemoteException
java.sql.SQLException
java.rmi.RemoteException
public final <T extends IDBCommon> T getInterface(java.lang.Class<T> cls) throws java.rmi.RemoteException
getInterface
in interface ISimpleTransaction
cls
- interface class
java.rmi.RemoteException
protected abstract R run() throws java.sql.SQLException, java.rmi.RemoteException
java.sql.SQLException
java.rmi.RemoteException
public static <T> T runInTransaction(IDBInterface db, TransactionRunnable<T> runnable) throws java.sql.SQLException, java.rmi.RemoteException
ITransaction
manually since you can forget to finish transaction.
Anyway you should call either commit()
or
rollback()
at the end of block, or else transaction will be rolled
back automatically.
Example:
TransactionRunnable.runInTransaction(db, new TransactionRunnable<Void>() { public Void run() { ITest testIface = getInterface(ITest.class); // work with testIFace in the transaction commit(); return null; } });
java.sql.SQLException
java.rmi.RemoteException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |