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

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


    int                 type;
    UUID[]                 uuids = null;
    long[]                 conglomNumbers = null;
    String[]              fkNames = null;
    ConstraintDescriptorList      fkcdl;
    ReferencedKeyConstraintDescriptor  refcd;
    boolean[]              isSelfReferencingFK;
    ConstraintDescriptorList      activeList = dd.getActiveConstraintDescriptors(cdl);
    int[]                rowMap = getRowMap(readColsBitSet, td);
    int[]                               raRules = null;
    ArrayList                           refTableNames = new ArrayList(1);
    ArrayList                           refIndexConglomNum = new ArrayList(1);
    ArrayList                           refActions = new ArrayList(1);
    ArrayList                           refColDescriptors = new ArrayList(1);
    ArrayList                           fkColMap = new ArrayList(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.add(fktd.getSchemaName() + "." + fktd.getName());
            refActions.add(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.add(releventColDes);
            refIndexConglomNum.add(new Long(conglomNumbers[inner]));
            fkColMap.add(colArray);
          }
        }
      }
      else
      {
        continue;
      }

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

      TableDescriptor refTd = cd.getTableDescriptor();
      fkVector.add(new FKInfo(
                  fkNames,              // foreign key names
View Full Code Here


    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))
        {
          throw StandardException.newException(SQLState.LANG_NO_TRUNCATE_ON_FK_REFERENCE_TABLE,td.getName());
        }
      }
    }
View Full Code Here

    int                 type;
    UUID[]                 uuids = null;
    long[]                 conglomNumbers = null;
    String[]              fkNames = null;
    ConstraintDescriptorList      fkcdl;
    ReferencedKeyConstraintDescriptor  refcd;
    boolean[]              isSelfReferencingFK;
    ConstraintDescriptorList      activeList = dd.getActiveConstraintDescriptors(cdl);
    int[]                rowMap = getRowMap(readColsBitSet, td);
    int[]                               raRules = null;
    Vector                              refTableNames = new Vector(1);
    Vector                              refIndexConglomNum = new Vector(1);
    Vector                              refActions = new Vector(1);
    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
View Full Code Here

    dropConstraint(conDesc, activation, lcc, !cascadeOnRefKey);

    if (cascadeOnRefKey)
    {
      ForeignKeyConstraintDescriptor fkcd;
      ReferencedKeyConstraintDescriptor cd;
      ConstraintDescriptorList cdl;

      cd = (ReferencedKeyConstraintDescriptor)conDesc;
      cdl = cd.getForeignKeyConstraints(ReferencedKeyConstraintDescriptor.ALL);
      int cdlSize = cdl.size();

      for(int index = 0; index < cdlSize; index++)
      {
        fkcd = (ForeignKeyConstraintDescriptor) cdl.elementAt(index);
View Full Code Here

      /*
      ** Now we need to bump the reference count of the
      ** constraint that this FK references
      */
      ReferencedKeyConstraintDescriptor refDescriptor =
              fkDescriptor.getReferencedConstraint();

      refDescriptor.incrementReferenceCount();

      int[] colsToSet = new int[1];
      colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT;

      updateConstraintDescriptor(refDescriptor,
                      refDescriptor.getUUID(),
                      colsToSet,
                      tc);
    }
    else
    {
View Full Code Here

      ** because of the way FK.getReferencedConstraint() works. 
      */
      if (constraint.getConstraintType()
          == DataDictionary.FOREIGNKEY_CONSTRAINT)
      {
        ReferencedKeyConstraintDescriptor refDescriptor =
            (ReferencedKeyConstraintDescriptor)
                getConstraintDescriptor(
                  ((ForeignKeyConstraintDescriptor)constraint).
                      getReferencedConstraintId());

        if (refDescriptor != null)
        {
          refDescriptor.decrementReferenceCount();
 
          int[] colsToSet = new int[1];
          colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT;
   
          updateConstraintDescriptor(refDescriptor,
                        refDescriptor.getUUID(),
                        colsToSet,
                        tc);
        }
      }
    }
View Full Code Here

            //
            if (cd == null) {
                return;
            }

            ReferencedKeyConstraintDescriptor rcd =
                    cd.getReferencedConstraint();

            long[] cids = {
                cd.getIndexConglomerateDescriptor(dd).getConglomerateNumber(),
                rcd.getIndexConglomerateDescriptor(dd).getConglomerateNumber()

            };

            final Enumeration<?> e = infoRows.elements();

            while (e.hasMoreElements()) {
                final DataValueDescriptor[] key =
                        (DataValueDescriptor[])e.nextElement();

                // FIXME: This is not very efficient: we could sort the rows in
                // the hash table, and then check all rows using a single scan.
                ScanController indexSC = null;
                boolean violation = false;

                for (int idx = 0; idx < 2; idx++) {
                    boolean sawException = false;

                    try {
                        indexSC = tc.openScan(
                                cids[idx],
                                false,
                                0, // read only
                                TransactionController.MODE_RECORD,
                                TransactionController.ISOLATION_READ_COMMITTED,
                                (FormatableBitSet)null, // retrieve all fields
                                key,
                                ScanController.GE, // startSearchOp
                                null,
                                key,
                                ScanController.GT);

                        if (idx == 0) {
                            if (indexSC.next()) {
                                // The row with the PK still exists, so we need
                                // to check the referenced table's index
                            } else {
                                // No rows contain key: OK, must have been
                                // deleted later in transaction, or we got here
                                // due to pessimistic assumption on a timeout
                                // while checking on the insert.  In any case,
                                // no need to check the referenced key, so
                                // leave.
                                break;
                            }
                        } else {
                            if (indexSC.next()) {
                                // We found the referenced key, all is good
                            } else {
                                // We didn't find it and we know it is present
                                // as a PK, so we have a violation.
                                violation = true;
                            }
                        }
                    } catch (StandardException se) {
                        sawException = true;
                        throw se;
                    } finally {
                        // Clean up resource usage
                        try {
                            if (indexSC != null) {
                                indexSC.close();
                            }
                        } catch (StandardException ie) {
                            if (!sawException) {
                                throw ie;
                            } // else: can't let it shadow preceding exception
                        }
                    }
                }

                if (violation) {
                    final SchemaDescriptor sd =
                            dd.getSchemaDescriptor(schemaName, tc, true);

                    final TableDescriptor td  =
                            dd.getTableDescriptor(tableName, sd, tc);

                    final TableDescriptor rtd = rcd.getTableDescriptor();

                    throw StandardException.newException(
                            rollbackOnError ?
                                    SQLState.LANG_DEFERRED_FK_CONSTRAINT_T :
                                    SQLState.LANG_DEFERRED_FK_CONSTRAINT_S,
                            cd.getConstraintName(),
                            td.getQualifiedName(),
                            rcd.getConstraintName(),
                            rtd.getQualifiedName(),
                            RowUtil.toString(key));
                }
            }
        }
View Full Code Here

    if (td != null)
    {
      ForeignKeyConstraintDescriptor cd = (ForeignKeyConstraintDescriptor)td;
      constraintId = cd.getUUID().toString();
     
      ReferencedKeyConstraintDescriptor refCd = cd.getReferencedConstraint();
      if (SanityManager.DEBUG)
      {
        SanityManager.ASSERT(refCd != null, "this fk returned a null referenced key");
      }
      keyConstraintId = refCd.getUUID().toString();
      conglomId = cd.getIndexUUIDString();

      raDeleteRule = getRefActionAsString(cd.getRaDeleteRule());
      raUpdateRule = getRefActionAsString(cd.getRaUpdateRule());
    }
View Full Code Here

        // except if it is self referencing, or if the constraint is deferred
        // and the ON DELETE action is NO ACTION.
        for(ConstraintDescriptor cd : dd.getConstraintDescriptors(td)) {
      if (cd instanceof ReferencedKeyConstraintDescriptor)
      {
                final ReferencedKeyConstraintDescriptor rfcd =
                    (ReferencedKeyConstraintDescriptor)cd;

                for (ConstraintDescriptor fkcd :
                     rfcd.getNonSelfReferencingFK(ConstraintDescriptor.ENABLED))
                {
                    final ForeignKeyConstraintDescriptor fk =
                            (ForeignKeyConstraintDescriptor)fkcd;

                    throw StandardException.newException
View Full Code Here

    int                 type;
        UUID[]                              uuids;
        long[]                              conglomNumbers;
        String[]                            fkNames;
    ConstraintDescriptorList      fkcdl;
    ReferencedKeyConstraintDescriptor  refcd;
    boolean[]              isSelfReferencingFK;
    ConstraintDescriptorList      activeList = dd.getActiveConstraintDescriptors(cdl);
    int[]                rowMap = getRowMap(readColsBitSet, td);
        int[]                               raRules;
        boolean[]                           deferrable;
        UUID[]                              fkIds;
    ArrayList<String>              refTableNames = new ArrayList<String>(1);
    ArrayList<Long>               refIndexConglomNum = new ArrayList<Long>(1);
    ArrayList<Integer>            refActions = new ArrayList<Integer>(1);
    ArrayList<ColumnDescriptorList> refColDescriptors = new ArrayList<ColumnDescriptorList>(1);
    ArrayList<int[]>                fkColMap = new ArrayList<int[]>(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];
                deferrable = new boolean[1];
                fkIds = 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, deferrable, fkIds);

        // 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];
                deferrable = new boolean[size];
                fkIds = new UUID[size];
        fkNames = new String[size];
        conglomNumbers = new long[size];
        isSelfReferencingFK = new boolean[size];
        raRules = new int[size];
        TableDescriptor fktd;
        ColumnDescriptorList coldl;
        int[] refColumns;
        ColumnDescriptor cold;
        int[] colArray = remapReferencedColumns(cd, rowMap);
        for (int inner = 0; inner < size; inner++)
        {
                    ForeignKeyConstraintDescriptor fkcd =
                        (ForeignKeyConstraintDescriptor) fkcdl.elementAt(inner);
                    fkSetupArrays(
                        dd, fkcd,
                        inner, uuids, conglomNumbers, fkNames,
                        isSelfReferencingFK, raRules, deferrable, fkIds);

          if((raRules[inner] == StatementType.RA_CASCADE) ||
             (raRules[inner] ==StatementType.RA_SETNULL))
          {
            //find  the referencing  table Name
            fktd = fkcd.getTableDescriptor();
            refTableNames.add(fktd.getSchemaName() + "." + fktd.getName());
                        refActions.add(Integer.valueOf(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 = coldl.elementAt(refColumns[i]-1);
              releventColDes.add(cold);
            }
            refColDescriptors.add(releventColDes);
                        refIndexConglomNum.add(
                            Long.valueOf(conglomNumbers[inner]));
            fkColMap.add(colArray);
          }
        }
      }
      else
      {
        continue;
      }

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

            final TableDescriptor refTd = cd.getTableDescriptor();

            fkList.add(
                new FKInfo(
                    fkNames,                // foreign key names
                    cd.getSchemaDescriptor().getSchemaName(),
                    refTd.getName(),        // table being modified
                    statementType,          // INSERT|UPDATE|DELETE
                    type,                   // FOREIGN_KEY|REFERENCED_KEY
                    pkIndexId,              // referenced backing index uuid
                    pkIndexConglom.getConglomerateNumber(),
                                            // referenced backing index conglom
                    refcd.getUUID(),
                    refcd.deferrable(),     // referenced constraint is
                                            // deferrable?
                    uuids,                  // fk backing index uuids
                    conglomNumbers,         // fk backing index congloms
                    isSelfReferencingFK,    // is self ref array of bool
                    remapReferencedColumns(cd, rowMap),
View Full Code Here

TOP

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

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.