Package org.apache.derby.iapi.sql.dictionary

Examples of org.apache.derby.iapi.sql.dictionary.DataDictionary


        {
          /*
          ** Get the DataDictionary, so we can get the descriptor for
          ** the SPP to invalidate it.
          */
          DataDictionary dd = lcc.getDataDictionary();
           
          SchemaDescriptor sd = dd.getSchemaDescriptor(execSchemaName, lcc.getTransactionCompile(), true);
          SPSDescriptor spsd = dd.getSPSDescriptor(execStmtName, sd);
          spsd.makeInvalid(action, lcc);
          break;
        }
        }
      }
View Full Code Here


    try {
      tr.startTransaction();
            LanguageConnectionContext lcc = tr.getLcc();
            String username = lcc.getSessionUserId();

      DataDictionary dd = lcc.getDataDictionary();

      // Check is only performed if we have
      // derby.database.sqlAuthorization == true and we have
      // upgraded dictionary to at least level 10.4 (roles
      // introduced in 10.4):
      if (lcc.usesSqlAuthorization() &&
        dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_4, null)) {

        TransactionController tc = lcc.getTransactionExecute();

        String failedString =
          MessageService.getTextMessage(MessageId.AUTH_INVALID);

        if (dd.getRoleDefinitionDescriptor(username) != null) {
          throw newSQLException(SQLState.NET_CONNECT_AUTH_FAILED,
                      failedString);
        }
      }
View Full Code Here

        ** Tell the data dictionary that we are about to do
        ** a bunch of "get" operations that must be consistent with
        ** each other.
        */
       
        DataDictionary dataDictionary = lcc.getDataDictionary();

        int ddMode = dataDictionary == null ? 0 : dataDictionary.startReading(lcc);

        try
        {
          // start a nested transaction -- all locks acquired by bind
          // and optimize will be released when we end the nested
          // transaction.
          lcc.beginNestedTransaction(true);

          qt.bindStatement();
          bindTime = getCurrentTimeMillis(lcc);

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("DumpBindTree"))
            {
              qt.treePrint();
            }

            if (SanityManager.DEBUG_ON("StopAfterBinding")) {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_BINDING);
            }
          }

          //Derby424 - In order to avoid caching select statements referencing
          // any SESSION schema objects (including statements referencing views
          // in SESSION schema), we need to do the SESSION schema object check
          // here. 
          //a specific eg for statement referencing a view in SESSION schema
          //CREATE TABLE t28A (c28 int)
          //INSERT INTO t28A VALUES (280),(281)
          //CREATE VIEW SESSION.t28v1 as select * from t28A
          //SELECT * from SESSION.t28v1 should show contents of view and we
          // should not cache this statement because a user can later define
          // a global temporary table with the same name as the view name.
          //Following demonstrates that
          //DECLARE GLOBAL TEMPORARY TABLE SESSION.t28v1(c21 int, c22 int) not
          //     logged
          //INSERT INTO SESSION.t28v1 VALUES (280,1),(281,2)
          //SELECT * from SESSION.t28v1 should show contents of global temporary
          //table and not the view.  Since this select statement was not cached
          // earlier, it will be compiled again and will go to global temporary
          // table to fetch data. This plan will not be cached either because
          // select statement is using SESSION schema object.
          //
          //Following if statement makes sure that if the statement is
          // referencing SESSION schema objects, then we do not want to cache it.
          // We will remove the entry that was made into the cache for
          //this statement at the beginning of the compile phase.
          //The reason we do this check here rather than later in the compile
          // phase is because for a view, later on, we loose the information that
          // it was referencing SESSION schema because the reference
          //view gets replaced with the actual view definition. Right after
          // binding, we still have the information on the view and that is why
          // we do the check here.
          if (preparedStmt.referencesSessionSchema(qt)) {
            if (foundInCache)
              ((GenericLanguageConnectionContext)lcc).removeStatement(this);
          }
         
          qt.optimizeStatement();

          optimizeTime = getCurrentTimeMillis(lcc);

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), End compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
        }

        catch (StandardException se)
        {
          lcc.commitNestedTransaction();

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), Error compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
          throw se;
        }

        finally
        {
          /* Tell the data dictionary that we are done reading */
          if (dataDictionary != null)
          dataDictionary.doneReading(ddMode, lcc);
        }

        /* we need to move the commit of nested sub-transaction
         * after we mark PS valid, during compilation, we might need
         * to get some lock to synchronize with another thread's DDL
View Full Code Here

         */
        private void pushIndexName(ConglomerateDescriptor cd, MethodBuilder mb)
          throws StandardException
        {
            if (cd.isConstraint()) {
                DataDictionary dd = getDataDictionary();
                ConstraintDescriptor constraintDesc =
                    dd.getConstraintDescriptor(tableDescriptor, cd.getUUID());
                mb.push(constraintDesc.getConstraintName());
            } else if (cd.isIndex())  {
                mb.push(cd.getConglomerateName());
            } else {
             // If the conglomerate is the base table itself, make sure we push null.
View Full Code Here

      return false;
    }

    int[] baseColumnPositions = irg.baseColumnPositions();

    DataDictionary dd = getDataDictionary();

    // Do we have an exact match on the full key
    for (int index = 0; index < baseColumnPositions.length; index++)
    {
      // get the column number at this position
View Full Code Here

  {
    try
    {
      LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();

      DataDictionary dd = lcc.getDataDictionary();

      TransactionController tc = lcc.getTransactionExecute();

      /*
      ** Inform the data dictionary we are going
      ** to perform some DDL
      */
      dd.startWriting(lcc);

      for (java.util.ListIterator li = dd.getAllSPSDescriptors().listIterator(); li.hasNext(); )
      {
        SPSDescriptor spsd = (SPSDescriptor) li.next();

        /*
        ** Is it in SYS? if so, zap it. Can't drop metadata SPS in SYSIBM, JCC depends on it.
        */
        if (spsd.getSchemaDescriptor().isSystemSchema() && !spsd.getSchemaDescriptor().isSYSIBM())
        {
          dd.dropSPSDescriptor(spsd, tc);
          dd.dropDependentsStoredDependencies(spsd.getUUID(), tc);
        }
      }
    } catch (StandardException se)
    {
      throw PublicAPI.wrapStandardException(se);
View Full Code Here

   */
  public void  executeConstantAction( Activation activation )
            throws StandardException
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();

    /*
    ** Inform the data dictionary that we are about to write to it.
    ** There are several calls to data dictionary "get" methods here
    ** that might be done in "read" mode in the data dictionary, but
    ** it seemed safer to do this whole operation in "write" mode.
    **
    ** We tell the data dictionary we're done writing at the end of
    ** the transaction.
    */
    dd.startWriting(lcc);

        SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);

        sd.drop(lcc);

  }
View Full Code Here

                    String colName,
                    boolean nullability)
    throws StandardException               
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    TransactionController tc = lcc.getTransactionExecute();

    ColumnDescriptor columnDescriptor =
      td.getColumnDescriptor(colName),
      newColumnDescriptor = null;
       
        // Get the type and change the nullability
    DataTypeDescriptor dataType =
            columnDescriptor.getType().getNullabilityType(nullability);


    newColumnDescriptor =
       new ColumnDescriptor(colName,
                  columnDescriptor.getPosition(),
                  dataType,
                  columnDescriptor.getDefaultValue(),
                  columnDescriptor.getDefaultInfo(),
                  td,
                  columnDescriptor.getDefaultUUID(),
                  columnDescriptor.getAutoincStart(),
                  columnDescriptor.getAutoincInc());
   


    // Update the ColumnDescriptor with new default info
    dd.dropColumnDescriptor(td.getUUID(), colName, tc);
    dd.addDescriptor(newColumnDescriptor, td,
             DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);
   
  }
View Full Code Here

  private void modifyColumnDefault(Activation activation,
                   int ix)
      throws StandardException            
  {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();

    ColumnDescriptor columnDescriptor =
      td.getColumnDescriptor(columnInfo[ix].name);
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    int columnPosition = columnDescriptor.getPosition();

    // Clean up after the old default, if non-null
    if (columnDescriptor.hasNonNullDefault())
    {
      // Invalidate off of the old default
      DefaultDescriptor defaultDescriptor = new DefaultDescriptor(dd, columnInfo[ix].oldDefaultUUID,
                     td.getUUID(), columnPosition);

   
      dm.invalidateFor(defaultDescriptor, DependencyManager.MODIFY_COLUMN_DEFAULT, lcc);
   
      // Drop any dependencies
      dm.clearDependencies(lcc, defaultDescriptor);
    }

    UUID defaultUUID = columnInfo[ix].newDefaultUUID;

    /* Generate a UUID for the default, if one exists
     * and there is no default id yet.
     */
    if (columnInfo[ix].defaultInfo != null &&
      defaultUUID == null)
    { 
      defaultUUID = dd.getUUIDFactory().createUUID();
    }

    /* Get a ColumnDescriptor reflecting the new default */
    columnDescriptor = new ColumnDescriptor(
                           columnInfo[ix].name,
                           columnPosition,
                           columnInfo[ix].dataType,
                           columnInfo[ix].defaultValue,
                           columnInfo[ix].defaultInfo,
                           td,
                           defaultUUID,
                           columnInfo[ix].autoincStart,
                           columnInfo[ix].autoincInc,
                           columnInfo[ix].autoinc_create_or_modify_Start_Increment
                           );

    // Update the ColumnDescriptor with new default info
    dd.dropColumnDescriptor(td.getUUID(), columnInfo[ix].name, tc);
    dd.addDescriptor(columnDescriptor, td,
             DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);
 
    if (columnInfo[ix].action == ColumnInfo.MODIFY_COLUMN_DEFAULT_INCREMENT)
    {
      // adding an autoincrement default-- calculate the maximum value
      // of the autoincrement column.
      long maxValue = getColumnMax(activation, td, columnInfo[ix].name,
                     columnInfo[ix].autoincInc,
                     columnInfo[ix].autoincStart);
      dd.setAutoincrementValue(tc, td.getUUID(), columnInfo[ix].name,
                   maxValue, true);
    } else if (columnInfo[ix].action == ColumnInfo.MODIFY_COLUMN_DEFAULT_RESTART)
    {
      dd.setAutoincrementValue(tc, td.getUUID(), columnInfo[ix].name,
           columnInfo[ix].autoincStart, false);
    }
    // else we are simply changing the default value
  }
View Full Code Here

   */
  public void  executeConstantAction( Activation activation )
            throws StandardException
  {
    LanguageConnectionContext   lcc;
    DataDictionary         dd;

    // find the language context.
    lcc = activation.getLanguageConnectionContext();

    dd = lcc.getDataDictionary();
    String thisSchemaName = schemaName;
    if (type == StatementType.SET_SCHEMA_DYNAMIC)
    {
      ParameterValueSet pvs = activation.getParameterValueSet();
      DataValueDescriptor dvs = pvs.getParameter(0);
      thisSchemaName = dvs.getString();
      //null parameter is not allowed
      if (thisSchemaName == null || thisSchemaName.length() > Limits.MAX_IDENTIFIER_LENGTH)
        throw StandardException.newException(SQLState.LANG_DB2_REPLACEMENT_ERROR, "CURRENT SCHEMA");
    }
    else if (type == StatementType.SET_SCHEMA_USER)
    {
      thisSchemaName = lcc.getAuthorizationId();
    }
    // if schemaName is null, sd will be null and default schema will be used
    SchemaDescriptor sd = dd.getSchemaDescriptor(thisSchemaName, null, true);
    lcc.setDefaultSchema(sd);
  }
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.dictionary.DataDictionary

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.