Berkeley DB
version 4.2.52

com.sleepycat.bdb
Class DataStore

java.lang.Object
  |
  +--com.sleepycat.bdb.DataStore

public class DataStore
extends Object

Represents a Berkeley DB database in the role of a primary data store. A store may be used by itself or along with one or more DataIndex objects. A store 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.open(null, "store.db", null, Db.DB_BTREE, dbOpenFlags, 0);
 DataStore store = new DataStore(db, keyFormat, valueFormat, keyAssigner);
 StoredMap map = new StoredMap(store, 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.

A store is always associated with the environment of its underlying database, which is the first parameter to the {Db#Db} constructor. There are three types of environments in Berkeley DB.

Environment Access Mode Berkeley DB Flags
Data Store single-threaded access Db.DB_INIT_MPOOL
Concurrent Data Store single-writer multiple-reader access Db.DB_INIT_CDB | Db.DB_INIT_MPOOL
Transactional Data Store transactional access for any number of readers and writers Db.DB_INIT_TXN | Db.DB_INIT_LOCK | Db.DB_INIT_MPOOL

The flags shown are the minimum required for creating the Berkeley DB environment. Many other Berkeley DB options are also available. For details on creating and configuring the environment see the Berkeley DB documentation.

All three environments may be used within BDB. However, the Concurrent Data Store Environment imposes the restriction that only one writable cursor may be open at a time. This means that if you have a writable iterator for a data store open, then you cannot obtain another writable iterator for the same data store and you cannot perform other write operations through a collection for that data store (since this also uses a write cursor).


Constructor Summary
DataStore(Db db, DataFormat keyFormat, DataFormat valueFormat, PrimaryKeyAssigner keyAssigner)
          Creates a store from a previously opened Db object.
 
Method Summary
 void close()
          Closes the store and all associated indices.
 DbEnv getEnv()
          Returns the environment associated with this store.
 Iterator getIndices()
          Returns the indices associated with this store.
 PrimaryKeyAssigner getKeyAssigner()
          Returns the key assigner associated with this store.
 DataFormat getKeyFormat()
          Returns the key format associated with this store.
 DataFormat getValueFormat()
          Returns the value format associated with this store.
 String toString()
          Returns a printable string identifying the filename and datbase name of the store.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataStore

public DataStore(Db db,
                 DataFormat keyFormat,
                 DataFormat valueFormat,
                 PrimaryKeyAssigner keyAssigner)
Creates a store from a previously opened Db object.

Parameters:
db - the previously opened Db object.
keyFormat - the data format for keys.
valueFormat - the data format for values.
keyAssigner - an object for assigning keys or null if no automatic key assignment is used.
Method Detail

close

public void close()
           throws DbException
Closes the store and all associated indices.

DbException

getEnv

public final DbEnv getEnv()
Returns the environment associated with this store.


getKeyFormat

public final DataFormat getKeyFormat()
Returns the key format associated with this store.


getKeyAssigner

public final PrimaryKeyAssigner getKeyAssigner()
Returns the key assigner associated with this store.


getValueFormat

public final DataFormat getValueFormat()
Returns the value format associated with this store.


getIndices

public final Iterator getIndices()
Returns the indices associated with this store. Indices are associated with a store when they are constructed. All objects returned by the iterator will be of class DataIndex and may also be of class ForeignKeyIndex.

Returns:
an iterator of associated indices or null if there are none.

toString

public String toString()
Returns a printable string identifying the filename and datbase name of the store.

Overrides:
toString in class Object

Berkeley DB
version 4.2.52

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