use of org.apache.derby.iapi.store.raw.Transaction 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);
}
use of org.apache.derby.iapi.store.raw.Transaction in project derby by apache.
the class RAMAccessManager method startXATransaction.
/**
* Start a global transaction.
* <p>
* Get a transaction controller with which to manipulate data within
* the access manager. Implicitly creates an access context.
* <p>
* Must only be called if no other transaction context exists in the
* current context manager. If another transaction exists in the context
* an exception will be thrown.
* <p>
* The (format_id, global_id, branch_id) triplet is meant to come exactly
* from a javax.transaction.xa.Xid. We don't use Xid so that the system
* can be delivered on a non-1.2 vm system and not require the javax classes
* in the path.
*
* @param cm The context manager for the current context.
* @param format_id the format id part of the Xid - ie. Xid.getFormatId().
* @param global_id the global transaction identifier part of XID - ie.
* Xid.getGlobalTransactionId().
* @param branch_id The branch qualifier of the Xid - ie.
* Xid.getBranchQaulifier()
*
* @exception StandardException Standard exception policy.
* @see TransactionController
*/
public /* XATransactionController */
Object startXATransaction(ContextManager cm, int format_id, byte[] global_id, byte[] branch_id) throws StandardException {
RAMTransaction xa_tc = null;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(global_id != null);
SanityManager.ASSERT(branch_id != null);
}
if (cm == null)
// XXX (nat) should throw exception
return null;
// See if there's already a transaction context.
RAMTransactionContext rtc = (RAMTransactionContext) cm.getContext(AccessFactoryGlobals.RAMXACT_CONTEXT_ID);
if (rtc == null) {
// No transaction context. Create or find a raw store 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.
Transaction rawtran = rawstore.startGlobalTransaction(cm, format_id, global_id, branch_id);
xa_tc = new RAMTransaction(this, rawtran, null);
rtc = new RAMTransactionContext(cm, AccessFactoryGlobals.RAMXACT_CONTEXT_ID, xa_tc, false);
if (xactProperties != null) {
rawtran.setup(xa_tc);
// HACK - special support has been added to the commitNoSync
// of a global xact, to allow committing of read only xact,
// which will allow subsequent activity on the xact keeping
// the same global transaction id.
xa_tc.commitNoSync(TransactionController.RELEASE_LOCKS | TransactionController.READONLY_TRANSACTION_INITIALIZATION);
}
rawtran.setDefaultLockingPolicy(system_default_locking_policy);
// HACK - special support has been added to the commitNoSync
// of a global xact, to allow committing of read only xact,
// which will allow subsequent activity on the xact keeping
// the same global transaction id.
xa_tc.commitNoSync(TransactionController.RELEASE_LOCKS | TransactionController.READONLY_TRANSACTION_INITIALIZATION);
} else {
// throw an error.
if (SanityManager.DEBUG)
SanityManager.THROWASSERT("RAMTransactionContext found on stack.");
}
return (xa_tc);
}
use of org.apache.derby.iapi.store.raw.Transaction in project derby by apache.
the class Heap method addColumn.
/*
** Methods of Conglomerate
*/
/**
* Add a column to the heap conglomerate.
* <p>
* This routine update's the in-memory object version of the Heap
* Conglomerate to have one more column of the type described by the
* input template column.
*
* @param column_id The column number to add this column at.
* @param template_column An instance of the column to be added to table.
* @param collation_id Collation id of the column added.
*
* @exception StandardException Standard exception policy.
*/
public void addColumn(TransactionManager xact_manager, int column_id, Storable template_column, int collation_id) throws StandardException {
// need to open the container and update the row containing the
// serialized format of the heap.
ContainerHandle container = null;
Page page = null;
Transaction rawtran = xact_manager.getRawStoreXact();
try {
container = rawtran.openContainer(id, rawtran.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true), ContainerHandle.MODE_FORUPDATE | (isTemporary() ? ContainerHandle.MODE_TEMP_IS_KEPT : 0));
if (column_id != format_ids.length) {
if (SanityManager.DEBUG)
SanityManager.THROWASSERT("Expected (column_id == format_ids.length)" + "column_id = " + column_id + "format_ids.length = " + format_ids.length + "format_ids = " + format_ids);
throw (StandardException.newException(SQLState.HEAP_TEMPLATE_MISMATCH, column_id, this.format_ids.length));
}
// create a new array, and copy old values to it.
int[] old_format_ids = format_ids;
format_ids = new int[old_format_ids.length + 1];
System.arraycopy(old_format_ids, 0, format_ids, 0, old_format_ids.length);
// add the new column
format_ids[old_format_ids.length] = template_column.getTypeFormatId();
// create a new collation array, and copy old values to it.
int[] old_collation_ids = collation_ids;
collation_ids = new int[old_collation_ids.length + 1];
System.arraycopy(old_collation_ids, 0, collation_ids, 0, old_collation_ids.length);
// add the new column's collation id.
collation_ids[old_collation_ids.length] = collation_id;
// row in slot 0 of heap page 1 which is just a single column with
// the heap entry.
DataValueDescriptor[] control_row = new DataValueDescriptor[1];
control_row[0] = this;
page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
page.updateAtSlot(Page.FIRST_SLOT_NUMBER, control_row, (FormatableBitSet) null);
page.unlatch();
page = null;
} finally {
if (container != null)
container.close();
if (page != null)
page.unlatch();
}
return;
}
Aggregations