Search in sources :

Example 41 with ContextManager

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

the class T_FileSystemData method commonContainer.

/*
	 * create a container that all threads can use
	 */
private long commonContainer() throws T_Fail {
    ContextManager cm1 = contextService.newContextManager();
    contextService.setCurrentContextManager(cm1);
    long cid;
    try {
        Transaction t = t_util.t_startTransaction();
        cid = t_util.t_addContainer(t, 0);
        t_util.t_commit(t);
        t.close();
    } catch (StandardException se) {
        // Assume database is not active. DERBY-4856 thread dump
        cm1.cleanupOnError(se, false);
        throw T_Fail.exceptionFail(se);
    } finally {
        contextService.resetCurrentContextManager(cm1);
    }
    return cid;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 42 with ContextManager

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

the class T_StreamFile method commonContainer.

/*
	 * create a container that all threads can use
	 */
private long commonContainer() throws T_Fail {
    ContextManager cm1 = contextService.newContextManager();
    contextService.setCurrentContextManager(cm1);
    long cid;
    try {
        Transaction t = t_util.t_startTransaction();
        cid = t_util.t_addContainer(t, 0);
        t_util.t_commit(t);
        t.close();
    } catch (StandardException se) {
        // Assume database is not active. DERBY-4856 thread dump
        cm1.cleanupOnError(se, false);
        throw T_Fail.exceptionFail(se);
    } finally {
        contextService.resetCurrentContextManager(cm1);
    }
    return cid;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 43 with ContextManager

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

the class T_StreamFile method runTestSet.

/**
 *	  run the test
 *
 *	  @exception T_Fail Unexpected behaviour from the API
 */
protected void runTestSet() throws T_Fail {
    // get a utility helper
    ContextManager cm1 = contextService.newContextManager();
    contextService.setCurrentContextManager(cm1);
    try {
        // boundry case: 1 row, 13 columns, string types
        SF001(1, 13, T_RowSource.STRING_ROW_TYPE, false);
        // boundry case: 1 rows, 1 null column, string types
        SF001(1, 1, T_RowSource.STRING_ROW_TYPE, false);
        // boundry case: 1000 rows, 1 null column, string types
        SF001(1000, 1, T_RowSource.STRING_ROW_TYPE, false);
        // boundry case: 1000 rows, 2 column (first null, second not null), string types
        SF001(1000, 2, T_RowSource.STRING_ROW_TYPE, false);
        // boundry case: 500 rows, 9 columns (first & last column null), string types
        SF001(500, 9, T_RowSource.STRING_ROW_TYPE, false);
        // 500 rows, 13 column, string type
        SF001(500, 13, T_RowSource.STRING_ROW_TYPE, false);
        // test error condition
        SF001(1000, 2, T_RowSource.STRING_ROW_TYPE, true);
    // The following test tests externalizable types, but we currently don't support it.
    // do, don't run the test yet.
    // 100 rows, 5 column, Integer object type
    // SF001(100, 5, T_RowSource.INTEGER_ROW_TYPE, false);
    // 100 rows, 1 column, Integer object type
    // SF001(100, 1, T_RowSource.INTEGER_ROW_TYPE, false);
    // SF002() tests are used to check performance of the stream file.
    // no need to run them regularly.
    // SF002(0);
    // SF002(1);
    } catch (StandardException se) {
        // Assume database is not active. DERBY-4856 thread dump
        cm1.cleanupOnError(se, false);
        throw T_Fail.exceptionFail(se);
    } finally {
        contextService.resetCurrentContextManager(cm1);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 44 with ContextManager

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

the class commit_method method XATest_3.

/**
 * Test aborts of unprepared xa transaction.
 * <p>
 * @exception  StandardException  Standard exception policy.
 */
void XATest_3(commit_method commit_method) throws StandardException, T_Fail {
    REPORT("(XATest_3) starting");
    ContextManager cm = getContextService().getCurrentContextManager();
    // ABORT AN IDLE TRANSACTION.
    // Start a global transaction
    XATransactionController xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
    42, global_id, branch_id);
    // commit an idle transaction - using onePhase optimization.
    commit_method.rollback(42, global_id, branch_id, xa_tc);
    // done with this xact.
    xa_tc.destroy();
    // ABORT AN UPDATE ONLY TRANSACTION.
    // Start a global transaction
    xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
    42, global_id, branch_id);
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(1);
    long conglomid = xa_tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order - not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // commit an idle transaction - using onePhase optimization.
    commit_method.rollback(42, global_id, branch_id, xa_tc);
    // done with this xact.
    xa_tc.destroy();
    // ABORT A READ ONLY TRANSACTION.
    // Start a global transaction
    xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
    42, global_id, branch_id);
    // Create a heap conglomerate.
    template_row = new T_AccessRow(1);
    conglomid = xa_tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order - not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // commit an idle transaction - using onePhase optimization.
    commit_method.commit(true, 42, global_id, branch_id, xa_tc);
    // done with this xact.
    xa_tc.destroy();
    // Start a global transaction
    xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
    42, global_id, branch_id);
    // Open a scan on the conglomerate.
    ScanController scan1 = xa_tc.openScan(conglomid, // don't hold
    false, // not for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    scan1.next();
    scan1.close();
    // commit an idle transaction - using onePhase optimization.
    commit_method.rollback(42, global_id, branch_id, xa_tc);
    // done with this xact.
    xa_tc.destroy();
    REPORT("(XATest_3) finishing");
}
Also used : ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 45 with ContextManager

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

the class commit_method method commit.

public void commit(boolean one_phase, int format_id, byte[] global_id, byte[] branch_id, XATransactionController xa_tc) throws StandardException {
    if (SanityManager.DEBUG)
        SanityManager.ASSERT((global_id != null) || (xa_tc != null));
    boolean local_online_xact = online_xact;
    if (global_id == null)
        local_online_xact = true;
    if (xa_tc == null)
        local_online_xact = false;
    if (local_online_xact) {
        xa_tc.xa_commit(one_phase);
    } else {
        Xid xid = new XAXactId(format_id, global_id, branch_id);
        ContextManager cm = ((XAResourceManager) store.getXAResourceManager()).find(xid);
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(cm != null, "could not find xid = " + xid);
            SanityManager.ASSERT(cm == T_XA.getContextService().getCurrentContextManager(), "cm = " + cm + "current = " + T_XA.getContextService().getCurrentContextManager());
        }
        ((XAResourceManager) store.getXAResourceManager()).commit(cm, xid, one_phase);
    }
}
Also used : Xid(javax.transaction.xa.Xid) 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