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

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


    ExecRow          row,
    TupleDescriptor      parentTupleDescriptor,
    DataDictionary       dd )
          throws StandardException
  {
    ConstraintDescriptor constraintDesc = null;

    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT(
        row.nColumns() == SYSCONSTRAINTS_COLUMN_COUNT,
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

            new ConstraintDescriptor[csdl_size];

    // let's go downwards, don't want to get messed up while removing
    for (int i = csdl_size - 1; i >= 0; i--)
    {
      ConstraintDescriptor cd = csdl.elementAt(i);
      int[] referencedColumns = cd.getReferencedColumns();
      int numRefCols = referencedColumns.length, j;
      boolean changed = false;
      for (j = 0; j < numRefCols; j++)
      {
        if (referencedColumns[j] > droppedColumnPosition)
          changed = true;
        if (referencedColumns[j] == droppedColumnPosition)
          break;
      }
      if (j == numRefCols)      // column not referenced
      {
        if ((cd instanceof CheckConstraintDescriptor) && changed)
        {
          dd.dropConstraintDescriptor(cd, tc);
          for (j = 0; j < numRefCols; j++)
          {
            if (referencedColumns[j] > droppedColumnPosition)
              referencedColumns[j]--;
          }
          ((CheckConstraintDescriptor) cd).setReferencedColumnsDescriptor(new ReferencedColumnsDescriptorImpl(referencedColumns));
          dd.addConstraintDescriptor(cd, tc);
        }
        continue;
      }

      if (! cascade)
      {
        // Reject the DROP COLUMN, because there exists a constraint
        // which references this column.
        //
        throw StandardException.newException(
                        SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
                        dm.getActionString(DependencyManager.DROP_COLUMN),
                        columnInfo[ix].name, "CONSTRAINT",
                        cd.getConstraintName() );
      }

      if (cd instanceof ReferencedKeyConstraintDescriptor)
      {
        // restrict will raise an error in invalidate if referenced
        toBeRemoved[tbr_size++] = cd;
        continue;
      }

      // drop now in all other cases
      dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT,
                  lcc);
            cd.drop(lcc, true);

      activation.addWarning(
                StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,
        cd.getConstraintName(), td.getName()));
    }

    for (int i = tbr_size - 1; i >= 0; i--)
    {
      ConstraintDescriptor cd = toBeRemoved[i];
      cd.drop(lcc, false);

      activation.addWarning(
                StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED,
                cd.getConstraintName(), td.getName()));

      if (cascade)
      {
        ConstraintDescriptorList fkcdl = dd.getForeignKeys(cd.getUUID());
        for (int j = 0; j < fkcdl.size(); j++)
        {
          ConstraintDescriptor fkcd =
                        (ConstraintDescriptor) fkcdl.elementAt(j);

          dm.invalidateFor(fkcd,
                  DependencyManager.DROP_CONSTRAINT,
                  lcc);

                    fkcd.drop(lcc, true);

          activation.addWarning(
                        StandardException.newWarning(
                            SQLState.LANG_CONSTRAINT_DROPPED,
                fkcd.getConstraintName(),
                            fkcd.getTableDescriptor().getName()));
        }
      }

      dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT, lcc);
      dm.clearDependencies(lcc, cd);
View Full Code Here

    //truncate table is not allowed if there are any tables referencing it.
    //except if it is self referencing.
    ConstraintDescriptorList cdl = dd.getConstraintDescriptors(td);
    for(int index = 0; index < cdl.size(); index++)
    {
      ConstraintDescriptor cd = cdl.elementAt(index);
      if (cd instanceof ReferencedKeyConstraintDescriptor)
      {
        ReferencedKeyConstraintDescriptor rfcd = (ReferencedKeyConstraintDescriptor) cd;
        if(rfcd.hasNonSelfReferencingFK(ConstraintDescriptor.ENABLED))
        {
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

    int intArray[] = new int[1];
    intArray[0] = columnPosition;

    for (int index = 0; index < cdl.size(); index++)
    {
      ConstraintDescriptor existingConstraint =
                                        cdl.elementAt(index);
      if (!(existingConstraint instanceof KeyConstraintDescriptor))
        continue;

      if (!existingConstraint.columnIntersects(intArray))
        continue;
                              
      int constraintType = existingConstraint.getConstraintType();

      // cannot change the length of a column that is part of a
      // foreign key constraint. Must be an exact match between pkey
      // and fkey columns.
      if ((constraintType == DataDictionary.FOREIGNKEY_CONSTRAINT)
        &&
        (getNodeType() == C_NodeTypes.MODIFY_COLUMN_TYPE_NODE))
      {
        throw StandardException.newException(
           SQLState.LANG_MODIFY_COLUMN_FKEY_CONSTRAINT, name, existingConstraint.getConstraintName());
     
     
      else
      {
        // a column that is part of a primary key or unique constraint
                // is being made nullable; can't be done.
        if ((getNodeType() ==
           C_NodeTypes.MODIFY_COLUMN_CONSTRAINT_NODE) &&
          ((existingConstraint.getConstraintType() ==
           DataDictionary.PRIMARYKEY_CONSTRAINT) ||
           (existingConstraint.getConstraintType() ==
           DataDictionary.UNIQUE_CONSTRAINT)))
        {
        throw StandardException.newException(
           SQLState.LANG_MODIFY_COLUMN_EXISTING_CONSTRAINT, name);
        }
        // unique key or primary key.
        ConstraintDescriptorList
          refcdl = dd.getForeignKeys(existingConstraint.getUUID());
        
        if (refcdl.size() > 0)
        {
          throw StandardException.newException(
             SQLState.LANG_MODIFY_COLUMN_REFERENCED, name, refcdl.elementAt(0).getConstraintName());
View Full Code Here

    /* Verify that there are no check constraints on the table */
    ConstraintDescriptorList constraintDescriptorList = dd.getConstraintDescriptors(td);
    int size =
      constraintDescriptorList == null ? 0 : constraintDescriptorList.size();

    ConstraintDescriptor constraintDescriptor;

    // go through all the constraints defined on the table
    for (int index = 0; index < size; index++)
    {
      constraintDescriptor = constraintDescriptorList.elementAt(index);
      // if it is a check constraint, error
      if (constraintDescriptor.getConstraintType() == DataDictionary.CHECK_CONSTRAINT)
      {
        throw StandardException.newException(
            SQLState.LANG_PROVIDER_HAS_DEPENDENT_OBJECT,
            "RENAME",
            td.getName(),
            "CONSTRAINT",
            constraintDescriptor.getConstraintName());
      }
    }
  }
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.