import com.sleepycat.db.*;public DbEnv(String homeDir, String db_config, int flags) throws DbException; public DbEnv(); public void appinit(String homeDir, String db_config, int flags) throws DbException;
The DbEnv.appinit method provides a simple way to initialize and configure the Berkeley DB environment. It is not necessary that it be called, but it provides a structure for creating a consistent environment for processes using one or more of the features of Berkeley DB.
The db_home and db_config arguments to DbEnv.appinit are described in Berkeley DB File Naming.
The flags argument specifies the subsystems that are initialized and how the environment affects Berkeley DB file naming, among other things. The flags value is specified by logically OR'ing together one or more of the following values:
The DbEnv.appinit function returns successfully if DB_RECOVER is
specified and no log files exist, so it is necessary to ensure all
necessary log files are present before running recovery.
For further information, consult db_archive and db_recover.
The DbEnv.appinit function returns successfully if DB_RECOVER_FATAL
is specified and no log files exist, so it is necessary to ensure all
necessary log files are present before running recovery. For further
information, consult db_archive and db_recover.
Threading is assumed in the Java API, so no special flags are required,
and Berkeley DB functions will always behave as if the DB_THREAD flag was
specified.
The Berkeley DB environment is configured based on the dbenv argument. It is expected that applications will use a single DbEnv object as the argument to all of the subsystems in the Berkeley DB package. The fields of the DbEnv object used by DbEnv.appinit are described below. Any of the DbEnv fields that are not explicitly set will default to appropriate values.
The following fields in the DbEnv object may be initialized, using the appropriate set method, before calling DbEnv.appinit:
If db_paniccall is not null and such an error occurs,
db_paniccall.paniccall() will be called. This method takes two arguments.
The dbenv argument is the current environment's DbEnv
object, and the errval argument is the system errno value that
was returned when the error occurred.
If db_errcall is not null, db_errcall.errcall() may be called
with additional error information. This method takes two arguments. The
prefix argument is the current environment's db_errpfx
field. The buffer argument is a string with the additional
information.
This error logging facility does not slow performance or significantly
increase application size, and may be run during normal operation as
well as during debugging.
Each of the open functions that DbEnv.appinit may call (DbLockTab.open, DbLog.open, DbMpool.open and DbTxnMgr.open), is called as follows, where the DB_CREATE flag is optional:
XXX::open(null, Db.DB_CREATE, 0660, dbenv);
This call will cause each subsystem to construct pathnames as described in Berkeley DB File Naming. The subsystem has permission to read and write underlying files as necessary, and optionally to create files. (All created files will be created readable and writeable by the owner and the group. The group ownership of created files is based on the system and directory defaults, and is not further specified by Berkeley DB.)
In addition, the dbenv argument is passed to the open functions of any subsystems initialized by DbEnv.appinit. For this reason the fields of the DbEnv object relevant to the subsystems being initialized must themselves be initialized before DbEnv.appinit is called. See the appropriate subsystem documentation for a list of these fields and their uses.
The return value from each of these calls is placed in the appropriate field of the DbEnv object:
In general, these fields are not directly used by applications; subsystems of Berkeley DB that use these fields simply reference them using the DbEnv object passed to the subsystem.
For example, an application using the Berkeley DB hash access method functions to access a database will first call Db.open passing it the DbEnv argument initialized by a call to DbEnv.appinit. Then, all future calls to the hash access method functions for that database will automatically use the underlying shared memory buffer pool that was specified by the mp_info field of that DbEnv object.
The single exception to this rule is the tx_info field, which applications must explicitly specify to the DbTxnMgr.begin, DbTxnMgr.checkpoint and DbTxnMgr.close methods.
The error_model field of DbEnv allows the user to configure the way errors are treated in Berkeley DB, and may be changed at any time, including after the call to DbEnv.appinit. The error model is further described in DbException.
The db_prefix field of DbEnv allows the user to configure the error message prefix, and may be changed at any time, including after the call to DbEnv.appinit.
Otherwise, once the Berkeley DB environment has been initialized by a call to DbEnv.appinit, no fields should be modified.
On Windows/95, files that are opened by multiple processes do not share data correctly. To cause Berkeley DB to use the paging file to share memory among processes, use the DB_REGION_NAME flag of the db_value_set function. Obviously, you do not need to do this if only a single process will be accessing database files.
The DbEnv.appinit method throws an exception that encapsulates an errno on failure.
The DbEnv.appinit method may fail and throw an exception for any of the errors specified for the following Berkeley DB and C library functions: Db.close, abort(3), ctime(3), DbEnv.appexit, dbenv->tx_recover(3), fclose(3), fcntl(3), fflush(3), fgets(3), fopen(3), fprintf(3), free(3), getenv(3), getpid(3), getuid(3), isspace(3), DbLockTab.open, DbLockTab.unlink, DbLog.compare, DbLog.get, DbLog.open, DbLog.unlink, malloc(3), memcpy(3), DbMpool.open, DbMpool.unlink, memset(3), realloc(3), stat(3), strcat(3), strchr(3), strcmp(3), strcpy(3), strlen(3), time(3), DbTxnMgr.checkpoint, DbTxnMgr.open, DbTxnMgr.unlink, vfprintf(3), and vsnprintf(3).
In addition, the DbEnv.appinit method may fail and throw an exception encapsulating errno for the following conditions:
The DB_THREAD flag was specified and spinlocks are not implemented for this architecture.
The DB_HOME or TMPDIR environment variables were set but empty.
An incorrectly formatted NAME VALUE entry or line was found.