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);
}
Aggregations