Class ReferencedKeyRIChecker

java.lang.Object
org.apache.derby.impl.sql.execute.GenericRIChecker
org.apache.derby.impl.sql.execute.ReferencedKeyRIChecker

public class ReferencedKeyRIChecker extends GenericRIChecker
A Referential Integrity checker for a change to a referenced key (primary or unique). Makes sure that all the referenced key row is not referenced by any of its foreign keys. see ForeignKeyRIChecker for the code that validates changes to foreign keys.
  • Field Details

    • refKeyIndexScan

      private ScanController refKeyIndexScan
    • refKey

      private final DataValueDescriptor[] refKey
      Key mapping used when storing referenced (PK, unique) keys under deferred row processing and deferred key constraint (PK, unique).
    • deletedKeys

      private BackingStoreHashtable deletedKeys
      We save away keys with a counter in this hash table, so we know how many instances of a key (duplicates) have been deleted/modified, cf usage in postCheck(). Initialized on demand.
  • Constructor Details

  • Method Details

    • doCheck

      void doCheck(Activation a, ExecRow row, boolean restrictCheckOnly, int deferredRowReq) throws StandardException
      Check that the row either has a null column(s), or has no corresponding foreign keys.

      If a foreign key is found, an exception is thrown. If not, the scan is closed.

      Specified by:
      doCheck in class GenericRIChecker
      Parameters:
      a - the activation
      row - the row to check
      restrictCheckOnly - true if the check is relevant only for RESTRICTED referential action.
      deferredRowReq - For referenced keys: The required number of duplicates that need to be present. Only used if postCheck==false.
      Throws:
      StandardException - on unexpected error, or on a primary/unique key violation
    • rememberKey

      private void rememberKey(ExecRow rememberRow) throws StandardException
      Remember the deletion of this key, it may cause a RESTRICT foreign key violation, cf. logic in @{link #postCheck}.
      Parameters:
      rememberRow -
      Throws:
      StandardException
    • postCheck

      public void postCheck() throws StandardException
      Check that we have at least one more row in the referenced table table containing a key than the number of projected deletes of that key. Only used when the referenced constraint id deferred and with RESTRICT mode
      Throws:
      StandardException - Standard error policy
    • isDuplicated

      private boolean isDuplicated(ExecRow row, int deferredRowReq) throws StandardException
      Throws:
      StandardException
    • isDuplicated

      private boolean isDuplicated(DataValueDescriptor[] key, long deferredRowReq) throws StandardException
      Throws:
      StandardException
    • close

      void close() throws StandardException
      Clean up all scan controllers and other resources
      Overrides:
      close in class GenericRIChecker
      Throws:
      StandardException - on error