Class AbstractSchemaTransaction

  • Direct Known Subclasses:
    DeleteTablesSchemaTransaction, RDBMSStoreManager.ClassAdder, 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.

    • 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 java.sql.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 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

      • isolationLevel

        protected final int isolationLevel
      • maxRetries

        protected final int maxRetries
      • mconn

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

        private java.sql.Connection conn
    • Constructor Detail

      • 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 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
        Returns the current connection for the schema transaction. Creates one if needed
        Returns:
        the connection
        Throws:
        java.sql.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.