Package org.datanucleus.store.rdbms
Class AbstractSchemaTransaction
- java.lang.Object
-
- org.datanucleus.store.rdbms.AbstractSchemaTransaction
-
- Direct Known Subclasses:
DeleteTablesSchemaTransaction
,ValidateTableSchemaTransaction
public abstract class AbstractSchemaTransaction extends 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
Fields Modifier and Type Field Description protected int
isolationLevel
protected int
maxRetries
protected org.datanucleus.store.connection.ManagedConnection
mconn
protected RDBMSStoreManager
rdbmsMgr
-
Constructor Summary
Constructors Constructor Description AbstractSchemaTransaction(RDBMSStoreManager rdbmsMgr, int isolationLevel)
Constructs a new management transaction having the given isolation level.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
execute(org.datanucleus.ClassLoaderResolver clr)
Executes the schema transaction.protected Connection
getCurrentConnection()
Returns the current connection for the schema transaction.protected abstract void
run(org.datanucleus.ClassLoaderResolver clr)
Implements the body of the transaction.abstract String
toString()
Returns a description of the management transaction.
-
-
-
Field Detail
-
rdbmsMgr
protected final RDBMSStoreManager rdbmsMgr
-
isolationLevel
protected final int isolationLevel
-
maxRetries
protected final int maxRetries
-
mconn
protected org.datanucleus.store.connection.ManagedConnection mconn
-
-
Constructor Detail
-
AbstractSchemaTransaction
public AbstractSchemaTransaction(RDBMSStoreManager rdbmsMgr, int isolationLevel)
Constructs a new management transaction having the given isolation level.- Parameters:
rdbmsMgr
- RDBMSManager to useisolationLevel
- One of the isolation level constants from java.sql.Connection.
-
-
Method Detail
-
toString
public abstract String toString()
Returns a description of the management transaction. Subclasses should override this method so that transaction failures are given an appropriate exception message.
-
run
protected abstract void run(org.datanucleus.ClassLoaderResolver clr) throws SQLException
Implements the body of the transaction.- Parameters:
clr
- the ClassLoaderResolver- Throws:
SQLException
- Thrown if the transaction fails due to a database error that should allow the entire transaction to be retried.
-
getCurrentConnection
protected Connection getCurrentConnection() throws SQLException
Returns the current connection for the schema transaction. Creates one if needed- Returns:
- the connection
- Throws:
SQLException
- thrown when an error occurs getting the connection
-
execute
public final void execute(org.datanucleus.ClassLoaderResolver clr)
Executes the schema transaction. A database connection is acquired and theexecute(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 persistence property "datanucleus.rdbms.classAdditionMaxRetries".- Parameters:
clr
- the ClassLoaderResolver- Throws:
org.datanucleus.exceptions.NucleusDataStoreException
- If a SQL exception occurred even after "maxRetries" attempts.
-
-