Berkeley DB
version 4.2.52

com.sleepycat.bdb
Class ForeignKeyIndex

java.lang.Object
  |
  +--com.sleepycat.bdb.DataIndex
        |
        +--com.sleepycat.bdb.ForeignKeyIndex

public class ForeignKeyIndex
extends DataIndex

Represents a Berkeley DB secondary index where the index key is the primary key of another data store. An index is always attached to a single DataStore when it is constructed. An index is typically accessed by passing it to the constructor of one of the collection classes in the com.sleepycat.bdb.collection package. For example:

 Db db = new Db(env, 0);
 db.setFlags(Db.DB_DUPSORT);
 db.open(null, "index.db", null, Db.DB_BTREE, dbOpenFlags, 0);
 ForeignKeyIndex index = new ForeignKeyIndex(store, db, keyExtractor,
                                             foreignStore, deleteAction);
 StoredMap map = new StoredMap(index, keyBinding, valueBinding, writeAllowed);
 

All access methods may be used with BDB. However, some access methods may only be used with certain types of collection views, and some access methods impose restrictions on the way collection views are used.


Field Summary
static int ON_DELETE_ABORT
          When the foreign key is deleted, throw an exception.
static int ON_DELETE_CASCADE
          When the foreign key is deleted, delete the index key.
static int ON_DELETE_CLEAR
          When the foreign key is deleted, clear the index key.
 
Constructor Summary
ForeignKeyIndex(DataStore store, Db db, KeyExtractor keyExtractor, DataStore foreignStore, int deleteAction)
          Creates a foreign key index from a previously opened Db object.
 
Method Summary
 int getDeleteAction()
          Returns a value indicating what action occurs when the foreign key is deleted.
 DataStore getForeignStore()
          Returns the foreign store which has the primary key which matches the index key of this store.
 
Methods inherited from class com.sleepycat.bdb.DataIndex
getKeyExtractor, getKeyFormat, getStore, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ON_DELETE_ABORT

public static final int ON_DELETE_ABORT
When the foreign key is deleted, throw an exception.

See Also:
Constant Field Values

ON_DELETE_CASCADE

public static final int ON_DELETE_CASCADE
When the foreign key is deleted, delete the index key.

See Also:
Constant Field Values

ON_DELETE_CLEAR

public static final int ON_DELETE_CLEAR
When the foreign key is deleted, clear the index key.

See Also:
Constant Field Values
Constructor Detail

ForeignKeyIndex

public ForeignKeyIndex(DataStore store,
                       Db db,
                       KeyExtractor keyExtractor,
                       DataStore foreignStore,
                       int deleteAction)
Creates a foreign key index from a previously opened Db object.

Parameters:
store - the store to be indexed and also specifies the environment that was used to create the Db object.
db - the previously opened Db object.
keyExtractor - an object for extracting the index key from primary key and/or value buffers, and for clearing the index key in a value buffer.
foreignStore - is the store in which the index key for this store is a primary key.
deleteAction - determines what action occurs when the foreign key is deleted. It must be one of the ON_DELETE_ constants.
Throws:
IllegalArgumentException - if a format mismatch is detected between the index and the store, or if unsorted duplicates were specified for the index Db.
Method Detail

getForeignStore

public final DataStore getForeignStore()
Returns the foreign store which has the primary key which matches the index key of this store.


getDeleteAction

public final int getDeleteAction()
Returns a value indicating what action occurs when the foreign key is deleted. It must be one of the ON_DELETE_ constants.


Berkeley DB
version 4.2.52

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.