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

public Class RIBulkChecker

extends Object
Class Inheritance
Imports
org.apache.derby.catalog.UUID, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.sql.Activation, .LanguageProperties, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.execute.ExecRow, org.apache.derby.iapi.store.access.BackingStoreHashtable, .ConglomerateController, .GroupFetchScanController, org.apache.derby.iapi.types.DataValueDescriptor, .RowLocation

Do a merge run comparing all the foreign keys from the foreign key conglomerate against the referenced keys from the primary key conglomerate. The scanControllers are passed in by the caller (caller controls locking on said conglomerates).

The comparision is done via a merge. Consequently, it is imperative that the scans are on keyed conglomerates (indexes) and that the referencedKeyScan is a unique scan.

Performance is no worse than N + M where N is foreign key rows and M is primary key rows.

Bulk fetch is used to further speed performance. The fetch size is LanguageProperties.BULK_FETCH_DEFAULT

See Also
LanguageProperties

Field Summary

Modifier and TypeField and Description
private final UUID
private int
private int
private final boolean
private BackingStoreHashtable
private static final int
private int
private ExecRow
private final long
private DataValueDescriptor[][]
private GroupFetchScanController
private static final int
private int
private int
private final LanguageConnectionContext
private static final int
private int
private final long
private boolean
private DataValueDescriptor[][]
private GroupFetchScanController
private final String
private final String
private ConglomerateController

Constructor Summary

AccessConstructor and Description
public
RIBulkChecker(Activation
the activation
a
,
GroupFetchScanController
scan of the referenced key's backing index. must be unique
referencedKeyScan
,
GroupFetchScanController
scan of the foreign key's backing index
foreignKeyScan
,
ExecRow
a template row for the indexes. Will be cloned when it is used. Must be a full index row.
templateRow
,
boolean
quit on first unreferenced key
quitOnFirstFailure
,
ConglomerateController
put unreferenced keys here
unreferencedCC
,
ExecRow
the first row that fails the constraint is copied to this, if non-null
firstRowToFail
,
String
schema name of the table we insert into
schemaName
,
String
table name of the table we insert into
tableName
,
UUID
constraint id of the foreign constraint
constraintId
,
boolean
true if the constraint is deferrable
deferrable
,
long
conglomerate id of the foreign key supporting index
fkCID
,
long
conglomerate id of the referenced primary key or unique index.
pkCID
)

Create a RIBulkChecker

Method Summary

Modifier and TypeMethod and Description
private boolean
public int

Returns:

the number of failed rows
doCheck
()

Perform the check.

private void
failure(DataValueDescriptor[] foreignKeyRow)

private DataValueDescriptor[]
private DataValueDescriptor[]
private int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

constraintIdback to summary
private final UUID constraintId
currFKRowIndexback to summary
private int currFKRowIndex
currRefRowIndexback to summary
private int currRefRowIndex
deferredback to summary
private final boolean deferred
deferredRowsHashTableback to summary
private BackingStoreHashtable deferredRowsHashTable
EQUALback to summary
private static final int EQUAL
failedCounterback to summary
private int failedCounter
firstRowToFailback to summary
private ExecRow firstRowToFail
fkCIDback to summary
private final long fkCID
foreignKeyRowArrayback to summary
private DataValueDescriptor[][] foreignKeyRowArray
foreignKeyScanback to summary
private GroupFetchScanController foreignKeyScan
GREATER_THANback to summary
private static final int GREATER_THAN
lastFKRowIndexback to summary
private int lastFKRowIndex
lastRefRowIndexback to summary
private int lastRefRowIndex
lccback to summary
private final LanguageConnectionContext lcc
LESS_THANback to summary
private static final int LESS_THAN
numColumnsback to summary
private int numColumns
pkCIDback to summary
private final long pkCID
quitOnFirstFailureback to summary
private boolean quitOnFirstFailure
referencedKeyRowArrayback to summary
private DataValueDescriptor[][] referencedKeyRowArray
referencedKeyScanback to summary
private GroupFetchScanController referencedKeyScan
schemaNameback to summary
private final String schemaName
tableNameback to summary
private final String tableName
unreferencedCCback to summary
private ConglomerateController unreferencedCC

Constructor Detail

RIBulkCheckerback to summary
public RIBulkChecker(Activation a, GroupFetchScanController referencedKeyScan, GroupFetchScanController foreignKeyScan, ExecRow templateRow, boolean quitOnFirstFailure, ConglomerateController unreferencedCC, ExecRow firstRowToFail, String schemaName, String tableName, UUID constraintId, boolean deferrable, long fkCID, long pkCID) throws StandardException

Create a RIBulkChecker

Parameters
a:Activation

the activation

referencedKeyScan:GroupFetchScanController

scan of the referenced key's backing index. must be unique

foreignKeyScan:GroupFetchScanController

scan of the foreign key's backing index

templateRow:ExecRow

a template row for the indexes. Will be cloned when it is used. Must be a full index row.

quitOnFirstFailure:boolean

quit on first unreferenced key

unreferencedCC:ConglomerateController

put unreferenced keys here

firstRowToFail:ExecRow

the first row that fails the constraint is copied to this, if non-null

schemaName:String

schema name of the table we insert into

tableName:String

table name of the table we insert into

constraintId:UUID

constraint id of the foreign constraint

deferrable:boolean

true if the constraint is deferrable

fkCID:long

conglomerate id of the foreign key supporting index

pkCID:long

conglomerate id of the referenced primary key or unique index.

Method Detail

anyNullback to summary
private boolean anyNull(DataValueDescriptor[] fkRowArray) throws StandardException
doCheckback to summary
public int doCheck() throws StandardException

Perform the check. If deferred constraint mode, the numbers of failed rows returned will be always be 0 (but any violating keys will have been saved for later checking).

Returns:int

the number of failed rows

Exceptions
StandardException:
on error
failureback to summary
private void failure(DataValueDescriptor[] foreignKeyRow) throws StandardException
getNextFKback to summary
private DataValueDescriptor[] getNextFK() throws StandardException
getNextRefback to summary
private DataValueDescriptor[] getNextRef() throws StandardException
greaterThanback to summary
private int greaterThan(DataValueDescriptor[] fkRowArray, DataValueDescriptor[] refRowArray) throws StandardException