Class DeferredConstraintsMemory
java.lang.Object
org.apache.derby.impl.sql.execute.DeferredConstraintsMemory
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Info needed for check constraintsprivate static class
private static class
Info needed for unique and primary key constraintsstatic class
Class hierarchy carrying the information we need to validate some deferred constraint. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
compressOrTruncate
(LanguageConnectionContext lcc, UUID tableId, String tableName) static Enumeration
<Object> getDeferredCheckConstraintLocations
(Activation activation, UUID validatingBaseTableUUID) private static BackingStoreHashtable
makeDeferredHashTable
(TransactionController tc, int cols) static BackingStoreHashtable
rememberCheckViolations
(LanguageConnectionContext lcc, UUID basetableId, String schemaName, String tableName, BackingStoreHashtable deferredCheckViolations, List<UUID> violatingCheckConstraints, RowLocation offendingRow, DeferredConstraintsMemory.CheckInfo[] result) 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.static BackingStoreHashtable
rememberDuplicate
(LanguageConnectionContext lcc, BackingStoreHashtable deferredRowsHashTable, UUID constraintId, DataValueDescriptor[] insertRow) 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.static BackingStoreHashtable
rememberFKViolation
(LanguageConnectionContext lcc, BackingStoreHashtable deferredRowsHashTable, UUID fkId, DataValueDescriptor[] indexRow, String schemaName, String tableName) Make note of a violated foreign key constraint, i.e. the referenced key is not present
-
Constructor Details
-
DeferredConstraintsMemory
public DeferredConstraintsMemory()
-
-
Method Details
-
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 contextdeferredRowsHashTable
- client cached valueconstraintId
- the id of the unique or primary key constraintinsertRow
- 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, String schemaName, String tableName, BackingStoreHashtable deferredCheckViolations, 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:
lcc
- the language connection contextbasetableId
- the id of the target tableschemaName
- the schema of the target tabletableName
- the target table namedeferredCheckViolations
- client cached valueviolatingCheckConstraints
- offending constraint(s)offendingRow
- the duplicate row to be saved in the hash table for later checkingresult
- OUT parameter: the allocated CheckInfo- Returns:
- the hash table (for caching by client to minimize lookups)
- Throws:
StandardException
- standard error policy
-
getDeferredCheckConstraintLocations
public static Enumeration<Object> getDeferredCheckConstraintLocations(Activation activation, UUID validatingBaseTableUUID) throws StandardException - Throws:
StandardException
-
rememberFKViolation
public static BackingStoreHashtable rememberFKViolation(LanguageConnectionContext lcc, BackingStoreHashtable deferredRowsHashTable, UUID fkId, DataValueDescriptor[] indexRow, String schemaName, 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 contextdeferredRowsHashTable
- cached client copyfkId
- the UUID of the foreign key constraintindexRow
- the row in the supporting index which contains the key which is not present in the referenced index.schemaName
- the schema of the tabletableName
- the table being modified that has a FK.- Returns:
- value to cache
- Throws:
StandardException
-
makeDeferredHashTable
private static BackingStoreHashtable makeDeferredHashTable(TransactionController tc, int cols) throws StandardException - Throws:
StandardException
-
compressOrTruncate
public static void compressOrTruncate(LanguageConnectionContext lcc, UUID tableId, String tableName) throws StandardException - Throws:
StandardException
-