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

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


    }


    //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


  private ConstraintDescriptorList getAllConstraintDescriptors()
    throws StandardException
  {
    TabInfoImpl          ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);

    ConstraintDescriptorList list = new ConstraintDescriptorList();

    getConstraintDescriptorViaHeap(
            (ScanQualifier[][]) null,
            ti,
            (TupleDescriptor) null,
View Full Code Here

   * @exception StandardException    Thrown on failure
   */
  public ConstraintDescriptorList getConstraintDescriptors(TableDescriptor td)
    throws StandardException
  {
    ConstraintDescriptorList  cdl;

    if (td == null)
    {
      return getAllConstraintDescriptors();
    }

    /* RESOLVE - need to look at multi-user aspects of hanging constraint
     * descriptor list off of table descriptor when we restore the cache.
     */

    /* Build the TableDescriptor's CDL if it is currently empty */
    cdl = td.getConstraintDescriptorList();

    /*
    ** Synchronize the building of the CDL.  The CDL itself is created
    ** empty when the TD is created, so there is no need to synchronize
    ** the getting of the CDL.
    */
    synchronized(cdl)
    {
      if (! cdl.getScanned())
      {
        getConstraintDescriptorsScan(td, false);
      }
    }

View Full Code Here

   * @exception StandardException    Thrown on failure
   */
   private void getConstraintDescriptorsScan(TableDescriptor td, boolean forUpdate)
      throws StandardException
  {
    ConstraintDescriptorList  cdl = td.getConstraintDescriptorList();
    DataValueDescriptor      tableIDOrderable = null;
    TabInfoImpl            ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);

    /* Use tableIDOrderable in both start and stop positions for scan */
    tableIDOrderable = getIDValueAsCHAR(td.getUUID());

    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);

    keyRow.setColumn(1, tableIDOrderable);

    getConstraintDescriptorViaIndex(
          SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX3_ID,
          keyRow,
          ti,
          td,
          cdl,
          forUpdate);
    cdl.setScanned(true);
  }
View Full Code Here

            fkList,
            false);

    SubKeyConstraintDescriptor cd;
    TableDescriptor td;
    ConstraintDescriptorList cdl = new ConstraintDescriptorList();
    ConstraintDescriptorList tmpCdl;

    for (Iterator iterator = fkList.iterator(); iterator.hasNext(); )
    {
      cd = (SubKeyConstraintDescriptor) iterator.next();
      td = getConstraintTableDescriptor(cd.getUUID());
View Full Code Here

   */
  public void  dropAllConstraintDescriptors(TableDescriptor table,
                       TransactionController tc)
    throws StandardException
  {
    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);
    }

View Full Code Here

          {
            case DataDictionary.PRIMARYKEY_CONSTRAINT:

              // Check to see if a constraint of the same type
                            // already exists
              ConstraintDescriptorList cdl =
                                dd.getConstraintDescriptors(td);

              if (cdl.getPrimaryKey() != null)
              {
                throw StandardException.newException(
                                    SQLState.LANG_ADD_PRIMARY_KEY_FAILED1,
                                    td.getQualifiedName());
              }
View Full Code Here

                 DataDictionary.SYSTRIGGERS_CATALOG_NUM,
                 false, tc);
      }
    }

    ConstraintDescriptorList csdl = dd.getConstraintDescriptors(td);
    int csdl_size = csdl.size();

    // we want to remove referenced primary/unique keys in the second
    // round.  This will ensure that self-referential constraints will
    // work OK.
    int tbr_size = 0;
    ConstraintDescriptor[] toBeRemoved =
            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);
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

          {
            case DataDictionary.PRIMARYKEY_CONSTRAINT:

              // Check to see if a constraint of the same type
                            // already exists
              ConstraintDescriptorList cdl =
                                dd.getConstraintDescriptors(td);

              if (cdl.getPrimaryKey() != null)
              {
                throw StandardException.newException(
                                    SQLState.LANG_ADD_PRIMARY_KEY_FAILED1,
                                    td.getQualifiedName());
              }
View Full Code Here

TOP

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

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.