Class DeferredConstraintsMemory
- java.lang.Object
-
- org.apache.derby.impl.sql.execute.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DeferredConstraintsMemory.CheckInfo
Info needed for check constraintsprivate static class
DeferredConstraintsMemory.ForeignKeyInfo
private static class
DeferredConstraintsMemory.UniquePkInfo
Info needed for unique and primary key constraintsstatic class
DeferredConstraintsMemory.ValidationInfo
Class hierarchy carrying the information we need to validate some deferred constraint.
-
Constructor Summary
Constructors Constructor Description DeferredConstraintsMemory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
compressOrTruncate(LanguageConnectionContext lcc, UUID tableId, java.lang.String tableName)
static java.util.Enumeration<java.lang.Object>
getDeferredCheckConstraintLocations(Activation activation, UUID validatingBaseTableUUID)
private static BackingStoreHashtable
makeDeferredHashTable(TransactionController tc, int cols)
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)
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, java.lang.String schemaName, java.lang.String tableName)
Make note of a violated foreign key constraint, i.e. the referenced key is not present
-
-
-
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 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, 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 tableschemaName
- the schema of the target tabletableName
- the target table namedeferredCheckViolations
- client cached valuelcc
- the language connection contextviolatingCheckConstraints
- 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 java.util.Enumeration<java.lang.Object> getDeferredCheckConstraintLocations(Activation activation, UUID validatingBaseTableUUID) throws StandardException
- Throws:
StandardException
-
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 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, java.lang.String tableName) throws StandardException
- Throws:
StandardException
-
-