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

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


   * @exception StandardException    Thrown on failure
   */
  public void  executeConstantAction( Activation activation )
            throws StandardException
  {
    ConstraintDescriptor    conDesc = null;
    TableDescriptor        td;
    UUID              indexId = null;
    String            indexUUIDString;

    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();


    /*
    ** 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);

    td = dd.getTableDescriptor(tableId);

    if (td == null)
    {
      throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
    }

    /* Table gets locked in AlterTableConstantAction */

    /*
    ** If the schema descriptor is null, then
    ** we must have just read ourselves in. 
    ** So we will get the corresponding schema
    ** descriptor from the data dictionary.
    */

    SchemaDescriptor tdSd = td.getSchemaDescriptor();
    SchemaDescriptor constraintSd =
      constraintSchemaName == null ? tdSd : dd.getSchemaDescriptor(constraintSchemaName, tc, true);


    /* Get the constraint descriptor for the index, along
     * with an exclusive row lock on the row in sys.sysconstraints
     * in order to ensure that no one else compiles against the
     * index.
     */
    if (constraintName == null// this means "alter table drop primary key"
      conDesc = dd.getConstraintDescriptors(td).getPrimaryKey();
    else
      conDesc = dd.getConstraintDescriptorByName(td, constraintSd, constraintName, true);

    // Error if constraint doesn't exist
    if (conDesc == null)
    {
      String errorName = constraintName == null ? "PRIMARY KEY" :
                (constraintSd.getSchemaName() + "."+ constraintName);

      throw StandardException.newException(SQLState.LANG_DROP_NON_EXISTENT_CONSTRAINT,
            errorName,
            td.getQualifiedName());
    }
        switch( verifyType)
        {
        case DataDictionary.UNIQUE_CONSTRAINT:
            if( conDesc.getConstraintType() != verifyType)
                throw StandardException.newException(SQLState.LANG_DROP_CONSTRAINT_TYPE,
                                                     constraintName, "UNIQUE");
            break;

        case DataDictionary.CHECK_CONSTRAINT:
            if( conDesc.getConstraintType() != verifyType)
                throw StandardException.newException(SQLState.LANG_DROP_CONSTRAINT_TYPE,
                                                     constraintName, "CHECK");
            break;

        case DataDictionary.FOREIGNKEY_CONSTRAINT:
            if( conDesc.getConstraintType() != verifyType)
                throw StandardException.newException(SQLState.LANG_DROP_CONSTRAINT_TYPE,
                                                     constraintName, "FOREIGN KEY");
            break;
        }

View Full Code Here


     * so it's okay to drop a backing index if we can't find its
     * ConstraintDescriptor.
     */
    if (cd.isConstraint())
    {
      ConstraintDescriptor conDesc;
      String constraintName;

      conDesc = dd.getConstraintDescriptor(td, cd.getUUID());
      if (conDesc != null)
      {
        constraintName = conDesc.getConstraintName();
        throw StandardException.newException(SQLState.LANG_CANT_DROP_BACKING_INDEX,
                    getFullName(), constraintName);
      }
    }

View Full Code Here

      ( StatementType.UPDATE, false, changedColumnIds, needsDeferredProcessing, relevantConstraints );

    int rclSize = relevantConstraints.size();
    for (int index = 0; index < rclSize; index++)
    {
      ConstraintDescriptor cd = relevantConstraints.elementAt(index);
      if (cd.getConstraintType() != DataDictionary.CHECK_CONSTRAINT)
      {
        continue;
      }

      int[] refColumns = ((CheckConstraintDescriptor)cd).getReferencedColumns();
View Full Code Here

            boolean forUpdate)
      throws StandardException
  {
    SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
    ConglomerateController  heapCC;
    ConstraintDescriptor  cd = null;
    ExecIndexRow        indexRow1;
    ExecIndexRow      indexTemplateRow;
    ExecRow         outRow;
    RowLocation        baseRowLocation;
    ScanController      scanController;
View Full Code Here

    ConglomerateController  heapCC;
    ExecRow         outRow;
    ExecRow         templateRow;
    ScanController      scanController;
    TransactionController  tc;
    ConstraintDescriptor  cd = null;

    // Get the current transaction controller
    tc = getTransactionCompile();

    outRow = rf.makeEmptyRow();
View Full Code Here

    ConstraintDescriptorList cdl = getConstraintDescriptors(table);

    // Walk the table's CDL and drop each ConstraintDescriptor.
    for (Iterator iterator = cdl.iterator(); iterator.hasNext(); )
    {
      ConstraintDescriptor cd = (ConstraintDescriptor) iterator.next();
      dropConstraintDescriptor(cd, tc);
    }

    /*
    ** Null out the table's constraint descriptor list.  NOTE: This is
View Full Code Here

     *    invalid value for hashLoadFactor
     *    invalid value for hashMaxCapacity
     */
    boolean indexSpecified = false;
    boolean constraintSpecified = false;
    ConstraintDescriptor consDesc = null;
    Enumeration e = tableProperties.keys();

      StringUtil.SQLEqualsIgnoreCase(tableDescriptor.getSchemaName(),
                       "SYS");
    while (e.hasMoreElements())
    {
      String key = (String) e.nextElement();
      String value = (String) tableProperties.get(key);

      if (key.equals("index"))
      {
        // User only allowed to specify 1 of index and constraint, not both
        if (constraintSpecified)
        {
          throw StandardException.newException(SQLState.LANG_BOTH_FORCE_INDEX_AND_CONSTRAINT_SPECIFIED,
                getBaseTableName());
        }
        indexSpecified = true;

        /* Validate index name - NULL means table scan */
        if (! StringUtil.SQLToUpperCase(value).equals("NULL"))
        {
          ConglomerateDescriptor cd = null;
          ConglomerateDescriptor[] cds = tableDescriptor.getConglomerateDescriptors();

          for (int index = 0; index < cds.length; index++)
          {
            cd = cds[index];
            String conglomerateName = cd.getConglomerateName();
            if (conglomerateName != null)
            {
              if (conglomerateName.equals(value))
              {
                break;
              }
            }
            // Not a match, clear cd
            cd = null;
          }

          // Throw exception if user specified index not found
          if (cd == null)
          {
            throw StandardException.newException(SQLState.LANG_INVALID_FORCED_INDEX1,
                    value, getBaseTableName());
          }
          /* Query is dependent on the ConglomerateDescriptor */
          getCompilerContext().createDependency(cd);
        }
      }
      else if (key.equals("constraint"))
      {
        // User only allowed to specify 1 of index and constraint, not both
        if (indexSpecified)
        {
          throw StandardException.newException(SQLState.LANG_BOTH_FORCE_INDEX_AND_CONSTRAINT_SPECIFIED,
                getBaseTableName());
        }
        constraintSpecified = true;

        if (! StringUtil.SQLToUpperCase(value).equals("NULL"))
        {
          consDesc =
            dDictionary.getConstraintDescriptorByName(
                  tableDescriptor, (SchemaDescriptor)null, value,
                  false);

          /* Throw exception if user specified constraint not found
           * or if it does not have a backing index.
           */
          if ((consDesc == null) || ! consDesc.hasBackingIndex())
          {
            throw StandardException.newException(SQLState.LANG_INVALID_FORCED_INDEX2,
                    value, getBaseTableName());
          }

          /* Query is dependent on the ConstraintDescriptor */
          getCompilerContext().createDependency(consDesc);
        }
      }
      else if (key.equals("joinStrategy"))
      {
        userSpecifiedJoinStrategy = StringUtil.SQLToUpperCase(value);
      }
      else if (key.equals("hashInitialCapacity"))
      {
        initialCapacity = getIntProperty(value, key);

        // verify that the specified value is valid
        if (initialCapacity <= 0)
        {
          throw StandardException.newException(SQLState.LANG_INVALID_HASH_INITIAL_CAPACITY,
              String.valueOf(initialCapacity));
        }
      }
      else if (key.equals("hashLoadFactor"))
      {
        try
        {
          loadFactor = Float.valueOf(value).floatValue();
        }
        catch (NumberFormatException nfe)
        {
          throw StandardException.newException(SQLState.LANG_INVALID_NUMBER_FORMAT_FOR_OVERRIDE,
              value, key);
        }

        // verify that the specified value is valid
        if (loadFactor <= 0.0 || loadFactor > 1.0)
        {
          throw StandardException.newException(SQLState.LANG_INVALID_HASH_LOAD_FACTOR,
              value);
        }
      }
      else if (key.equals("hashMaxCapacity"))
      {
        maxCapacity = getIntProperty(value, key);

        // verify that the specified value is valid
        if (maxCapacity <= 0)
        {
          throw StandardException.newException(SQLState.LANG_INVALID_HASH_MAX_CAPACITY,
              String.valueOf(maxCapacity));
        }
      }
      else if (key.equals("bulkFetch"))
      {
        bulkFetch = getIntProperty(value, key);

        // verify that the specified value is valid
        if (bulkFetch <= 0)
        {
          throw StandardException.newException(SQLState.LANG_INVALID_BULK_FETCH_VALUE,
              String.valueOf(bulkFetch));
        }
     
        // no bulk fetch on updatable scans
        if (forUpdate())
        {
          throw StandardException.newException(SQLState.LANG_INVALID_BULK_FETCH_UPDATEABLE);
        }
      }
      else
      {
        // No other "legal" values at this time
        throw StandardException.newException(SQLState.LANG_INVALID_FROM_TABLE_PROPERTY, key,
          "index, constraint, joinStrategy");
      }
    }

    /* If user specified a non-null constraint name(DERBY-1707), then 
     * replace it in the properties list with the underlying index name to
     * simplify the code in the optimizer.
     * NOTE: The code to get from the constraint name, for a constraint
     * with a backing index, to the index name is convoluted.  Given
     * the constraint name, we can get the conglomerate id from the
     * ConstraintDescriptor.  We then use the conglomerate id to get
     * the ConglomerateDescriptor from the DataDictionary and, finally,
     * we get the index name (conglomerate name) from the ConglomerateDescriptor.
     */
    if (constraintSpecified && consDesc != null)
    {
      ConglomerateDescriptor cd =
        dDictionary.getConglomerateDescriptor(
          consDesc.getConglomerateId());
      String indexName = cd.getConglomerateName();

      tableProperties.remove("constraint");
      tableProperties.put("index", indexName);
    }
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.
             //  Before the fix for DERBY-578, we would push the base table name
View Full Code Here

    ValueNode          checkTree = null;

    // Get the text of all the check constraints
    for (int index = 0; index < ccCDLSize; index++)
    {
      ConstraintDescriptor cd = ccCDL.elementAt(index);

      String constraintText = cd.getConstraintText();

      // Get the query tree for this constraint
      ValueNode oneConstraint =
        parseCheckConstraint(constraintText, td);

      // Put a TestConstraintNode above the constraint tree
      TestConstraintNode tcn =
        (TestConstraintNode) getNodeFactory().getNode(
          C_NodeTypes.TEST_CONSTRAINT_NODE,
          oneConstraint,
          SQLState.LANG_CHECK_CONSTRAINT_VIOLATED,
          td.getQualifiedName(),
          cd.getConstraintName(),
          getContextManager());
         
      // Link consecutive TestConstraintNodes with AND nodes
      if (checkTree == null)
      {
View Full Code Here

    Vector                              refColDescriptors = new Vector(1);
    Vector                              fkColMap = new Vector(1);
    int activeSize = activeList.size();
    for (int index = 0; index < activeSize; index++)
    {
      ConstraintDescriptor cd = activeList.elementAt(index);

      if (cd instanceof ForeignKeyConstraintDescriptor)
      {
        /*
        ** We are saving information for checking the
        ** primary/unique key that is referenced by this
        ** foreign key, so type is FOREIGN KEY.
        */ 
        type = FKInfo.FOREIGN_KEY;
        refcd = ((ForeignKeyConstraintDescriptor)cd).getReferencedConstraint();
        uuids = new UUID[1];
        conglomNumbers = new long[1];
        fkNames = new String[1];
        isSelfReferencingFK = new boolean[1];
        raRules = new int[1];
        fkSetupArrays(dd, (ForeignKeyConstraintDescriptor)cd,
            0, uuids, conglomNumbers,
            fkNames, isSelfReferencingFK, raRules);

        // oops, get the right constraint name -- for error
        // handling we want the FK name, not refcd name
        fkNames[0] = cd.getConstraintName();
      }
      else if (cd instanceof ReferencedKeyConstraintDescriptor)
      { 
        refcd = (ReferencedKeyConstraintDescriptor)cd;

        /*
        ** We are saving information for checking the
        ** foreign key(s) that is dependent on this referenced
        ** key, so type is REFERENCED KEY.
        */ 
        type = FKInfo.REFERENCED_KEY;
        fkcdl = dd.getActiveConstraintDescriptors
          ( ((ReferencedKeyConstraintDescriptor)cd).getForeignKeyConstraints(ConstraintDescriptor.ENABLED) );
 
        int size = fkcdl.size();
        if (size == 0)
        {
          continue;
        }

        uuids = new UUID[size];
        fkNames = new String[size];
        conglomNumbers = new long[size];
        isSelfReferencingFK = new boolean[size];
        raRules = new int[size];
        ForeignKeyConstraintDescriptor fkcd = null;
        TableDescriptor fktd;
        ColumnDescriptorList coldl;
        int[] refColumns;
        ColumnDescriptor cold;
        int[] colArray = remapReferencedColumns(cd, rowMap);
        for (int inner = 0; inner < size; inner++)
        {
          fkcd = (ForeignKeyConstraintDescriptor) fkcdl.elementAt(inner);
          fkSetupArrays(dd, fkcd,
                inner, uuids, conglomNumbers, fkNames,
                isSelfReferencingFK, raRules);
          if((raRules[inner] == StatementType.RA_CASCADE) ||
             (raRules[inner] ==StatementType.RA_SETNULL))
          {
            //find  the referencing  table Name
            fktd = fkcd.getTableDescriptor();
            refTableNames.addElement(fktd.getSchemaName() + "." + fktd.getName());
            refActions.addElement(new Integer(raRules[inner]));
            //find the referencing column name required for update null.
            refColumns = fkcd.getReferencedColumns();
            coldl = fktd.getColumnDescriptorList();
            ColumnDescriptorList releventColDes = new ColumnDescriptorList();
            for(int i = 0 ; i < refColumns.length; i++)
            {
              cold =(ColumnDescriptor)coldl.elementAt(refColumns[i]-1);
              releventColDes.add(cold);
            }
            refColDescriptors.addElement(releventColDes);
            refIndexConglomNum.addElement(new Long(conglomNumbers[inner]));
            fkColMap.addElement(colArray);
          }
        }
      }
      else
      {
        continue;
      }

      TableDescriptor  pktd = refcd.getTableDescriptor();
      UUID pkuuid = refcd.getIndexId();
      ConglomerateDescriptor pkIndexConglom = pktd.getConglomerateDescriptor(pkuuid);

      TableDescriptor refTd = cd.getTableDescriptor();
      fkVector.addElement(new FKInfo(
                  fkNames,              // foreign key names
                  refTd.getName(),        // table being modified
                  statementType,            // INSERT|UPDATE|DELETE
                  type,                // FOREIGN_KEY|REFERENCED_KEY
View Full Code Here

TOP

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

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.