Class DeferredConstraintsMemory


  • public final class DeferredConstraintsMemory
    extends java.lang.Object
    This class provides support for deferrable constraints. When the constraint mode is deferred, any violation of the constraint should not be flagged until the constraint mode is switched back to immediate, which may happen by explicitly setting the constraint mode to immediate, or implicitly at commit time. It may also happen implicitly when returning from a stored procedure if the constraint mode is immediate in the caller context.

    The approach taken in Derby to support deferred constraints is to make a note when the violation happens (at insert or update time), and then remember that violation until the mode switches back as described above. We note exactly which rows cause violations, so checking can happen as quickly as possible when we get there. The core mechanism used to remember the violations as well as the deferred checking is embodied in this class.

    • Constructor Detail

      • DeferredConstraintsMemory

        public DeferredConstraintsMemory()
    • Method Detail

      • rememberDuplicate

        public static BackingStoreHashtable rememberDuplicate​(LanguageConnectionContext lcc,
                                                              BackingStoreHashtable deferredRowsHashTable,
                                                              UUID constraintId,
                                                              DataValueDescriptor[] insertRow)
                                                       throws StandardException
        Save the contents of an constraint supporting index row in a hash table (which may spill to disk) for later checking, typically on transaction commit, or upon request.
        Parameters:
        lcc - the language connection context
        deferredRowsHashTable - client cached value
        constraintId - the id of the unique or primary key constraint
        insertRow - the duplicate row to be saved in the hash table for later checking
        Returns:
        the hash table (for caching by client to minimize lookups)
        Throws:
        StandardException - standard error policy
      • rememberCheckViolations

        public static BackingStoreHashtable rememberCheckViolations​(LanguageConnectionContext lcc,
                                                                    UUID basetableId,
                                                                    java.lang.String schemaName,
                                                                    java.lang.String tableName,
                                                                    BackingStoreHashtable deferredCheckViolations,
                                                                    java.util.List<UUID> violatingCheckConstraints,
                                                                    RowLocation offendingRow,
                                                                    DeferredConstraintsMemory.CheckInfo[] result)
                                                             throws StandardException
        Save the row location of an offending row (one or more check constraints were violated) in a hash table (which may spill to disk) for later checking, typically on transaction commit, or upon request. The row locations are subject to invalidation, cf. CheckInfo#setInvalidatedRowLocations.
        Parameters:
        basetableId - the id of the target table
        schemaName - the schema of the target table
        tableName - the target table name
        deferredCheckViolations - client cached value
        lcc - the language connection context
        violatingCheckConstraints - offending constraint(s)
        offendingRow - the duplicate row to be saved in the hash table for later checking
        result - OUT parameter: the allocated CheckInfo
        Returns:
        the hash table (for caching by client to minimize lookups)
        Throws:
        StandardException - standard error policy
      • rememberFKViolation

        public static BackingStoreHashtable rememberFKViolation​(LanguageConnectionContext lcc,
                                                                BackingStoreHashtable deferredRowsHashTable,
                                                                UUID fkId,
                                                                DataValueDescriptor[] indexRow,
                                                                java.lang.String schemaName,
                                                                java.lang.String tableName)
                                                         throws StandardException
        Make note of a violated foreign key constraint, i.e. the referenced key is not present
        Parameters:
        lcc - the language connection context
        deferredRowsHashTable - cached client copy
        fkId - the UUID of the foreign key constraint
        indexRow - the row in the supporting index which contains the key which is not present in the referenced index.
        schemaName - the schema of the table
        tableName - the table being modified that has a FK.
        Returns:
        value to cache
        Throws:
        StandardException