org.datanucleus.store.rdbms
Class AbstractSchemaTransaction

java.lang.Object
  extended by org.datanucleus.store.rdbms.AbstractSchemaTransaction
Direct Known Subclasses:
DeleteTablesSchemaTransaction, ValidateTableSchemaTransaction

public abstract class AbstractSchemaTransaction
extends java.lang.Object

An abstract base class for RDBMSManager transactions that perform some schema operation on the database.

Management transactions may be retried in the face of SQL exceptions to work around failures caused by transient conditions, such as DB deadlocks.


Field Summary
protected  int isolationLevel
           
protected  int maxRetries
           
protected  org.datanucleus.ManagedConnection mconn
           
protected  RDBMSManager rdbmsMgr
           
 
Constructor Summary
AbstractSchemaTransaction(RDBMSManager rdbmsMgr, int isolationLevel)
          Constructs a new management transaction having the given isolation level.
 
Method Summary
 void execute(org.datanucleus.ClassLoaderResolver clr)
          Executes the transaction.
protected  java.sql.Connection getCurrentConnection()
          Obtains the current connection for the transaction.
protected abstract  void run(org.datanucleus.ClassLoaderResolver clr)
          Implements the body of the transaction.
abstract  java.lang.String toString()
          Returns a description of the management transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rdbmsMgr

protected RDBMSManager rdbmsMgr

isolationLevel

protected final int isolationLevel

maxRetries

protected final int maxRetries

mconn

protected org.datanucleus.ManagedConnection mconn
Constructor Detail

AbstractSchemaTransaction

public AbstractSchemaTransaction(RDBMSManager rdbmsMgr,
                                 int isolationLevel)
Constructs a new management transaction having the given isolation level.

Parameters:
rdbmsMgr - RDBMSManager to use
isolationLevel - One of the isolation level constants from java.sql.Connection.
Method Detail

toString

public abstract java.lang.String toString()
Returns a description of the management transaction. Subclasses should override this method so that transaction failures are given an appropriate exception message.

Overrides:
toString in class java.lang.Object
Returns:
A description of the management transaction.

run

protected abstract void run(org.datanucleus.ClassLoaderResolver clr)
                     throws java.sql.SQLException
Implements the body of the transaction.

Parameters:
clr - the ClassLoaderResolver
Throws:
java.sql.SQLException - Thrown if the transaction fails due to a database error that should allow the entire transaction to be retried.

getCurrentConnection

protected java.sql.Connection getCurrentConnection()
                                            throws java.sql.SQLException
Obtains the current connection for the transaction. Creates one if needed

Returns:
the connection
Throws:
java.sql.SQLException

execute

public final void execute(org.datanucleus.ClassLoaderResolver clr)
Executes the transaction.

A database connection is acquired and the execute(ClassLoaderResolver)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 not. If the invocation failed the sequence is repeated, up to a maximum of maxRetries times, configurable by the system property datanucleus.store.maxRetries.

Parameters:
clr - the ClassLoaderResolver
Throws:
org.datanucleus.exceptions.NucleusDataStoreException - If a SQL exception occurred even after "maxRetries" attempts.


Copyright © 2009. All Rights Reserved.