public abstract class SerialSerialKeyCreator<PK,D,SK> extends java.lang.Object implements SecondaryKeyCreator, ForeignKeyNullifier
If ForeignKeyDeleteAction.NULLIFY
was
specified when opening the secondary database, the following method must be
overridden to nullify the foreign index key. If NULLIFY was not specified,
this method need not be overridden.
Modifier and Type | Field and Description |
---|---|
protected SerialBinding<D> |
dataBinding |
protected SerialBinding<SK> |
indexKeyBinding |
protected SerialBinding<PK> |
primaryKeyBinding |
Constructor and Description |
---|
SerialSerialKeyCreator(ClassCatalog classCatalog,
java.lang.Class<PK> primaryKeyClass,
java.lang.Class<D> dataClass,
java.lang.Class<SK> indexKeyClass)
Creates a serial-serial key creator.
|
SerialSerialKeyCreator(SerialBinding<PK> primaryKeyBinding,
SerialBinding<D> dataBinding,
SerialBinding<SK> indexKeyBinding)
Creates a serial-serial entity binding.
|
Modifier and Type | Method and Description |
---|---|
abstract SK |
createSecondaryKey(PK primaryKey,
D data)
Creates the index key object from primary key and data objects.
|
boolean |
createSecondaryKey(SecondaryDatabase db,
DatabaseEntry primaryKeyEntry,
DatabaseEntry dataEntry,
DatabaseEntry indexKeyEntry)
Creates a secondary key entry, given a primary key and data entry.
|
D |
nullifyForeignKey(D data)
Clears the index key in a data object.
|
boolean |
nullifyForeignKey(SecondaryDatabase db,
DatabaseEntry dataEntry)
Sets the foreign key reference to null in the datum of the primary
database.
|
protected SerialBinding<PK> primaryKeyBinding
protected SerialBinding<D> dataBinding
protected SerialBinding<SK> indexKeyBinding
public SerialSerialKeyCreator(ClassCatalog classCatalog, java.lang.Class<PK> primaryKeyClass, java.lang.Class<D> dataClass, java.lang.Class<SK> indexKeyClass)
classCatalog
- is the catalog to hold shared class information and
for a database should be a StoredClassCatalog
.primaryKeyClass
- is the primary key base class.dataClass
- is the data base class.indexKeyClass
- is the index key base class.public SerialSerialKeyCreator(SerialBinding<PK> primaryKeyBinding, SerialBinding<D> dataBinding, SerialBinding<SK> indexKeyBinding)
primaryKeyBinding
- is the primary key binding.dataBinding
- is the data binding.indexKeyBinding
- is the index key binding.public boolean createSecondaryKey(SecondaryDatabase db, DatabaseEntry primaryKeyEntry, DatabaseEntry dataEntry, DatabaseEntry indexKeyEntry)
SecondaryKeyCreator
A secondary key may be derived from the primary key, primary data, or a combination of the primary key and data. For secondary keys that are optional, the key creator method may return false and the key/data pair will not be indexed. To ensure the integrity of a secondary database the key creator method must always return the same result for a given set of input parameters.
A RuntimeException
may be thrown by this method if an error
occurs attempting to create the secondary key. This exception will be
thrown by the API method currently in progress, for example, a put
method. However, this will cause the write operation
to be incomplete. When databases are not configured to be
transactional, caution should be used to avoid integrity problems. See
Special considerations for
using Secondary Databases with and without Transactions.
createSecondaryKey
in interface SecondaryKeyCreator
db
- the database to which the secondary key will be
added. This parameter is passed for informational purposes but is not
commonly used. This parameter is always non-null.primaryKeyEntry
- the primary key entry. This parameter must not be modified
by this method. This parameter is always non-null.dataEntry
- the primary data entry. This parameter must not be modified
by this method. If SecondaryConfig#setExtractFromPrimaryKeyOnly
is configured as true
, the data
param may be either null
or non-null, and the implementation is expected to ignore it; otherwise,
this parameter is always non-null.indexKeyEntry
- the secondary key created by this method. This parameter
is always non-null.public boolean nullifyForeignKey(SecondaryDatabase db, DatabaseEntry dataEntry)
ForeignKeyNullifier
nullifyForeignKey
in interface ForeignKeyNullifier
db
- the database in which the foreign key integrity
constraint is defined. This parameter is passed for informational
purposes but is not commonly used.dataEntry
- the existing primary datum in which the foreign key
reference should be set to null. This parameter should be updated by
this method if it returns true.public abstract SK createSecondaryKey(PK primaryKey, D data)
primaryKey
- is the deserialized source primary key entry, or
null if no primary key entry is used to construct the index key.data
- is the deserialized source data entry, or null if no
data entry is used to construct the index key.public D nullifyForeignKey(D data)
On entry the data parameter contains the index key to be cleared. It
should be changed by this method such that createSecondaryKey(com.sleepycat.je.SecondaryDatabase, com.sleepycat.je.DatabaseEntry, com.sleepycat.je.DatabaseEntry, com.sleepycat.je.DatabaseEntry)
will return false. Other fields in the data object should remain
unchanged.
data
- is the source and destination data object.Copyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.