import com.sleepycat.db.*;
import java.io.FileNotFoundException;

public void open(String file, String database, int type, int flags, int mode) throws DbException, FileNotFoundException;


The currently supported Berkeley DB file formats (or access methods) are Btree, Hash, Queue, and Recno. The Btree format is a representation of a sorted, balanced tree structure. The Hash format is an extensible, dynamic hashing scheme. The Queue format supports fast access to fixed-length records accessed sequentially or by logical record number. The Recno format supports fixed- or variable-length records, accessed sequentially or by logical record number, and optionally backed by a flat text file.

Storage and retrieval for the Berkeley DB access methods are based on key/data pairs; see Dbt for more information.

The Db.open interface opens the database represented by the file and database arguments for both reading and writing. The file argument is used as the name of an underlying file that will be used to back the database. The database argument is optional, and allows applications to have multiple databases in a single file. Although no database argument needs to be specified, it is an error to attempt to open a second database in a file that was not initially created using a database name. Further, the database argument is not supported by the Queue format.

In-memory databases never intended to be preserved on disk may be created by setting both the file and database arguments to null. Note that in-memory databases can only ever be shared by sharing the single database handle that created them, in circumstances where doing so is safe.

The type argument is of type int, and must be set to one of Db.DB_BTREE, Db.DB_HASH, Db.DB_QUEUE, Db.DB_RECNO, or Db.DB_UNKNOWN. If type is Db.DB_UNKNOWN, the database must already exist and Db.open will automatically determine its type. The Db.get_type method may be used to determine the underlying type of databases opened using Db.DB_UNKNOWN.

The flags and mode arguments specify how files will be opened and/or created if they do not already exist.

The flags value must be set to 0 or by bitwise inclusively OR'ing together one or more of the following values:

Create any underlying files, as necessary. If the files do not already exist and the DB_CREATE flag is not specified, the call will fail.

Support dirty reads; that is, transactions, cursors and read operations in the database may request the return of modified but not yet committed data.

Return an error if the file already exists. Underlying filesystem primitives are used to implement this flag. For this reason, it is only applicable to the file and cannot be used to test whether a database in a file already exists.

The Db.DB_EXCL flag is only meaningful when specified with the Db.DB_CREATE flag.

Do not map this database into process memory (see the description of the DbEnv.set_mp_mmapsize method for further information).

Open the database for reading only. Any attempt to modify items in the database will fail, regardless of the actual permissions of any underlying files.

Cause the Db handle returned by Db.open to be free-threaded; that is, usable by multiple threads within a single address space.

Threading is always assumed in the Java API, so no special flags are required, and Berkeley DB functions will always behave as if the Db.DB_THREAD flag was specified.

Physically truncate the underlying file, discarding all previous databases it might have held. Underlying filesystem primitives are used to implement this flag. For this reason, it is applicable only to the file and cannot be used to discard databases within a file.

The Db.DB_TRUNCATE flag cannot be transaction-protected, and it is an error to specify it in a transaction-protected environment.

On UNIX systems or in IEEE/ANSI Std 1003.1 (POSIX) environments, all files created by the access methods are created with mode mode (as described in chmod(2)) and modified by the process' umask value at the time of creation (see umask(2)). If mode is 0, the access methods will use a default mode of readable and writable by both owner and group. On Windows systems, the mode argument is ignored. The group ownership of created files is based on the system and directory defaults, and is not further specified by Berkeley DB.

Calling Db.open is a reasonably expensive operation, and maintaining a set of open databases will normally be preferable to repeatedly opening and closing the database for each new query.

The Db.open method throws an exception that encapsulates a non-zero error value on failure.

Environment Variables

If the dbenv argument to db_create was initialized using DbEnv.open, the environment variable DB_HOME may be used as the path of the database environment home. Specifically, Db.open is affected by the configuration value DB_DATA_DIR.

If the file and dbenv arguments to Db.open are null, the environment variable TMPDIR may be used as a directory in which to create a temporary backing file.


The Db.open method may fail and throw an exception encapsulating a non-zero error for the following conditions:

The database cannot be opened without being first upgraded.

DB_CREATE and DB_EXCL were specified and the file exists.

An invalid flag value or parameter was specified (for example, unknown database type, page size, hash function, pad byte, byte order) or a flag value or parameter that is incompatible with the specified database.

The Db.DB_THREAD flag was specified and fast mutexes are not available for this architecture.

The Db.DB_THREAD flag was specified to Db.open, but was not specified to the DbEnv.open call for the environment in which the Db handle was created.

A backing flat text file was specified with either the Db.DB_THREAD flag or the provided database environment supports transaction processing.

A nonexistent re_source file was specified.

The Db.open method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the Db.open method may fail and throw a DbRunRecoveryException, in which case all subsequent Berkeley DB calls will fail in the same way.



See Also

Db.associate, Db.close, Db.cursor, Db.del, Db.fd, Db.get, Db.pget, Db.get_byteswapped, Db.get_type, Db.join, Db.key_range, Db.open, Db.put, Db.remove, Db.rename, Db.set_append_recno, Db.set_bt_minkey, Db.set_cachesize, Db.set_errcall, Db.set_errpfx, Db.set_feedback, Db.set_flags, Db.set_h_ffactor, Db.set_h_nelem, Db.set_lorder, Db.set_pagesize, Db.set_q_extentsize, Db.set_re_delim, Db.set_re_len, Db.set_re_pad, Db.set_re_source, Db.stat, Db.sync, Db.truncate, Db.upgrade, and Db.verify.


Copyright Sleepycat Software