Package rife.database
Class DbTransactionUser<ResultType,DataType>
java.lang.Object
rife.database.DbTransactionUser<ResultType,DataType>
- All Implemented Interfaces:
Cloneable
,TransactionUser<ResultType>
- Direct Known Subclasses:
DbTransactionUserWithoutResult
public abstract class DbTransactionUser<ResultType,DataType>
extends Object
implements Cloneable, TransactionUser<ResultType>
By extending this class it's possible to provide the logic that should be
executed by the
inTransaction
method in the DbQueryManager
class.
This class has both a default constructor and one that can take a data
object. This can be handy when using it as an extending anonymous inner
class when you need to use variables inside the inner class that are
cumbersome to change to final
in the enclosing class.
- Since:
- 1.0
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Simply clones the instance with the default clone method since this class contains no member variables.getData()
int
Should be overridden if the transaction has to be executed in another isolation level.void
rollback()
Should be used to roll back ongoing transactions, otherwise enclosing transaction users might not be interrupted and subsequent modification can still happen outside the transaction.void
throwException
(Exception exception) Calling this method makes it possible to throw a checked exception from within this class.abstract ResultType
Should be implemented by all extending classes.
-
Field Details
-
data_
-
-
Constructor Details
-
DbTransactionUser
public DbTransactionUser() -
DbTransactionUser
-
-
Method Details
-
getData
-
getTransactionIsolation
public int getTransactionIsolation()Should be overridden if the transaction has to be executed in another isolation level.- Returns:
-1
when the active isolation level should be preserved; ora level constant from
Connection
if the isolation needs to be changed.- Since:
- 1.0
-
rollback
Should be used to roll back ongoing transactions, otherwise enclosing transaction users might not be interrupted and subsequent modification can still happen outside the transaction.- Throws:
RollbackException
- indicates that a rollback should happen and all further transaction logic interrupted.- Since:
- 1.0
-
throwException
Calling this method makes it possible to throw a checked exception from within this class.To catch it you should surround the
inTransaction
with atry-catch
block that catchingInnerClassException
. The original exception is then available throughgetCause()
and can for example be rethrown.- Throws:
InnerClassException
- when a checked exception needs to be thrown from within this class and caught outside the caller.- Since:
- 1.0
-
useTransaction
Should be implemented by all extending classes.- Specified by:
useTransaction
in interfaceTransactionUser<ResultType>
- Throws:
InnerClassException
- Since:
- 1.0
-
clone
Simply clones the instance with the default clone method since this class contains no member variables.
-