Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

public Class ReferencedKeyRIChecker

extends GenericRIChecker
Class Inheritance
Imports
java.util.Enumeration, org.apache.derby.catalog.UUID, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.sql.Activation, .StatementType, .StatementUtil, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.execute.ExecRow, org.apache.derby.iapi.store.access.BackingStoreHashtable, .KeyHasher, .ScanController, .TransactionController, org.apache.derby.iapi.types.DataValueDescriptor, .SQLLongint, org.apache.derby.shared.common.sanity.SanityManager

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

Modifier and TypeField and 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 in postCheck().

private final DataValueDescriptor[]
refKey

Key mapping used when storing referenced (PK, unique) keys under deferred row processing and deferred key constraint (PK, unique).

private ScanController
Inherited from org.apache.derby.impl.sql.execute.GenericRIChecker:
deferredRowsHashTablefkDcocisfkInfofkScocisidentityMapindexQualifierRowlccnumColumnsrefDcocirefScocitc

Constructor Summary

AccessConstructor and Description
pack-priv
ReferencedKeyRIChecker(LanguageConnectionContext
the language connection context
lcc
,
TransactionController
the xact controller
tc
,
FKInfo
the foreign key information
fkinfo
)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
close()

Overrides org.apache.derby.impl.sql.execute.GenericRIChecker.close.

Clean up all scan controllers and other resources

pack-priv void
doCheck(Activation
the activation
a
,
ExecRow
the row to check
row
,
boolean
true if the check is relevant only for RESTRICTED referential action.
restrictCheckOnly
,
int
For referenced keys: The required number of duplicates that need to be present. Only used if postCheck==false.
deferredRowReq
)

Implements abstract org.apache.derby.impl.sql.execute.GenericRIChecker.doCheck.

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)

public 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}.

Inherited from org.apache.derby.impl.sql.execute.GenericRIChecker:
getRICheckIsolationLevelgetScanControllerisAnyFieldNull

Field Detail

deletedKeysback to summary
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 in postCheck(). Initialized on demand.

refKeyback to summary
private final DataValueDescriptor[] refKey

Key mapping used when storing referenced (PK, unique) keys under deferred row processing and deferred key constraint (PK, unique).

refKeyIndexScanback to summary
private ScanController refKeyIndexScan

Constructor Detail

ReferencedKeyRICheckerback to summary
pack-priv ReferencedKeyRIChecker(LanguageConnectionContext lcc, TransactionController tc, FKInfo fkinfo) throws StandardException
Parameters
lcc:LanguageConnectionContext

the language connection context

tc:TransactionController

the xact controller

fkinfo:FKInfo

the foreign key information

Exceptions
StandardException:
Thrown on failure

Method Detail

closeback to summary
pack-priv void close() throws StandardException

Overrides org.apache.derby.impl.sql.execute.GenericRIChecker.close.

Clean up all scan controllers and other resources

Annotations
@Override
Exceptions
StandardException:
on error
doCheckback to summary
pack-priv void doCheck(Activation a, ExecRow row, boolean restrictCheckOnly, int deferredRowReq) throws StandardException

Implements abstract org.apache.derby.impl.sql.execute.GenericRIChecker.doCheck.

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.

Parameters
a:Activation

the activation

row:ExecRow

the row to check

restrictCheckOnly:boolean

true if the check is relevant only for RESTRICTED referential action.

deferredRowReq:int

For referenced keys: The required number of duplicates that need to be present. Only used if postCheck==false.

Annotations
@Override
Exceptions
StandardException:
on unexpected error, or on a primary/unique key violation
isDuplicatedback to summary
private boolean isDuplicated(ExecRow row, int deferredRowReq) throws StandardException
isDuplicatedback to summary
private boolean isDuplicated(DataValueDescriptor[] key, long deferredRowReq) throws StandardException
postCheckback to summary
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

Exceptions
StandardException:
Standard error policy
rememberKeyback to summary
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}.