The DbEnv.open method opens a Berkeley DB environment. It provides a structure for creating a consistent environment for processes using one or more of the features of Berkeley DB.
|db_home ||the database environment's home directory. For more information on db_home , and filename resolution in general, see Berkeley DB File Naming . The environment variable DB_HOME may be used as the path of the database home, as described in Berkeley DB File Naming . |
|flags ||specifies the subsystems that are initialized and how the application's environment affects Berkeley DB file naming, among other things. The flags parameter must be set to 0 or by bitwise inclusively OR 'ing together one or more of the following values: |
Because there are a large number of flags that can be specified, they have been grouped together by functionality. The first group of flags indicates which of the Berkeley DB subsystems should be initialized:
Initialize the locking subsystem. This subsystem should be used when multiple processes or threads are going to be reading and writing a Berkeley DB database, so that they do not interfere with each other. If all threads are accessing the database(s) read-only, locking is unnecessary. When the
Db.DB_INIT_LOCK flag is specified, it is usually necessary to run a deadlock detector, as well. See db_deadlock and DbEnv.lockDetect for more information.
Initialize the logging subsystem. This subsystem should be used when recovery from application or system failure is necessary. If the log region is being created and log files are already present, the log files are reviewed; subsequent log writes are appended to the end of the log, rather than overwriting current log entries.
The second group of flags govern what recovery, if any, is performed when the environment is initialized:
A standard part of the recovery process is to remove the existing Berkeley DB environment and create a new one in which to perform recovery. If the thread of control performing recovery does not specify the correct region initialization information (for example, the correct memory pool cache size), the result can be an application running in an environment with incorrect cache and other subsystem sizes. For this reason, the thread of control performing recovery should specify correct configuration information before calling the DbEnv.open
method; or it should remove the environment after recovery is completed, leaving creation of the correctly sized environment to a subsequent call to DbEnv.open
All Berkeley DB recovery processing must be single-threaded; that is, only a single thread of control may perform recovery or access a Berkeley DB environment while recovery is being performed. Because it is not an error to specify Db.DB_RECOVER for an environment for which no recovery is required, it is reasonable programming practice for the thread of control responsible for performing recovery and creating the environment to always specify the Db.DB_CREATE and Db.DB_RECOVER flags during startup.
The DbEnv.open function returns successfully if Db.DB_RECOVER or Db.DB_RECOVER_FATAL is specified and no log files exist, so it is necessary to ensure that all necessary log files are present before running recovery. For further information, consult db_archive and db_recover .
The third group of flags govern file-naming extensions in the environment:
The Berkeley DB process' environment may be permitted to specify information to be used when naming files; see Berkeley DB File Naming . Because permitting users to specify which files are used can create security problems, environment information will be used in file naming for all users only if the
Db.DB_USE_ENVIRON flag is set.
The Berkeley DB process' environment may be permitted to specify information to be used when naming files; see Berkeley DB File Naming . Because permitting users to specify which files are used can create security problems, if the
Db.DB_USE_ENVIRON_ROOT flag is set, environment information will be used for file naming only for users with appropriate permissions (for example, users with a user-ID of 0 on UNIX systems).
Finally, there are a few additional unrelated flags:
Specify that the environment will only be accessed by a single process (although that process may be multithreaded). This flag has two effects on the Berkeley DB environment. First, all underlying data structures are allocated from per-process memory instead of from shared memory that is potentially accessible to more than a single process. Second, mutexes are only configured to work between threads.
This flag should not be specified if more than a single process is accessing the environment because it is likely to cause database corruption and unpredictable behavior. For example, if both a server application and the Berkeley DB utility db_stat are expected to access the environment, the
Db.DB_PRIVATE flag should not be specified.
Cause the DbEnv handle returned by DbEnv.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.
|mode ||On UNIX systems or in IEEE/ANSI Std 1003.1 (POSIX) environments, all files created by Berkeley DB 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, Berkeley DB will use a default mode of readable and writable by both owner and group. On Windows systems, the mode parameter is ignored. The group ownership of created files is based on the system and directory defaults, and is not further specified by Berkeley DB. |
|DbException ||The DbEnv.open method may fail and throw DbException, encapsulating one of the following non-zero errors: The shared memory region was locked and (repeatedly) unavailable. HP-UX only: a previously created Berkeley DB environment for this process still exists. |
|IllegalArgumentException ||The DbEnv.open method will fail and throw a IllegalArgumentException exception if the Db.DB_THREAD flag was specified and fast mutexes are not available for this architecture; The DB_HOME or TMPDIR environment variables were set, but empty; An incorrectly formatted NAME VALUE entry or line was found; or if an invalid flag value or parameter was specified. |
|FileNotFoundException ||If the file or directory does not exist, the DbEnv.open method will fail and throw a FileNotFoundException exception. |
Definition at line 696 of file DbEnv.java.
Referenced by com::sleepycat::examples::bdb::helloworld::HelloDatabaseWorld::main(), com::sleepycat::examples::bdb::access::AccessExample::main(), com::sleepycat::examples::bdb::shipment::tuple::SampleDatabase::SampleDatabase(), com::sleepycat::examples::bdb::shipment::sentity::SampleDatabase::SampleDatabase(), com::sleepycat::examples::bdb::shipment::marshal::SampleDatabase::SampleDatabase(), com::sleepycat::examples::bdb::shipment::index::SampleDatabase::SampleDatabase(), com::sleepycat::examples::bdb::shipment::factory::SampleDatabase::SampleDatabase(), com::sleepycat::examples::bdb::shipment::entity::SampleDatabase::SampleDatabase(), and com::sleepycat::examples::bdb::shipment::basic::SampleDatabase::SampleDatabase().
flags |= Db.DB_THREAD;
open0(db_home, flags, mode);