Examples of ForeignKeyConstraintDescriptor


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

    ** all others get a row in SYSKEYS.
    */
    if (descriptor.getConstraintType()
        == DataDictionary.FOREIGNKEY_CONSTRAINT)
    {
      ForeignKeyConstraintDescriptor fkDescriptor =
          (ForeignKeyConstraintDescriptor)descriptor;

      if (SanityManager.DEBUG)
      {
        if (!(descriptor instanceof ForeignKeyConstraintDescriptor))
        {
          SanityManager.THROWASSERT("descriptor not an fk descriptor, is "+
            descriptor.getClass().getName());
        }
      }
     
      ti = getNonCoreTI(SYSFOREIGNKEYS_CATALOG_NUM);
      SYSFOREIGNKEYSRowFactory fkkeysRF = (SYSFOREIGNKEYSRowFactory)ti.getCatalogRowFactory();

      row = fkkeysRF.makeRow(fkDescriptor, null);

      /*
      ** 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;
View Full Code Here

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

            TransactionController tc = lcc.getTransactionExecute();

            DataDictionary dd = lcc.getDataDictionary();

            ForeignKeyConstraintDescriptor cd =
                (ForeignKeyConstraintDescriptor)
                    dd.getConstraintDescriptor(fkId);

            // If the foreign key has been dropped, there is nothing to do.
            // See DERBY-6670
            //
            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

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

    String                  raDeleteRule="N";
    String          raUpdateRule="N";

    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());
    }
     
     
    /* Build the row  */
    row = getExecutionFactory().getIndexableRow(SYSFOREIGNKEYS_COLUMN_COUNT);
View Full Code Here

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

                    (ReferencedKeyConstraintDescriptor)cd;

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

                    throw StandardException.newException
                        ( SQLState.LANG_NO_TRUNCATE_ON_FK_REFERENCE_TABLE, td.getName() );
        }
View Full Code Here

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

        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);
View Full Code Here

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

          }
        }
      }
      else if (cd instanceof ForeignKeyConstraintDescriptor)
      {
        ForeignKeyConstraintDescriptor fkcd = (ForeignKeyConstraintDescriptor) cd;
        if (dependent == null)
        {
          compilerContext.createDependency(fkcd.getReferencedConstraint().getTableDescriptor());
        }
        else
        {
          compilerContext.createDependency(dependent,
                  fkcd.getReferencedConstraint().getTableDescriptor());
        }
      }
    }
  }
View Full Code Here

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

    ** all others get a row in SYSKEYS.
    */
    if (descriptor.getConstraintType()
        == DataDictionary.FOREIGNKEY_CONSTRAINT)
    {
      ForeignKeyConstraintDescriptor fkDescriptor =
          (ForeignKeyConstraintDescriptor)descriptor;

      if (SanityManager.DEBUG)
      {
        if (!(descriptor instanceof ForeignKeyConstraintDescriptor))
        {
          SanityManager.THROWASSERT("descriptor not an fk descriptor, is "+
            descriptor.getClass().getName());
        }
      }
     
      ti = getNonCoreTI(SYSFOREIGNKEYS_CATALOG_NUM);
      SYSFOREIGNKEYSRowFactory fkkeysRF = (SYSFOREIGNKEYSRowFactory)ti.getCatalogRowFactory();

      row = fkkeysRF.makeRow(fkDescriptor, null);

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

      refDescriptor.incrementReferenceCount();

      int[] colsToSet = new int[1];
      colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT;
View Full Code Here

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

        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);
View Full Code Here

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

          }
        }
      }
      else if (cd instanceof ForeignKeyConstraintDescriptor)
      {
        ForeignKeyConstraintDescriptor fkcd = (ForeignKeyConstraintDescriptor) cd;
        if (dependent == null)
        {
          compilerContext.createDependency(fkcd.getReferencedConstraint().getTableDescriptor());
        }
        else
        {
          compilerContext.createDependency(dependent,
                  fkcd.getReferencedConstraint().getTableDescriptor());
        }
      }
    }
  }
View Full Code Here

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

    ** all others get a row in SYSKEYS.
    */
    if (descriptor.getConstraintType()
        == DataDictionary.FOREIGNKEY_CONSTRAINT)
    {
      ForeignKeyConstraintDescriptor fkDescriptor =
          (ForeignKeyConstraintDescriptor)descriptor;

      if (SanityManager.DEBUG)
      {
        if (!(descriptor instanceof ForeignKeyConstraintDescriptor))
        {
          SanityManager.THROWASSERT("descriptor not an fk descriptor, is "+
            descriptor.getClass().getName());
        }
      }
     
      ti = getNonCoreTI(SYSFOREIGNKEYS_CATALOG_NUM);
      SYSFOREIGNKEYSRowFactory fkkeysRF = (SYSFOREIGNKEYSRowFactory)ti.getCatalogRowFactory();

      row = fkkeysRF.makeRow(fkDescriptor, null);

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

      refDescriptor.incrementReferenceCount();

      int[] colsToSet = new int[1];
      colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_REFERENCECOUNT;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.