Package org.copperengine.core.db.utility
Class RetryingTransaction<R>
- java.lang.Object
-
- org.copperengine.core.db.utility.RetryingTransaction<R>
-
- All Implemented Interfaces:
Transaction<R>
public abstract class RetryingTransaction<R> extends java.lang.Object implements Transaction<R>
A simple transaction implementation for COPPER applications. Retrying means that the user's implementation of execute() will automatically be retried in case of technical failures.
-
-
Constructor Summary
Constructors Constructor Description RetryingTransaction(java.lang.String name, javax.sql.DataSource ds)
RetryingTransaction(java.lang.String name, javax.sql.DataSource ds, boolean modificatory)
RetryingTransaction(javax.sql.DataSource ds)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.sql.Connection
aquireConnection(boolean validateNewConnection)
protected RetryAction
check4retry(java.sql.SQLException e, int seqNr)
protected abstract R
execute()
This function is to be implemented by anonymous inner classes.java.sql.Connection
getConnection()
static RetryingTransaction<?>
getCurrent()
int
getMaxConnectRetries()
R
run()
This function implements error handling (i.e.static void
setDefaultSQLExceptionProcessor(SQLExceptionProcessor defaultSQLExceptionProcessor)
Transaction<R>
setMaxConnectRetries(int maxConnectRetries)
void
setSqlExceptionProcessor(SQLExceptionProcessor sqlExceptionProcessor)
-
-
-
Constructor Detail
-
RetryingTransaction
public RetryingTransaction(java.lang.String name, javax.sql.DataSource ds)
-
RetryingTransaction
public RetryingTransaction(javax.sql.DataSource ds)
-
RetryingTransaction
public RetryingTransaction(java.lang.String name, javax.sql.DataSource ds, boolean modificatory)
-
-
Method Detail
-
getCurrent
public static RetryingTransaction<?> getCurrent()
-
setDefaultSQLExceptionProcessor
public static void setDefaultSQLExceptionProcessor(SQLExceptionProcessor defaultSQLExceptionProcessor)
-
setSqlExceptionProcessor
public void setSqlExceptionProcessor(SQLExceptionProcessor sqlExceptionProcessor)
-
execute
protected abstract R execute() throws java.lang.Exception
This function is to be implemented by anonymous inner classes. Usage should look like this:... new RetryingTransaction<ReturnType>("TestTransaction") { protected ReturnType execute() { doSomething(); doAnotherThing(); return ...; } }.run();
- Returns:
- any type which shall be passed back after execution succeeded.
- Throws:
java.lang.Exception
- Any exception which could happen in an implementation of this method
-
getConnection
public java.sql.Connection getConnection()
-
run
public final R run() throws java.lang.Exception
This function implements error handling (i.e. transaction rollbacks in case of exceptions etc.), and automatic retries in case of deadlocks or timeouts.- Specified by:
run
in interfaceTransaction<R>
- Throws:
java.lang.Exception
-
check4retry
protected RetryAction check4retry(java.sql.SQLException e, int seqNr)
-
aquireConnection
protected java.sql.Connection aquireConnection(boolean validateNewConnection) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getMaxConnectRetries
public int getMaxConnectRetries()
-
setMaxConnectRetries
public Transaction<R> setMaxConnectRetries(int maxConnectRetries)
-
-