Search in sources :

Example 61 with ContextManager

use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.

the class RAMTransaction method startNestedUserTransaction.

/**
 * Get an nested user transaction.
 * <p>
 * A nested user can be used exactly as any other TransactionController,
 * except as follows.  For this discussion let the parent transaction
 * be the transaction used to make the getNestedUserTransaction(), and
 * let the child transaction be the transaction returned by the
 * getNestedUserTransaction() call.
 * <p>
 * The nesting is limited to one level deep.  An exception will be thrown
 * if a subsequent getNestedUserTransaction() is called on the child
 * transaction.
 * <p>
 * The locks in the child transaction will be compatible with the locks
 * of the parent transaction.
 * <p>
 * A commit in the child transaction will release locks associated with
 * the child transaction only, work can continue in the parent transaction
 * at this point.
 * <p>
 * Any abort of the child transaction will result in an abort of both
 * the child transaction and parent transaction.
 * <p>
 * A TransactionController.destroy() call should be made on the child
 * transaction once all child work is done, and the caller wishes to
 * continue work in the parent transaction.
 * <p>
 * Nested internal transactions are meant to be used to implement
 * system work necessary to commit as part of implementing a user's
 * request, but where holding the lock for the duration of the user
 * transaction is not acceptable.  2 examples of this are system catalog
 * read locks accumulated while compiling a plan, and auto-increment.
 * <p>
 *
 * @param readOnly                 Is transaction readonly?  Only 1 non-read
 *                                 only nested transaction is allowed per
 *                                 transaction.
 *
 * @param flush_log_on_xact_end    By default should the transaction commit
 *                                 and abort be synced to the log.  Normal
 *                                 usage should pick true, unless there is
 *                                 specific performance need and usage
 *                                 works correctly if a commit can be lost
 *                                 on system crash.
 *
 * @return The new nested user transaction.
 *
 * @exception  StandardException  Standard exception policy.
 */
public TransactionController startNestedUserTransaction(boolean readOnly, boolean flush_log_on_xact_end) throws StandardException {
    // Get the context manager.
    ContextManager cm = getContextManager();
    // Allocate a new transaction no matter what.
    // Create a transaction, make a context for it, and push the context.
    // Note this puts the raw store transaction context
    // above the access context, which is required for
    // error handling assumptions to be correct.
    // 
    // Note that the nested transaction inherits the compatibility space
    // from "this", thus the new transaction shares the compatibility space
    // of the current transaction.
    Transaction child_rawtran = ((readOnly) ? accessmanager.getRawStore().startNestedReadOnlyUserTransaction(rawtran, getLockSpace(), cm, AccessFactoryGlobals.NESTED_READONLY_USER_TRANS) : accessmanager.getRawStore().startNestedUpdateUserTransaction(rawtran, cm, AccessFactoryGlobals.NESTED_UPDATE_USER_TRANS, flush_log_on_xact_end));
    RAMTransaction rt = new RAMTransaction(accessmanager, child_rawtran, this);
    RAMTransactionContext rtc = new RAMTransactionContext(cm, AccessFactoryGlobals.RAMXACT_CHILD_CONTEXT_ID, rt, true);
    child_rawtran.setDefaultLockingPolicy(accessmanager.getDefaultLockingPolicy());
    return (rt);
}
Also used : Transaction(org.apache.derby.iapi.store.raw.Transaction) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Aggregations

ContextManager (org.apache.derby.iapi.services.context.ContextManager)61 StandardException (org.apache.derby.shared.common.error.StandardException)22 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)8 ContextService (org.apache.derby.iapi.services.context.ContextService)7 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)7 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)6 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)5 TransactionController (org.apache.derby.iapi.store.access.TransactionController)5 XAException (javax.transaction.xa.XAException)4 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)4 XAResourceManager (org.apache.derby.iapi.store.access.xa.XAResourceManager)4 XAXactId (org.apache.derby.iapi.store.access.xa.XAXactId)4 SQLException (java.sql.SQLException)3 Xid (javax.transaction.xa.Xid)3 Serviceable (org.apache.derby.iapi.services.daemon.Serviceable)3 ExecPreparedStatement (org.apache.derby.iapi.sql.execute.ExecPreparedStatement)3 RowLocation (org.apache.derby.iapi.types.RowLocation)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2