com.sleepycat.collections
Class StoredContainer

java.lang.Object
  extended by com.sleepycat.collections.StoredContainer
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
StoredCollection, StoredMap

public abstract class StoredContainer
extends Object
implements Cloneable

A abstract base class for all stored collections and maps. This class provides implementations of methods that are common to the Collection and the Map interfaces, namely clear(), isEmpty() and size().

In addition, this class provides the following methods for stored collections only. Note that the use of these methods is not compatible with the standard Java collections interface.

Author:
Mark Hayes

Field Summary
(package private)  DataView view
           
 
Constructor Summary
StoredContainer(DataView view)
           
 
Method Summary
 boolean areDuplicatesAllowed()
          Returns whether duplicate keys are allowed in this container.
 boolean areDuplicatesOrdered()
          Returns whether duplicate keys are allowed and sorted by element value.
 boolean areKeyRangesAllowed()
          Returns whether key ranges are allowed in this container.
 boolean areKeysRenumbered()
          Returns whether keys are renumbered when insertions and deletions occur.
(package private)  boolean beginAutoCommit()
           
 void clear()
          Removes all mappings or elements from this map or collection (optional operation).
(package private)  void closeCursor(DataCursor cursor)
           
(package private)  void commitAutoCommit(boolean doAutoCommit)
           
(package private)  StoredContainer configuredClone(CursorConfig config)
          Clones a container with a specified cursor configuration.
(package private)  boolean containsKey(Object key)
           
(package private)  boolean containsValue(Object value)
           
(package private) static RuntimeException convertException(Exception e)
           
 CursorConfig getCursorConfig()
          Returns the cursor configuration that is used for all operations performed via this container.
(package private)  Object getValue(Object key)
           
(package private)  RuntimeException handleException(Exception e, boolean doAutoCommit)
           
(package private)  void initAfterClone()
          Override this method to initialize view-dependent fields.
 boolean isEmpty()
          Returns true if this map or collection contains no mappings or elements.
 boolean isOrdered()
          Returns whether keys are ordered in this container.
 boolean isSecondary()
          Returns whether this container is a view on a secondary database rather than directly on a primary database.
 boolean isTransactional()
          Returns whether the databases underlying this container are transactional.
 boolean isWriteAllowed()
          Returns true if this is a read-write container or false if this is a read-only container.
(package private)  Object putKeyValue(Object key, Object value)
           
(package private)  boolean removeKey(Object key, Object[] oldVal)
           
(package private)  boolean removeValue(Object value)
           
abstract  int size()
          Returns a non-transactional count of the records in the collection or map.
(package private)  Iterator storedOrExternalIterator(Collection coll)
          Returns a StoredIterator if the given collection is a StoredCollection, else returns a regular/external Iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

view

DataView view
Constructor Detail

StoredContainer

StoredContainer(DataView view)
Method Detail

isWriteAllowed

public final boolean isWriteAllowed()
Returns true if this is a read-write container or false if this is a read-only container. This method does not exist in the standard Map or Collection interfaces.

Returns:
whether write is allowed.

getCursorConfig

public final CursorConfig getCursorConfig()
Returns the cursor configuration that is used for all operations performed via this container. For example, if CursorConfig.getReadUncommitted returns true, data will be read that is modified but not committed. This method does not exist in the standard Map or Collection interfaces.

Returns:
the cursor configuration, or null if no configuration has been specified.

isTransactional

public final boolean isTransactional()
Returns whether the databases underlying this container are transactional. Even in a transactional environment, a database will be transactional only if it was opened within a transaction or if the auto-commit option was specified when it was opened. This method does not exist in the standard Map or Collection interfaces.

Returns:
whether the database is transactional.

configuredClone

final StoredContainer configuredClone(CursorConfig config)
Clones a container with a specified cursor configuration.


initAfterClone

void initAfterClone()
Override this method to initialize view-dependent fields.


areDuplicatesAllowed

public final boolean areDuplicatesAllowed()
Returns whether duplicate keys are allowed in this container. Duplicates are optionally allowed for HASH and BTREE databases. This method does not exist in the standard Map or Collection interfaces.

Note that the JE product only supports BTREE databases.

Returns:
whether duplicates are allowed.

areDuplicatesOrdered

public final boolean areDuplicatesOrdered()
Returns whether duplicate keys are allowed and sorted by element value. Duplicates are optionally sorted for HASH and BTREE databases. This method does not exist in the standard Map or Collection interfaces.

Note that the JE product only supports BTREE databases, and duplicates are always sorted.

Returns:
whether duplicates are ordered.

areKeysRenumbered

public final boolean areKeysRenumbered()
Returns whether keys are renumbered when insertions and deletions occur. Keys are optionally renumbered for RECNO databases. This method does not exist in the standard Map or Collection interfaces.

Note that the JE product does not support RECNO databases, and therefore keys are never renumbered.

Returns:
whether keys are renumbered.

isOrdered

public final boolean isOrdered()
Returns whether keys are ordered in this container. Keys are ordered for BTREE, RECNO and QUEUE databases. This method does not exist in the standard Map or Collection interfaces.

Note that the JE product only support BTREE databases, and therefore keys are always ordered.

Returns:
whether keys are ordered.

areKeyRangesAllowed

public final boolean areKeyRangesAllowed()
Returns whether key ranges are allowed in this container. Key ranges are allowed only for BTREE databases. This method does not exist in the standard Map or Collection interfaces.

Note that the JE product only supports BTREE databases, and therefore key ranges are always allowed.

Returns:
whether keys are ordered.

isSecondary

public final boolean isSecondary()
Returns whether this container is a view on a secondary database rather than directly on a primary database. This method does not exist in the standard Map or Collection interfaces.

Returns:
whether the view is for a secondary database.

size

public abstract int size()
Returns a non-transactional count of the records in the collection or map. This method conforms to the Collection.size() and Map.size() interfaces.

This operation is faster than obtaining a count by scanning the collection manually, and will not perturb the current contents of the cache. However, the count is not guaranteed to be accurate if there are concurrent updates.

Throws:
OperationFailureException - if one of the Read Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C edition).

isEmpty

public boolean isEmpty()
Returns true if this map or collection contains no mappings or elements. This method conforms to the Collection.isEmpty() and Map.isEmpty() interfaces.

Returns:
whether the container is empty.
Throws:
OperationFailureException - if one of the Read Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C edition).

clear

public void clear()
Removes all mappings or elements from this map or collection (optional operation). This method conforms to the Collection.clear() and Map.clear() interfaces.

Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the container is read-only.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C edition).

getValue

Object getValue(Object key)

putKeyValue

Object putKeyValue(Object key,
                   Object value)

removeKey

final boolean removeKey(Object key,
                        Object[] oldVal)

containsKey

boolean containsKey(Object key)

removeValue

final boolean removeValue(Object value)

containsValue

boolean containsValue(Object value)

storedOrExternalIterator

final Iterator storedOrExternalIterator(Collection coll)
Returns a StoredIterator if the given collection is a StoredCollection, else returns a regular/external Iterator. The iterator returned should be closed with the static method StoredIterator.close(Iterator).


closeCursor

final void closeCursor(DataCursor cursor)

beginAutoCommit

final boolean beginAutoCommit()

commitAutoCommit

final void commitAutoCommit(boolean doAutoCommit)
                     throws DatabaseException
Throws:
DatabaseException

handleException

final RuntimeException handleException(Exception e,
                                       boolean doAutoCommit)

convertException

static RuntimeException convertException(Exception e)


Copyright (c) 2004-2010 Oracle. All rights reserved.