|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.triactive.jdo.store.RetryableTransaction
An abstract base class for JDBC transactions that can be retried in the face
of transient failures.
Subclasses must override, among others, the execute(int)
method to
implement the body of the transaction.
Users call the execute()
method to execute the transaction.
Field Summary | |
protected java.sql.Connection |
conn
|
Constructor Summary | |
RetryableTransaction(int isolationLevel)
Constructs a new transaction having the given isolation level. |
|
RetryableTransaction(int isolationLevel,
int maxRetries)
Constructs a new transaction having the given isolation level and number of retries. |
Method Summary | |
java.lang.Object |
execute()
Executes the transaction. |
protected abstract java.lang.Object |
execute(int attempts)
Implements the body of the transaction. |
void |
executeStatements(java.util.Collection stmts)
Convenience method for executing a collection of SQL statements during the transaction. |
java.sql.Connection |
getConnection()
Returns the JDBC connection currently being used by the transaction. |
protected abstract InitializedConnectionFactory |
getConnectionFactory()
Returns the connection factory from which this object obtains its JDBC connections. |
abstract DatabaseAdapter |
getDatabaseAdapter()
Returns the database adapter associated with connections provided by this object's connection factory. |
abstract java.lang.String |
toString()
Returns a description of the transaction. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.sql.Connection conn
Constructor Detail |
public RetryableTransaction(int isolationLevel)
isolationLevel
- One of the isolation level constants from java.sql.Connection.public RetryableTransaction(int isolationLevel, int maxRetries)
isolationLevel
- One of the isolation level constants from java.sql.Connection.maxRetries
- The maximum number of times the transaction will be tried. The
value includes the first attempt.Method Detail |
protected abstract InitializedConnectionFactory getConnectionFactory()
public abstract DatabaseAdapter getDatabaseAdapter()
public final java.lang.Object execute()
A database connection is acquired and the execute(int)
method
is invoked.
If the selected isolation level is not Connection.TRANSACTION_NONE, then
commit() or rollback() is called on the connection according to whether
the invocation succeeded or threw an exception.
If the invocation fails due to a SQLException, and the failure is
considered worth retrying, the transaction is repeated up to the
specified number of retries.
"Worth retrying" is defined by the exception's SQLSTATE
code.
If the driver doesn't provide SQLSTATE codes then all exceptions are
considered worth retrying.
inner execute
method
.
javax.jdo.JDODataStoreException
- If a SQL exception occurred even after retrying.SqlState.isWorthRetrying()
public final java.sql.Connection getConnection()
java.lang.IllegalStateException
- if the transaction object is not in the process of being executedprotected abstract java.lang.Object execute(int attempts) throws java.sql.SQLException
conn
field.
If the selected isolation level is Connection.TRANSACTION_NONE the
connection has auto-commit set to true, otherwise it's false.
attempts
- The number of times this transaction has already been attempted.
If greater than zero then this is a retry.
java.sql.SQLException
- If the transaction fails due to a database error that might allow
the entire transaction to be retried.public void executeStatements(java.util.Collection stmts) throws java.sql.SQLException
stmts
- A collection of string that are the statements to be executed. The
statements are executed in the order returned by the collection's
iterator.
java.lang.IllegalStateException
- if the transaction object is not in the process of being executed
java.sql.SQLException
- if a database error occurspublic abstract java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |