Package org.apache.derby.iapi.store.access

Examples of org.apache.derby.iapi.store.access.TransactionController


    boolean defragmentRows,
    boolean truncateEnd)
        throws SQLException
  {
    LanguageConnectionContext lcc       = ConnectionUtil.getCurrentLCC();
    TransactionController     tc        = lcc.getTransactionExecute();

    try
        {
            DataDictionary data_dictionary = lcc.getDataDictionary();
View Full Code Here


        ScanController[]         index_scan          =  null;
        ConglomerateController[] index_cc            =  null;
        DataValueDescriptor[][]  index_row           =  null;

    LanguageConnectionContext lcc       = ConnectionUtil.getCurrentLCC();
    TransactionController     nested_tc = null;

    try {

            SchemaDescriptor sd =
                data_dictionary.getSchemaDescriptor(
                    schemaName, nested_tc, true);
            TableDescriptor td =
                data_dictionary.getTableDescriptor(tableName, sd);
            nested_tc =
                tc.startNestedUserTransaction(false);

            if (td == null)
            {
                throw StandardException.newException(
                    SQLState.LANG_TABLE_NOT_FOUND,
                    schemaName + "." + tableName);
            }

            switch (td.getTableType())
            {
            /* Skip views and vti tables */
            case TableDescriptor.VIEW_TYPE:
            case TableDescriptor.VTI_TYPE:
              return;
            // other types give various errors here
            // DERBY-719,DERBY-720
            default:
              break;
            }


      ConglomerateDescriptor heapCD =
                td.getConglomerateDescriptor(td.getHeapConglomerateId());

      /* Get a row template for the base table */
      ExecRow baseRow =
                lcc.getLanguageConnectionFactory().getExecutionFactory().getValueRow(
                    td.getNumberOfColumns());


      /* Fill the row with nulls of the correct type */
      ColumnDescriptorList cdl = td.getColumnDescriptorList();
      int           cdlSize = cdl.size();

      for (int index = 0; index < cdlSize; index++)
      {
        ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
        baseRow.setColumn(cd.getPosition(), cd.getType().getNull());
      }

            DataValueDescriptor[][] row_array = new DataValueDescriptor[100][];
            row_array[0] = baseRow.getRowArray();
            RowLocation[] old_row_location_array = new RowLocation[100];
            RowLocation[] new_row_location_array = new RowLocation[100];

            // Create the following 3 arrays which will be used to update
            // each index as the scan moves rows about the heap as part of
            // the compress:
            //     index_col_map - map location of index cols in the base row,
            //                     ie. index_col_map[0] is column offset of 1st
            //                     key column in base row.  All offsets are 0
            //                     based.
            //     index_scan - open ScanController used to delete old index row
            //     index_cc   - open ConglomerateController used to insert new
            //                  row

            ConglomerateDescriptor[] conglom_descriptors =
                td.getConglomerateDescriptors();

            // conglom_descriptors has an entry for the conglomerate and each
            // one of it's indexes.
            num_indexes = conglom_descriptors.length - 1;

            // if indexes exist, set up data structures to update them
            if (num_indexes > 0)
            {
                // allocate arrays
                index_col_map   = new int[num_indexes][];
                index_scan      = new ScanController[num_indexes];
                index_cc        = new ConglomerateController[num_indexes];
                index_row       = new DataValueDescriptor[num_indexes][];

                setup_indexes(
                    nested_tc,
                    td,
                    index_col_map,
                    index_scan,
                    index_cc,
                    index_row);

            }

      /* Open the heap for reading */
      base_group_fetch_cc =
                nested_tc.defragmentConglomerate(
                    td.getHeapConglomerateId(),
                    false,
                    true,
                    TransactionController.OPENMODE_FORUPDATE,
            TransactionController.MODE_TABLE,
          TransactionController.ISOLATION_SERIALIZABLE);

            int num_rows_fetched = 0;
            while ((num_rows_fetched =
                        base_group_fetch_cc.fetchNextGroup(
                            row_array,
                            old_row_location_array,
                            new_row_location_array)) != 0)
            {
                if (num_indexes > 0)
                {
                    for (int row = 0; row < num_rows_fetched; row++)
                    {
                        for (int index = 0; index < num_indexes; index++)
                        {
                            fixIndex(
                                row_array[row],
                                index_row[index],
                                old_row_location_array[row],
                                new_row_location_array[row],
                                index_cc[index],
                                index_scan[index],
                                index_col_map[index]);
                        }
                    }
                }
            }

            // TODO - It would be better if commits happened more frequently
            // in the nested transaction, but to do that there has to be more
            // logic to catch a ddl that might jump in the middle of the
            // above loop and invalidate the various table control structures
            // which are needed to properly update the indexes.  For example
            // the above loop would corrupt an index added midway through
            // the loop if not properly handled.  See DERBY-1188. 
            nested_tc.commit();
     
    }
    catch (StandardException se)
    {
      throw PublicAPI.wrapStandardException(se);
    }
    finally
    {
            try
            {
                /* Clean up before we leave */
                if (base_group_fetch_cc != null)
                {
                    base_group_fetch_cc.close();
                    base_group_fetch_cc = null;
                }

                if (num_indexes > 0)
                {
                    for (int i = 0; i < num_indexes; i++)
                    {
                        if (index_scan != null && index_scan[i] != null)
                        {
                            index_scan[i].close();
                            index_scan[i] = null;
                        }
                        if (index_cc != null && index_cc[i] != null)
                        {
                            index_cc[i].close();
                            index_cc[i] = null;
                        }
                    }
                }

                if (nested_tc != null)
                {
                    nested_tc.destroy();
                }

            }
            catch (StandardException se)
            {
View Full Code Here

    // Need a TransactionController to get database/service wide properties.
    AccessFactory af = (AccessFactory)
      Monitor.getServiceModule(dataFactory, AccessFactory.MODULE);

    // RESOLVE: sku defectid 2014
    TransactionController tc =
            (af == null) ?
                null :
                af.getTransaction(
                        ContextService.getFactory().getCurrentContextManager());
View Full Code Here

     * @throws StandardException
     */
    public void drop(LanguageConnectionContext lcc) throws StandardException {
       
        DataDictionary dd = getDataDictionary();
        TransactionController tc = lcc.getTransactionExecute();
        DependencyManager dm = dd.getDependencyManager();
       
       
        /* Prepare all dependents to invalidate.  (This is their chance
         * to say that they can't be invalidated.  For example, an open
View Full Code Here

        //bug 4821 - First try compiling on a nested transaction so we can release
        //the locks after the compilation. But if we get lock time out on the
        //nested transaction, then go ahead and do the compilation on the user
        //transaction. When doing the compilation on user transaction, the locks
        //acquired for recompilation will be released at the end of the user transaction.
        TransactionController nestedTC;
        try
        {
          nestedTC = lcc.getTransactionCompile().startNestedUserTransaction(false);
        }
        catch (StandardException se)
        {
          // If I cannot start a Nested User Transaction use the parent
          // transaction to do all the work.
          nestedTC = null;
        }

        // DERBY-2584: If the first attempt to compile the query fails,
        // we need to reset initiallyCompilable to make sure the
        // prepared plan is fully stored to disk. Save the initial
        // value here.
        final boolean compilable = initiallyCompilable;

        try
        {
          prepareAndRelease(lcc, null, nestedTC);
          updateSYSSTATEMENTS(lcc, RECOMPILE, nestedTC);
        }
        catch (StandardException se)
        {
          if (se.getMessageId().equals(SQLState.LOCK_TIMEOUT))
          {
            if (nestedTC != null)
            {
            nestedTC.commit();
            nestedTC.destroy();
            nestedTC = null;
            }
            // if we couldn't do this with a nested xaction, retry with
            // parent-- we need to wait this time!
            initiallyCompilable = compilable;
            prepareAndRelease(lcc, null, null);
            updateSYSSTATEMENTS(lcc, RECOMPILE, null);
          }
          else throw se;
        }
        finally
        {
          // no matter what, commit the nested transaction; if something
          // bad happened in the child xaction lets not abort the parent
          // here.
          if (nestedTC != null)
          {
            nestedTC.commit();
            nestedTC.destroy();
          }
        }
      }
    }
View Full Code Here

   
    public void drop(LanguageConnectionContext   lcc) throws StandardException
    {
        DataDictionary dd = getDataDictionary();
        DependencyManager dm = getDataDictionary().getDependencyManager();
        TransactionController tc = lcc.getTransactionExecute();

        dm.invalidateFor(this, DependencyManager.DROP_TRIGGER, lcc);

        // Drop the trigger
        dd.dropTriggerDescriptor(this, tc);
View Full Code Here

     */
  public void drop(LanguageConnectionContext lcc) throws StandardException
  {
        DataDictionary dd = getDataDictionary();
        DependencyManager dm = dd.getDependencyManager();
        TransactionController tc = lcc.getTransactionExecute();
      
      //If user is attempting to drop SESSION schema and there is no physical SESSION schema, then throw an exception
      //Need to handle it this special way is because SESSION schema is also used for temporary tables. If there is no
      //physical SESSION schema, we internally generate an in-memory SESSION schema in order to support temporary tables
      //But there is no way for the user to access that in-memory SESSION schema. Following if will be true if there is
View Full Code Here

            boolean clearDependencies)
        throws StandardException
    {      
        DataDictionary dd = getDataDictionary();
        DependencyManager dm = dd.getDependencyManager();
        TransactionController tc = lcc.getTransactionExecute();

        if (clearDependencies)
        {
            dm.clearDependencies(lcc, this);
        }
View Full Code Here

          TableDescriptor td)
  throws StandardException
  {    
        DataDictionary dd = getDataDictionary();
        DependencyManager dm = dd.getDependencyManager();
        TransactionController tc = lcc.getTransactionExecute();
       
        // invalidate any prepared statements that
        // depended on the index (including this one)
        dm.invalidateFor(this, DependencyManager.DROP_INDEX, lcc);
     
        // only drop the conglomerate if no similar index but with different
      // name. Get from dd in case we drop other dup indexes with a cascade operation     
      if (dd.getConglomerateDescriptors(getConglomerateNumber()).length == 1)
      {
          /* Drop statistics */
          dd.dropStatisticsDescriptors(td.getUUID(), getUUID(), tc);
         
          /* Drop the conglomerate */
          tc.dropConglomerate(getConglomerateNumber());
        }     
     
      /* Drop the conglomerate descriptor */
      dd.dropConglomerateDescriptor(this, tc);
     
View Full Code Here

                SchemaDescriptor sd, TableDescriptor td)
    throws StandardException
  {
        DataDictionary dd = getDataDictionary();
        DependencyManager dm = dd.getDependencyManager();
        TransactionController tc = lcc.getTransactionExecute();
       
    /* Drop the columns */
    dd.dropAllColumnDescriptors(td.getUUID(), tc);

    /* Prepare all dependents to invalidate.  (This is there chance
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.store.access.TransactionController

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.