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 Summary
Fields Modifier and Type Field Description 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 inpostCheck()
.private DataValueDescriptor[]
refKey
Key mapping used when storing referenced (PK, unique) keys under deferred row processing and deferred key constraint (PK, unique).private ScanController
refKeyIndexScan
-
Fields inherited from class org.apache.derby.impl.sql.execute.GenericRIChecker
deferredRowsHashTable, fkDcocis, fkInfo, fkScocis, identityMap, indexQualifierRow, lcc, numColumns, refDcoci, refScoci, tc
-
-
Constructor Summary
Constructors Constructor Description ReferencedKeyRIChecker(LanguageConnectionContext lcc, TransactionController tc, FKInfo fkinfo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
close()
Clean up all scan controllers and other resources(package private) void
doCheck(Activation a, ExecRow row, boolean restrictCheckOnly, int deferredRowReq)
Check that the row either has a null column(s), or has no corresponding foreign keys.private boolean
isDuplicated(ExecRow row, int deferredRowReq)
private boolean
isDuplicated(DataValueDescriptor[] key, long deferredRowReq)
void
postCheck()
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.private void
rememberKey(ExecRow rememberRow)
Remember the deletion of this key, it may cause a RESTRICT foreign key violation, cf. logic in @{link #postCheck}.-
Methods inherited from class org.apache.derby.impl.sql.execute.GenericRIChecker
getRICheckIsolationLevel, getScanController, isAnyFieldNull
-
-
-
-
Field Detail
-
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 inpostCheck()
. Initialized on demand.
-
-
Constructor Detail
-
ReferencedKeyRIChecker
ReferencedKeyRIChecker(LanguageConnectionContext lcc, TransactionController tc, FKInfo fkinfo) throws StandardException
- Parameters:
lcc
- the language connection contexttc
- the xact controllerfkinfo
- the foreign key information- Throws:
StandardException
- Thrown on failure
-
-
Method Detail
-
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 classGenericRIChecker
- Parameters:
a
- the activationrow
- the row to checkrestrictCheckOnly
-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 ifpostCheck==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 classGenericRIChecker
- Throws:
StandardException
- on error
-
-