Package org.apache.derby.iapi.services.context

Examples of org.apache.derby.iapi.services.context.ContextManager


  protected void runTestSet() throws T_Fail {

    // get a utility helper
    t_util = new T_Util(factory, lf, contextService);

    ContextManager cm1 = contextService.newContextManager();
    contextService.setCurrentContextManager(cm1);

    try {


      // Run the tests with data not logged for purges.
      REPORT("Running tests with no data logged  for purges");
      openMode = 0;    // logged by default
      runPurgeWithNoDataLoggesTests();

      // Run the tests in normal logged mode
      REPORT("Running tests with logging requested");
      openMode = 0;    // logged by default
      runEachTest();

     
      // run the tests on temp tables
      REPORT("Running tests for temp tables");
      testRollback = false// obviously, we can't test rollback if we are not logging
      runTempTests();

      // Run the tests in unlogged mode
      REPORT("Running tests in unlogged mode");
      openMode = ContainerHandle.MODE_UNLOGGED | ContainerHandle.MODE_CREATE_UNLOGGED;
      testRollback = false// obviously, we can't test rollback if we are not logging
      runEachTest();

      // if more runs are added here then you probably want to reset testRollback to
      // its initial value, or add the runs before the unlogged mode.

    } catch (StandardException se) {

      cm1.cleanupOnError(se);
      throw T_Fail.exceptionFail(se);
    }
    finally {
      contextService.resetCurrentContextManager(cm1);
    }
View Full Code Here


     throws StandardException, T_Fail
  {
    if (!testRollback)
      return;

    ContextManager previousCM = contextService.getCurrentContextManager();

    ContextManager cm1 = contextService.newContextManager();
    contextService.setCurrentContextManager(cm1);

    Transaction tuser = t_util.t_startTransaction();
    Transaction tinternal = null;

    try
    {

      long cid1 = t_util.t_addContainer(tuser, 0);
      ContainerHandle c1 = t_util.t_openContainer(tuser, 0, cid1, true);
      Page p1 = t_util.t_addPage(c1);
      t_util.t_commit(tuser);

      // insert a row using user transaction
      T_RawStoreRow row = new T_RawStoreRow(REC_001);

      c1 = t_util.t_openContainer(tuser, 0, cid1, true);
      p1 = t_util.t_getLastPage(c1);
      RecordHandle r1 = t_util.t_insert(p1, row);

      REPORT("starting internal transaction");

      tinternal = t_util.t_startInternalTransaction();
      long cid2 = t_util.t_addContainer(tinternal, 0);
      ContainerHandle c2 = t_util.t_openContainer(tinternal, 0, cid2, true);
      Page p2 = t_util.t_addPage(c2);
      RecordHandle r2 = t_util.t_insert(p2, row);

      // commit internal transaction
      tinternal.commit();
      tinternal.abort()// this will close the container and release
                // the page
      tinternal.close();
      tinternal = null;

      REPORT("commit internal transaction");

      // abort user transaction
      t_util.t_abort(tuser);

      REPORT("rollback user transaction");

      c1 = t_util.t_openContainer(tuser, 0, cid1, true);

      p1 = t_util.t_getPage(c1, r1.getPageNumber());
      if (p1.recordExists(r1, false))
        throw T_Fail.testFailMsg("user transaction failed to rollback");


      c2 = t_util.t_openContainer(tuser, 0, cid2, true);
      t_util.t_checkFetch(c2, r2, REC_001); // this should be unaffected by the
                     // user transaction rollback
      p2 = t_util.t_getLastPage(c2);

      T_RawStoreRow row2 = new T_RawStoreRow(REC_002);

      if (!p2.spaceForInsert())
      {
        REPORT("P054 not run, page cannot accomodate 2 rows");
        return;
      }
      RecordHandle r21 = t_util.t_insert(p2, row2);

      // throw an exception, make sure everything is aborted.
      tinternal = t_util.t_startInternalTransaction();
      long cid3 = t_util.t_addContainer(tinternal, 0);
      ContainerHandle c3 = t_util.t_openContainer(tinternal, 0, cid3, true);
      Page p3 = t_util.t_addPage(c3);
      RecordHandle r3 = t_util.t_insert(p3, row);
      try
      {
        // this will throw a data statement exception
        t_util.t_insertAtSlot(p3, 100, row);
      }
      catch (StandardException se)
      {
        REPORT("cleanup on error");
        cm1.cleanupOnError(se);
        REPORT("done cleanup on error");
      }

      tinternal = null;
      //   tuser = t_util.t_startTransaction();
View Full Code Here

     throws StandardException, T_Fail
  {
    if (!testRollback)
      return;

    ContextManager previousCM = contextService.getCurrentContextManager();
    Transaction longtran = null;

    ContextManager cm1 = null;
    Transaction t1 = null;

    ContextManager cm2 = null;
    Transaction t2 = null;

    // ContextManager cpm = null; // reserved for the checkpoint transaction
    try {

      T_RawStoreRow row1 = new T_RawStoreRow(REC_001);
      T_RawStoreRow row2 = new T_RawStoreRow(REC_002);
      T_RawStoreRow row3 = new T_RawStoreRow(REC_003);
      T_RawStoreRow row4 = new T_RawStoreRow(REC_004);
      T_RawStoreRow row5 = new T_RawStoreRow(REC_005);

      // start a long running transaction that spans multiple checkpoints
      // make sure it can be rolled back a the end
      longtran = t_util.t_startTransaction();

      long cid = t_util.t_addContainer(longtran, 0);
      ContainerHandle c = t_util.t_openContainer(longtran, 0, cid, true);
      RecordHandle r1 = t_util.t_insert(c, row1);
      RecordHandle r2 = t_util.t_insert(c, row2);
      t_util.t_commit(longtran);

      c = t_util.t_openContainer(longtran, 0, cid, true);
      Page p2 = t_util.t_getPage(c, r2.getPageNumber());
      p2.update(r2, row5.getRow(), (FormatableBitSet) null);
      p2.unlatch();


      // a bunch of short running transactions that criss cross the
      // checkpoints

      cm1 = contextService.newContextManager();
      contextService.setCurrentContextManager(cm1);
      t1 = t_util.t_startTransaction();

      long cid1 = t_util.t_addContainer(t1, 0);
      ContainerHandle c1 = t_util.t_openContainer(t1, 0, cid1, true);
      RecordHandle r3 = t_util.t_insert(c1, row3);
      RecordHandle r4 = t_util.t_insert(c1, row4);
      contextService.resetCurrentContextManager(cm1);

      cm2 = contextService.newContextManager();
      contextService.setCurrentContextManager(cm2);
      t2 = t_util.t_startTransaction();

      long cid2 = t_util.t_addContainer(t2, 0);
      ContainerHandle c2 = t_util.t_openContainer(t2, 0, cid2, true);
      RecordHandle r5 = t_util.t_insert(c2, row1);
      t_util.t_commit(t2);
      c2 = t_util.t_openContainer(t2, 0, cid2, true);
      Page p5 = t_util.t_getPage(c2, r5.getPageNumber());
      p5.update(r5, row5.getRow(), (FormatableBitSet) null);
      p5.unlatch();

      //    cpm = contextService.newContextManager();
      //    contextService.setCurrentContextManager(cpm);
      factory.checkpoint();
      contextService.resetCurrentContextManager(cm2);


      // make sure checkpoint did not destroy any data
      contextService.setCurrentContextManager(previousCM);
      t_util.t_checkFetch(c, r1, REC_001);
      t_util.t_checkFetch(c, r2, REC_005);
      contextService.resetCurrentContextManager(previousCM);

      contextService.setCurrentContextManager(cm1);
      t_util.t_checkFetch(c1, r3, REC_003);
      t_util.t_checkFetch(c1, r4, REC_004);
      contextService.resetCurrentContextManager(cm1);

      contextService.setCurrentContextManager(cm2);
      t_util.t_checkFetch(c2, r5, REC_005);

      // two consecutive checkpoints
      //    contextService.setCurrentContextManager(cpm);
      factory.checkpoint();
      contextService.resetCurrentContextManager(cm2);

      // we can insert some more
      contextService.setCurrentContextManager(previousCM);
      Page page = t_util.t_addPage(c);
      RecordHandle r6 = t_util.t_insertAtSlot(page, 0, row1, Page.INSERT_UNDO_WITH_PURGE);
      page.unlatch();
      contextService.resetCurrentContextManager(previousCM);

      // commit/abort everything except the long running transaction
      contextService.setCurrentContextManager(cm1);
      t_util.t_commit(t1);
      contextService.resetCurrentContextManager(cm1);

      contextService.setCurrentContextManager(cm2);
      t_util.t_abort(t2);
      contextService.resetCurrentContextManager(cm2);

      contextService.setCurrentContextManager(previousCM);
      t_util.t_checkFetch(c, r1, REC_001);
      t_util.t_checkFetch(c, r2, REC_005);
      t_util.t_checkFetch(c, r6, REC_001);
      contextService.resetCurrentContextManager(previousCM);

      contextService.setCurrentContextManager(cm1);
      c1 = t_util.t_openContainer(t1, 0, cid1, true);
      t_util.t_checkFetch(c1, r3, REC_003);
      t_util.t_checkFetch(c1, r4, REC_004);
      contextService.resetCurrentContextManager(cm1);

      contextService.setCurrentContextManager(cm2);
      c2 = t_util.t_openContainer(t2, 0, cid2, true);
      t_util.t_checkFetch(c2, r5, REC_001);

      // checkpoint again
      //    contextService.setCurrentContextManager(cpm);
      factory.checkpoint();
      contextService.resetCurrentContextManager(cm2);

      contextService.setCurrentContextManager(previousCM);
      t_util.t_abort(longtran);
      c = t_util.t_openContainer(longtran, 0, cid, true);
      t_util.t_checkFetch(c, r1, REC_001);
      t_util.t_checkFetch(c, r2, REC_002);

      Page p6 = t_util.t_getPage(c, r6.getPageNumber());
      t_util.t_checkEmptyPage(p6);
      p6.unlatch();

      t_util.t_dropContainer(longtran, 0, cid); // cleanup
      contextService.resetCurrentContextManager(previousCM);

      contextService.setCurrentContextManager(cm1);
      t_util.t_checkFetch(c1, r3, REC_003);
      t_util.t_checkFetch(c1, r4, REC_004);
      t_util.t_dropContainer(t1, 0, cid1);
      contextService.resetCurrentContextManager(cm1);

      contextService.setCurrentContextManager(cm2);
      t_util.t_checkFetch(c2, r5, REC_001);
      t_util.t_dropContainer(t2, 0, cid2);

      // checkpoint again
      //    contextService.setCurrentContextManager(cpm);
        factory.checkpoint();
      contextService.resetCurrentContextManager(cm2);

      PASS("CP001");


    }
    catch (Throwable t)
    {
      t.printStackTrace(System.err);

      if (cm1 != null)
        cm1.cleanupOnError(t);
      if (cm2 != null)
        cm2.cleanupOnError(t);
      //    if (cpm != null)
      //      cpm.cleanupOnError(t);

    } finally {
View Full Code Here

   *
   * @exception StandardException thrown if something goes wrong
   */
  private void resetSavepoints() throws StandardException
  {
    final ContextManager cm = getContextManager();
    final List stmts = cm.getContextStack(org.apache.derby.
                        iapi.reference.
                        ContextId.LANG_STATEMENT);
    final int end = stmts.size();
    for (int i = 0; i < end; ++i) {
      ((StatementContext)stmts.get(i)).resetSavePoint();
View Full Code Here

     * @param global_id The global transaction we are searching for.
     **/
  public ContextManager findTransactionContextByGlobalId(
    GlobalXactId global_id)
  {
        ContextManager cm              = null;

        // Need to hold sync while linear searching the hash table.
        synchronized (trans)
        {
            for (Enumeration e = trans.elements(); e.hasMoreElements();)
View Full Code Here

      // need to invalidate the statement
      if (!isValid || (inUseCount != 0))
        return;

      ContextManager cm = ContextService.getFactory().getCurrentContextManager();
      LanguageConnectionContext lcc =
        (LanguageConnectionContext)
        (cm.getContext(LanguageConnectionContext.CONTEXT_ID));

      // invalidate any prepared statements that
      // depended on this statement (including this one)
      // prepareToInvalidate(this, DependencyManager.PREPARED_STATEMENT_INVALID);
      try
View Full Code Here

     * NOTE - We do the conversion here since ORs will eventually be
     * optimizable and there's no benefit for the optimizer to see NOT BETWEEN
     */

    NodeFactory nodeFactory = getNodeFactory();
    ContextManager cm = getContextManager();

    /* leftO < rightOList.elementAt(0) */
    leftBCO = (BinaryComparisonOperatorNode)
          nodeFactory.getNode(
                  C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE,
View Full Code Here

     *           /   \
     *          <=    TRUE
     */

    NodeFactory nodeFactory = getNodeFactory();
    ContextManager cm = getContextManager();

        QueryTreeNode trueNode = nodeFactory.getNode(
                      C_NodeTypes.BOOLEAN_CONSTANT_NODE,
                      Boolean.TRUE,
                      cm);
View Full Code Here

     * to:
     *    leftO >= rightOList.elementAt(0) and leftO <= rightOList.elementAt(1)
     */

    NodeFactory nodeFactory = getNodeFactory();
    ContextManager cm = getContextManager();

    /* leftO >= rightOList.elementAt(0) */
    leftBCO = (BinaryComparisonOperatorNode)
          nodeFactory.getNode(
              C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE,
View Full Code Here

                    C_NodeTypes.TABLE_NAME,
                    null,
                    null,
                    getContextManager());

    ContextManager cm = getContextManager();

    int size = size();
    for (int index = 0; index < size; index++)
    {
      boolean     nullableResult;
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.services.context.ContextManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.