Class AbstractSchemaTransaction

java.lang.Object
org.datanucleus.store.rdbms.AbstractSchemaTransaction
Direct Known Subclasses:
DeleteTablesSchemaTransaction, RDBMSStoreManager.ClassAdder, 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 Details

    • rdbmsMgr

      protected final RDBMSStoreManager rdbmsMgr
    • isolationLevel

      protected final int isolationLevel
    • maxRetries

      protected final int maxRetries
    • mconn

      protected org.datanucleus.store.connection.ManagedConnection mconn
    • conn

      private Connection conn
  • Constructor Details

    • AbstractSchemaTransaction

      public AbstractSchemaTransaction(RDBMSStoreManager 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 Details

    • 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.
      Overrides:
      toString in class Object
      Returns:
      A description of the management transaction.
    • 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 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 persistence property "datanucleus.rdbms.classAdditionMaxRetries".
      Parameters:
      clr - the ClassLoaderResolver
      Throws:
      org.datanucleus.exceptions.NucleusDataStoreException - If a SQL exception occurred even after "maxRetries" attempts.