com.sleepycat.persist
Class BasicIndex<K,E>

java.lang.Object
  extended by com.sleepycat.persist.BasicIndex<K,E>
All Implemented Interfaces:
EntityIndex<K,E>
Direct Known Subclasses:
KeysIndex, PrimaryIndex, SecondaryIndex

abstract class BasicIndex<K,E>
extends java.lang.Object
implements EntityIndex<K,E>

Implements EntityIndex using a ValueAdapter. This class is abstract and does not implement get()/map()/sortedMap() because it doesn't have access to the entity binding.

Author:
Mark Hayes

Field Summary
(package private)  Database db
           
(package private)  KeyRange emptyRange
           
(package private)  ValueAdapter<E> entityAdapter
           
(package private)  ValueAdapter<K> keyAdapter
           
(package private)  EntryBinding keyBinding
           
(package private)  java.lang.Class<K> keyClass
           
(package private) static DatabaseEntry NO_RETURN_ENTRY
           
(package private)  boolean transactional
           
 
Constructor Summary
BasicIndex(Database db, java.lang.Class<K> keyClass, EntryBinding keyBinding, ValueAdapter<E> entityAdapter)
           
 
Method Summary
 boolean contains(K key)
          Checks for existence of a key in this index.
 boolean contains(Transaction txn, K key, LockMode lockMode)
          Checks for existence of a key in this index.
 boolean delete(K key)
          Deletes all entities with a given index key.
 boolean delete(Transaction txn, K key)
          Deletes all entities with a given index key.
 EntityCursor<E> entities()
          Opens a cursor for traversing all entities in this index.
 EntityCursor<E> entities(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
          Opens a cursor for traversing entities in a key range.
 EntityCursor<E> entities(Transaction txn, CursorConfig config)
          Opens a cursor for traversing all entities in this index.
 EntityCursor<E> entities(Transaction txn, K fromKey, boolean fromInclusive, K toKey, boolean toInclusive, CursorConfig config)
          Opens a cursor for traversing entities in a key range.
 EntityCursor<K> keys()
          Opens a cursor for traversing all keys in this index.
 EntityCursor<K> keys(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
          Opens a cursor for traversing keys in a key range.
 EntityCursor<K> keys(Transaction txn, CursorConfig config)
          Opens a cursor for traversing all keys in this index.
 EntityCursor<K> keys(Transaction txn, K fromKey, boolean fromInclusive, K toKey, boolean toInclusive, CursorConfig config)
          Opens a cursor for traversing keys in a key range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sleepycat.persist.EntityIndex
get, get, map, sortedMap
 

Field Detail

NO_RETURN_ENTRY

static final DatabaseEntry NO_RETURN_ENTRY

db

Database db

transactional

boolean transactional

keyClass

java.lang.Class<K> keyClass

keyBinding

EntryBinding keyBinding

emptyRange

KeyRange emptyRange

keyAdapter

ValueAdapter<K> keyAdapter

entityAdapter

ValueAdapter<E> entityAdapter
Constructor Detail

BasicIndex

BasicIndex(Database db,
           java.lang.Class<K> keyClass,
           EntryBinding keyBinding,
           ValueAdapter<E> entityAdapter)
     throws DatabaseException
Throws:
DatabaseException
Method Detail

contains

public boolean contains(K key)
                 throws DatabaseException
Description copied from interface: EntityIndex
Checks for existence of a key in this index.

The operation will not be transaction protected, and LockMode.DEFAULT is used implicitly.

Specified by:
contains in interface EntityIndex<K,E>
Parameters:
key - the key to search for.
Returns:
whether the key exists in the index.
Throws:
DatabaseException

contains

public boolean contains(Transaction txn,
                        K key,
                        LockMode lockMode)
                 throws DatabaseException
Description copied from interface: EntityIndex
Checks for existence of a key in this index.

Specified by:
contains in interface EntityIndex<K,E>
Parameters:
txn - the transaction used to protect this operation, or null if the operation should not be transaction protected.
key - the key to search for.
lockMode - the lock mode to use for this operation, or null to use LockMode.DEFAULT.
Returns:
whether the key exists in the index.
Throws:
DatabaseException

delete

public boolean delete(K key)
               throws DatabaseException
Description copied from interface: EntityIndex
Deletes all entities with a given index key.

Auto-commit is used implicitly if the store is transactional.

Specified by:
delete in interface EntityIndex<K,E>
Parameters:
key - the key to search for.
Returns:
whether any entities were deleted.
Throws:
DatabaseException

delete

public boolean delete(Transaction txn,
                      K key)
               throws DatabaseException
Description copied from interface: EntityIndex
Deletes all entities with a given index key.

Specified by:
delete in interface EntityIndex<K,E>
Parameters:
txn - the transaction used to protect this operation, null to use auto-commit, or null if the store is non-transactional.
key - the key to search for.
Returns:
whether any entities were deleted.
Throws:
DatabaseException

keys

public EntityCursor<K> keys()
                     throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing all keys in this index.

The operations performed with the cursor will not be transaction protected, and CursorConfig.DEFAULT is used implicitly. If the store is transactional, the cursor may not be used to update or delete entities.

Specified by:
keys in interface EntityIndex<K,E>
Returns:
the cursor.
Throws:
DatabaseException

keys

public EntityCursor<K> keys(Transaction txn,
                            CursorConfig config)
                     throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing all keys in this index.

Specified by:
keys in interface EntityIndex<K,E>
Parameters:
txn - the transaction used to protect all operations performed with the cursor, or null if the operations should not be transaction protected. If null is specified and the store is transactional, the cursor may not be used to update or delete entities.
config - the cursor configuration that determines the default lock mode used for all cursor operations, or null to implicitly use CursorConfig.DEFAULT.
Returns:
the cursor.
Throws:
DatabaseException

entities

public EntityCursor<E> entities()
                         throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing all entities in this index.

The operations performed with the cursor will not be transaction protected, and CursorConfig.DEFAULT is used implicitly. If the store is transactional, the cursor may not be used to update or delete entities.

Specified by:
entities in interface EntityIndex<K,E>
Returns:
the cursor.
Throws:
DatabaseException

entities

public EntityCursor<E> entities(Transaction txn,
                                CursorConfig config)
                         throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing all entities in this index.

Specified by:
entities in interface EntityIndex<K,E>
Parameters:
txn - the transaction used to protect all operations performed with the cursor, or null if the operations should not be transaction protected. If null is specified and the store is transactional, the cursor may not be used to update or delete entities.
config - the cursor configuration that determines the default lock mode used for all cursor operations, or null to implicitly use CursorConfig.DEFAULT.
Returns:
the cursor.
Throws:
DatabaseException

keys

public EntityCursor<K> keys(K fromKey,
                            boolean fromInclusive,
                            K toKey,
                            boolean toInclusive)
                     throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing keys in a key range.

The operations performed with the cursor will not be transaction protected, and CursorConfig.DEFAULT is used implicitly. If the store is transactional, the cursor may not be used to update or delete entities.

Specified by:
keys in interface EntityIndex<K,E>
Parameters:
fromKey - is the lower bound of the key range, or null if the range has no lower bound.
fromInclusive - is true if keys greater than or equal to fromKey should be included in the key range, or false if only keys greater than fromKey should be included.
toKey - is the upper bound of the key range, or null if the range has no upper bound.
toInclusive - is true if keys less than or equal to toKey should be included in the key range, or false if only keys less than toKey should be included.
Returns:
the cursor.
Throws:
DatabaseException

keys

public EntityCursor<K> keys(Transaction txn,
                            K fromKey,
                            boolean fromInclusive,
                            K toKey,
                            boolean toInclusive,
                            CursorConfig config)
                     throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing keys in a key range.

Specified by:
keys in interface EntityIndex<K,E>
Parameters:
txn - the transaction used to protect all operations performed with the cursor, or null if the operations should not be transaction protected. If null is specified and the store is transactional, the cursor may not be used to update or delete entities.
fromKey - is the lower bound of the key range, or null if the range has no lower bound.
fromInclusive - is true if keys greater than or equal to fromKey should be included in the key range, or false if only keys greater than fromKey should be included.
toKey - is the upper bound of the key range, or null if the range has no upper bound.
toInclusive - is true if keys less than or equal to toKey should be included in the key range, or false if only keys less than toKey should be included.
config - the cursor configuration that determines the default lock mode used for all cursor operations, or null to implicitly use CursorConfig.DEFAULT.
Returns:
the cursor.
Throws:
DatabaseException

entities

public EntityCursor<E> entities(K fromKey,
                                boolean fromInclusive,
                                K toKey,
                                boolean toInclusive)
                         throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing entities in a key range.

The operations performed with the cursor will not be transaction protected, and CursorConfig.DEFAULT is used implicitly. If the store is transactional, the cursor may not be used to update or delete entities.

Specified by:
entities in interface EntityIndex<K,E>
Parameters:
fromKey - is the lower bound of the key range, or null if the range has no lower bound.
fromInclusive - is true if keys greater than or equal to fromKey should be included in the key range, or false if only keys greater than fromKey should be included.
toKey - is the upper bound of the key range, or null if the range has no upper bound.
toInclusive - is true if keys less than or equal to toKey should be included in the key range, or false if only keys less than toKey should be included.
Returns:
the cursor.
Throws:
DatabaseException

entities

public EntityCursor<E> entities(Transaction txn,
                                K fromKey,
                                boolean fromInclusive,
                                K toKey,
                                boolean toInclusive,
                                CursorConfig config)
                         throws DatabaseException
Description copied from interface: EntityIndex
Opens a cursor for traversing entities in a key range.

Specified by:
entities in interface EntityIndex<K,E>
Parameters:
txn - the transaction used to protect all operations performed with the cursor, or null if the operations should not be transaction protected. If null is specified and the store is transactional, the cursor may not be used to update or delete entities.
fromKey - is the lower bound of the key range, or null if the range has no lower bound.
fromInclusive - is true if keys greater than or equal to fromKey should be included in the key range, or false if only keys greater than fromKey should be included.
toKey - is the upper bound of the key range, or null if the range has no upper bound.
toInclusive - is true if keys less than or equal to toKey should be included in the key range, or false if only keys less than toKey should be included.
config - the cursor configuration that determines the default lock mode used for all cursor operations, or null to implicitly use CursorConfig.DEFAULT.
Returns:
the cursor.
Throws:
DatabaseException


Copyright 2004-2006 Sleepycat, Inc. All Rights Reserved.