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.
| Modifier and Type | Class and Description |
|---|---|
| public static class | DeferredConstraintsMemory.
Info needed for check constraints |
| private static class | |
| private static class | DeferredConstraintsMemory.
Info needed for unique and primary key constraints |
| public abstract static class | DeferredConstraintsMemory.
Class hierarchy carrying the information we need to validate some deferred constraint. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static void | |
| public static Enumeration | |
| private static BackingStoreHashtable | |
| public static BackingStoreHashtable | Returns: the hash table (for caching by client to minimize lookups)the language connection context lcc, UUID the id of the target table basetableId, final String the schema of the target table schemaName, final String the target table name tableName, BackingStoreHashtable client cached value deferredCheckViolations, final List<UUID> offending constraint(s) violatingCheckConstraints, final RowLocation the duplicate row to be saved in the hash table
for later checking offendingRow, DeferredConstraintsMemory.OUT parameter: the allocated CheckInfo resultSave 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. |
| public static BackingStoreHashtable | Returns: the hash table (for caching by client to minimize lookups)the language connection context lcc, BackingStoreHashtable client cached value deferredRowsHashTable, UUID the id of the unique or primary key constraint constraintId, final DataValueDescriptor[] the duplicate row to be saved in the hash table
for later checking 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. |
| public static BackingStoreHashtable | Returns: value to cachethe language connection context lcc, BackingStoreHashtable cached client copy deferredRowsHashTable, final UUID the UUID of the foreign key constraint fkId, final DataValueDescriptor[] the row in the supporting index which contains
the key which is not present in the referenced index. indexRow, String the schema of the table schemaName, String the table being modified that has a FK. tableName)Make note of a violated foreign key constraint, i.e. the referenced key is not present |
| DeferredConstraintsMemory | back to summary |
|---|---|
| public DeferredConstraintsMemory() | |
| compressOrTruncate | back to summary |
|---|---|
| public static void compressOrTruncate(LanguageConnectionContext lcc, UUID tableId, String tableName) throws StandardException | |
| getDeferredCheckConstraintLocations | back to summary |
|---|---|
| public static Enumeration | |
| makeDeferredHashTable | back to summary |
|---|---|
| private static BackingStoreHashtable makeDeferredHashTable(final TransactionController tc, final int cols) throws StandardException | |
| rememberCheckViolations | back to summary |
|---|---|
| public static BackingStoreHashtable rememberCheckViolations(final LanguageConnectionContext lcc, UUID basetableId, final String schemaName, final String tableName, BackingStoreHashtable deferredCheckViolations, final List<UUID> violatingCheckConstraints, final RowLocation offendingRow, DeferredConstraintsMemory. 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.
| |
| rememberDuplicate | back to summary |
|---|---|
| public static BackingStoreHashtable rememberDuplicate(final LanguageConnectionContext lcc, BackingStoreHashtable deferredRowsHashTable, UUID constraintId, final 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.
| |
| rememberFKViolation | back to summary |
|---|---|
| public static BackingStoreHashtable rememberFKViolation(final LanguageConnectionContext lcc, BackingStoreHashtable deferredRowsHashTable, final UUID fkId, final DataValueDescriptor[] indexRow, String schemaName, String tableName) throws StandardException Make note of a violated foreign key constraint, i.e. the referenced key is not present
| |
| Modifier and Type | Field and Description |
|---|---|
| private List | |
| private boolean | |
| private final String | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public List | |
| public boolean | |
| public void | |
| public void | |
| private void | validateCheck(final LanguageConnectionContext lcc, final UUID constraintId, final boolean rollbackOnError)
|
| public final void | validateConstraint(LanguageConnectionContext
The language connection context lcc, UUID If not constraintId, boolean null, check only for this
constraint. This is used when switching mode to
immediate. If null, we check all check
constraints, i.e. at commit or if we have SET CONSTRAINT ALL IMMEDIATE.If rollbackOnError)true and a violation occurs, throw
and exception that will cause rollback.Implements abstract org. Validate one or more CHECK constraints on a table. |
| culprits | back to summary |
|---|---|
| private List<UUID> culprits | |
| invalidatedDueToCompress | back to summary |
|---|---|
| private boolean invalidatedDueToCompress | |
| schemaName | back to summary |
|---|---|
| private final String schemaName | |
| tableName | back to summary |
|---|---|
| private final String tableName | |
| CheckInfo | back to summary |
|---|---|
| public CheckInfo(final BackingStoreHashtable infoRows, final String schemaName, final String tableName, final List<UUID> culprits) | |
| addCulprits | back to summary |
|---|---|
| public void addCulprits(List<UUID> newCulprits) | |
| getCulprints | back to summary |
|---|---|
| public List | |
| isInvalidated | back to summary |
|---|---|
| public boolean isInvalidated() | |
| possiblyValidateOnReturn | back to summary |
|---|---|
| public void possiblyValidateOnReturn(LanguageConnectionContext lcc, SQLSessionContext nested, SQLSessionContext caller) throws StandardException Implements abstract org.
| |
| setInvalidatedRowLocations | back to summary |
|---|---|
| public void setInvalidatedRowLocations() | |
| validateCheck | back to summary |
|---|---|
| private void validateCheck(final LanguageConnectionContext lcc, final UUID constraintId, final boolean rollbackOnError) throws StandardException | |
| validateConstraint | back to summary |
|---|---|
| public final void validateConstraint(LanguageConnectionContext lcc, UUID constraintId, boolean rollbackOnError) throws StandardException Implements abstract org. Validate one or more CHECK constraints on a table. Implementation Note We remember violations for a row by storing its row location in a disk based hash table, similar to what we do for the index location for primary key and unique constraints. As far as which constraints caused which violations, constraints are only presently remembered as having caused "one or more violations", i.e. for any violating row, we do not know at checking time exactly which constraint caused a problem for that exact row. So, for any given constraint which was violated in the transaction we visit all rows which had one or more violations and check again. This could be improved upon by remembering for each violating row the exact set of constraint(s) that saw a violation. Still, this is much faster than a full table scan in most use cases. We use a special internal query option to achieve this. The row locations may not be usable if Derby does a compress or otherwise makes them invalid. In that case we resort to a full table scan.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final UUID | fkId
the UUID of the foreign constraint |
| private final String | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public | ForeignKeyInfo(final BackingStoreHashtable infoRows, UUID fkId, String schemaName, String tableName)
|
| Modifier and Type | Method and Description |
|---|---|
| public UUID | |
| public void | |
| public final void | validateConstraint(LanguageConnectionContext lcc, UUID constraintId, boolean rollbackOnError)
Implements abstract org.
|
| private void |
| fkId | back to summary |
|---|---|
| private final UUID fkId the UUID of the foreign constraint | |
| schemaName | back to summary |
|---|---|
| private final String schemaName | |
| tableName | back to summary |
|---|---|
| private final String tableName | |
| ForeignKeyInfo | back to summary |
|---|---|
| public ForeignKeyInfo(final BackingStoreHashtable infoRows, UUID fkId, String schemaName, String tableName) | |
| getFkId | back to summary |
|---|---|
| public UUID getFkId() | |
| possiblyValidateOnReturn | back to summary |
|---|---|
| public void possiblyValidateOnReturn(LanguageConnectionContext lcc, SQLSessionContext nested, SQLSessionContext caller) throws StandardException Implements abstract org.
| |
| validateConstraint | back to summary |
|---|---|
| public final void validateConstraint(LanguageConnectionContext lcc, UUID constraintId, boolean rollbackOnError) throws StandardException Implements abstract org.
| |
| validateForeignKey | back to summary |
|---|---|
| private void validateForeignKey(LanguageConnectionContext lcc, boolean rollbackOnError) throws StandardException | |
| Modifier and Type | Field and Description |
|---|---|
| private final UUID |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final void | |
| public final void | validateConstraint(LanguageConnectionContext
The language connection context lcc, UUID Not used by this constraint type constraintId, boolean true if we should roll back the
transaction if we see a violation of the constraintImplements abstract org. Validate one primary key or unique constraint |
| private void | validateUniquePK(final LanguageConnectionContext lcc, final BackingStoreHashtable ht, final boolean rollbackOnError)
|
| constraintId | back to summary |
|---|---|
| private final UUID constraintId | |
| UniquePkInfo | back to summary |
|---|---|
| public UniquePkInfo(BackingStoreHashtable infoRows, UUID constraintId) | |
| possiblyValidateOnReturn | back to summary |
|---|---|
| public final void possiblyValidateOnReturn(LanguageConnectionContext lcc, SQLSessionContext nested, SQLSessionContext caller) throws StandardException Implements abstract org.
| |
| validateConstraint | back to summary |
|---|---|
| public final void validateConstraint(LanguageConnectionContext lcc, UUID constraintId, boolean rollbackOnError) throws StandardException Implements abstract org. Validate one primary key or unique constraint
| |
| validateUniquePK | back to summary |
|---|---|
| private void validateUniquePK(final LanguageConnectionContext lcc, final BackingStoreHashtable ht, final boolean rollbackOnError) throws StandardException | |
| Modifier and Type | Field and Description |
|---|---|
| public final BackingStoreHashtable |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract void | possiblyValidateOnReturn(LanguageConnectionContext lcc, SQLSessionContext nested, SQLSessionContext caller)
|
| public abstract void |
| infoRows | back to summary |
|---|---|
| public final BackingStoreHashtable infoRows | |
| ValidationInfo | back to summary |
|---|---|
| public ValidationInfo(final BackingStoreHashtable infoRows) | |
| possiblyValidateOnReturn | back to summary |
|---|---|
| public abstract void possiblyValidateOnReturn(LanguageConnectionContext lcc, SQLSessionContext nested, SQLSessionContext caller) throws StandardException | |
| validateConstraint | back to summary |
|---|---|
| public abstract void validateConstraint(LanguageConnectionContext lcc, UUID constraintId, boolean rollbackOnError) throws StandardException | |