summaryrefslogtreecommitdiff
path: root/db/java
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2001-03-21 18:33:35 +0000
committerjbj <devnull@localhost>2001-03-21 18:33:35 +0000
commit731946f4b90eb1173452dd30f1296dd825155d82 (patch)
tree67535f54ecb7e5463c06e62044e4efd84ae0291d /db/java
parent7ed904da030dc4640ff9bce8458ba07cc09d830d (diff)
downloadlibrpm-tizen-731946f4b90eb1173452dd30f1296dd825155d82.tar.gz
librpm-tizen-731946f4b90eb1173452dd30f1296dd825155d82.tar.bz2
librpm-tizen-731946f4b90eb1173452dd30f1296dd825155d82.zip
Initial revision
CVS patchset: 4644 CVS date: 2001/03/21 18:33:35
Diffstat (limited to 'db/java')
-rw-r--r--db/java/src/com/sleepycat/db/Db.java710
-rw-r--r--db/java/src/com/sleepycat/db/DbAppendRecno.java22
-rw-r--r--db/java/src/com/sleepycat/db/DbBtreeCompare.java21
-rw-r--r--db/java/src/com/sleepycat/db/DbBtreePrefix.java21
-rw-r--r--db/java/src/com/sleepycat/db/DbBtreeStat.java40
-rw-r--r--db/java/src/com/sleepycat/db/DbConstants.java217
-rw-r--r--db/java/src/com/sleepycat/db/DbDeadlockException.java28
-rw-r--r--db/java/src/com/sleepycat/db/DbDupCompare.java21
-rw-r--r--db/java/src/com/sleepycat/db/DbEnv.java392
-rw-r--r--db/java/src/com/sleepycat/db/DbEnvFeedback.java19
-rw-r--r--db/java/src/com/sleepycat/db/DbErrcall.java23
-rw-r--r--db/java/src/com/sleepycat/db/DbException.java56
-rw-r--r--db/java/src/com/sleepycat/db/DbFeedback.java23
-rw-r--r--db/java/src/com/sleepycat/db/DbHash.java21
-rw-r--r--db/java/src/com/sleepycat/db/DbHashStat.java37
-rw-r--r--db/java/src/com/sleepycat/db/DbKeyRange.java23
-rw-r--r--db/java/src/com/sleepycat/db/DbLock.java38
-rw-r--r--db/java/src/com/sleepycat/db/DbLockStat.java30
-rw-r--r--db/java/src/com/sleepycat/db/DbLogStat.java35
-rw-r--r--db/java/src/com/sleepycat/db/DbLsn.java42
-rw-r--r--db/java/src/com/sleepycat/db/DbMemoryException.java28
-rw-r--r--db/java/src/com/sleepycat/db/DbMpoolFStat.java28
-rw-r--r--db/java/src/com/sleepycat/db/DbMpoolStat.java42
-rw-r--r--db/java/src/com/sleepycat/db/DbOutputStreamErrcall.java58
-rw-r--r--db/java/src/com/sleepycat/db/DbQueueStat.java32
-rw-r--r--db/java/src/com/sleepycat/db/DbRecoveryInit.java23
-rw-r--r--db/java/src/com/sleepycat/db/DbRunRecoveryException.java32
-rw-r--r--db/java/src/com/sleepycat/db/DbTxn.java47
-rw-r--r--db/java/src/com/sleepycat/db/DbTxnRecover.java22
-rw-r--r--db/java/src/com/sleepycat/db/DbTxnStat.java40
-rw-r--r--db/java/src/com/sleepycat/db/Dbc.java56
-rw-r--r--db/java/src/com/sleepycat/db/Dbt.java110
-rw-r--r--db/java/src/com/sleepycat/examples/AccessExample.java186
-rw-r--r--db/java/src/com/sleepycat/examples/BtRecExample.java348
-rw-r--r--db/java/src/com/sleepycat/examples/EnvExample.java128
-rw-r--r--db/java/src/com/sleepycat/examples/LockExample.java235
-rw-r--r--db/java/src/com/sleepycat/examples/TpcbExample.java831
37 files changed, 4065 insertions, 0 deletions
diff --git a/db/java/src/com/sleepycat/db/Db.java b/db/java/src/com/sleepycat/db/Db.java
new file mode 100644
index 000000000..de11e2841
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/Db.java
@@ -0,0 +1,710 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: Db.java,v 11.38 2000/12/31 19:26:22 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+import java.io.OutputStream;
+import java.io.FileNotFoundException;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class Db
+{
+ // All constant and flag values used with Db* classes are defined here.
+
+ // Collectively, these constants are known by the name
+ // "DBTYPE" in the documentation.
+ //
+ public static final int DB_BTREE = 1; // B+tree
+ public static final int DB_HASH = 2; // Extended Linear Hashing.
+ public static final int DB_RECNO = 3; // Fixed and variable-length records.
+ public static final int DB_QUEUE = 4; // Queue
+ public static final int DB_UNKNOWN = 5; // Figure it out on open.
+
+ // Flags understood by DbEnv()
+ //
+ // Note: DB_CXX_NO_EXCEPTIONS will have no effect in Java.
+ //
+ public static final int DB_CXX_NO_EXCEPTIONS; // C++: return error values
+ public static final int DB_CLIENT; // Open for a client environment.
+
+ // Flags understood by Db()
+ //
+ public static final int DB_XA_CREATE; // Open in an XA environment.
+
+ // Flags understood by Db.open(), DbEnv.open().
+ //
+ public static final int DB_CREATE; // O_CREAT: create file as necessary.
+ public static final int DB_NOMMAP; // Don't mmap underlying file.
+ public static final int DB_THREAD; // Free-thread DB package handles.
+
+ // Flags understood by only DbEnv.open().
+ //
+ public static final int DB_LOCKDOWN; // Lock memory into physical core.
+ public static final int DB_PRIVATE; // DB_ENV is process local.
+
+ //
+ // Flags understood by DbEnv.txn_begin().
+ //
+ public static final int DB_TXN_NOWAIT; // Do not wait for locks in this TXN.
+ public static final int DB_TXN_SYNC; // Always sync log on commit.
+
+ // Flags understood by DbEnv.set_flags().
+ //
+ public static final int DB_CDB_ALLDB; // In CDB, lock across environment.
+
+ //
+ // Flags understood by Db.open().
+ //
+ public static final int DB_EXCL; // Exclusive open (O_EXCL).
+ public static final int DB_RDONLY; // Read-only (O_RDONLY).
+ public static final int DB_TRUNCATE; // Discard existing DB.
+ public static final int DB_UPGRADE; // Upgrade if necessary.
+
+ //
+ // DB (user visible) error return codes.
+ //
+ public static final int DB_INCOMPLETE = -30999; // Sync didn't finish.
+ public static final int DB_KEYEMPTY = -30998; // The key/data pair was deleted or
+ // was never created by the user.
+ public static final int DB_KEYEXIST = -30997; // The key/data pair already exists.
+ public static final int DB_LOCK_DEADLOCK = -30996; // Locker killed to resolve deadlock.
+ public static final int DB_LOCK_NOTGRANTED = -30995; // Lock unavailable, no-wait set.
+ public static final int DB_NOSERVER = -30994; // Server panic return.
+ public static final int DB_NOSERVER_HOME = -30993; // Bad home sent to server.
+ public static final int DB_NOSERVER_ID = -30992; // Bad ID sent to server.
+ public static final int DB_NOTFOUND = -30991; // Key/data pair not found (EOF).
+ public static final int DB_OLD_VERSION = -30990; // Out-of-date version.
+ public static final int DB_RUNRECOVERY = -30989; // Panic return.
+ public static final int DB_VERIFY_BAD = -30988; // Verify failed; bad format.
+
+ //
+ // Flags used by DbEnv.open and DbEnv.remove.
+ //
+ public static final int DB_FORCE; // Force (anything).
+ public static final int DB_INIT_CDB; // Concurrent Access Methods.
+ public static final int DB_INIT_LOCK; // Initialize locking.
+ public static final int DB_INIT_LOG; // Initialize logging.
+ public static final int DB_INIT_MPOOL; // Initialize mpool.
+ public static final int DB_INIT_TXN; // Initialize transactions.
+ public static final int DB_JOINENV; // Initialize all subsystems present.
+ public static final int DB_RECOVER; // Run normal recovery.
+ public static final int DB_RECOVER_FATAL; // Run catastrophic recovery.
+ public static final int DB_SYSTEM_MEM; // Use system-backed memory.
+ public static final int DB_TXN_NOSYNC; // Do not sync log on commit.
+ public static final int DB_USE_ENVIRON; // Use the environment.
+ public static final int DB_USE_ENVIRON_ROOT; // Use the environment if root.
+
+ //
+ // Operations values to the tx_recover() function.
+ //
+ public static final int DB_TXN_BACKWARD_ROLL = 1;
+ public static final int DB_TXN_FORWARD_ROLL = 2;
+ public static final int DB_TXN_OPENFILES = 3;
+ public static final int DB_TXN_REDO = 4;
+ public static final int DB_TXN_UNDO = 5;
+
+ //
+ // Verbose flags; used for DbEnv.set_verbose
+ //
+ public static final int DB_VERB_CHKPOINT; // List checkpoints.
+ public static final int DB_VERB_DEADLOCK; // Deadlock detection information.
+ public static final int DB_VERB_RECOVERY; // Recovery information.
+ public static final int DB_VERB_WAITSFOR; // Dump waits-for table.
+
+ //
+ // Deadlock detector modes; used in the DBENV structure to configure the
+ // locking subsystem.
+ //
+ public static final int DB_LOCK_NORUN;
+ public static final int DB_LOCK_DEFAULT;
+ public static final int DB_LOCK_OLDEST;
+ public static final int DB_LOCK_RANDOM;
+ public static final int DB_LOCK_YOUNGEST;
+
+ //
+ // Flags understood by only Db.set_flags.
+ //
+ public static final int DB_DUP; // Btree, Hash: duplicate keys.
+ public static final int DB_DUPSORT; // Btree, Hash: duplicate keys.
+ public static final int DB_RECNUM; // Btree: record numbers.
+ public static final int DB_RENUMBER; // Recno: renumber on insert/delete.
+ public static final int DB_REVSPLITOFF;// Btree: turn off reverse splits.
+ public static final int DB_SNAPSHOT; // Recno: snapshot the input.
+
+ //
+ // Flags understood by only Db.join
+ //
+ public static final int DB_JOIN_NOSORT;// Don't try to optimize join.
+
+ //
+ // Flags understood by only Db.verify
+ //
+ public static final int DB_NOORDERCHK; // Skip order check; subdb w/ user func
+ public static final int DB_ORDERCHKONLY;// Only perform an order check on subdb
+ public static final int DB_SALVAGE; // Salvage what looks like data.
+ public static final int DB_AGGRESSIVE; // Salvage anything which might be data.
+
+ // Collectively, these constants are known by the name
+ // "db_lockmode_t" in the documentation.
+ //
+ public static final int DB_LOCK_NG = 0; // Not granted.
+ public static final int DB_LOCK_READ = 1; // Shared/read.
+ public static final int DB_LOCK_WRITE = 2; // Exclusive/write.
+ public static final int DB_LOCK_IWRITE = 3; // Intent exclusive/write.
+ public static final int DB_LOCK_IREAD = 4; // Intent to share/read.
+ public static final int DB_LOCK_IWR = 5; // Intent to read and write.
+
+ // Collectively, these constants are known by the name
+ // "db_lockop_t" in the documentation.
+ //
+ public static final int DB_LOCK_DUMP = 0; // Display held locks.
+ public static final int DB_LOCK_GET = 1; // Get the lock.
+ /* Not visible to API: DB_LOCK_INHERIT = 2 // Pass locks to parent. */
+ public static final int DB_LOCK_PUT = 3; // Release the lock.
+ public static final int DB_LOCK_PUT_ALL = 4;// Release locker's locks.
+ public static final int DB_LOCK_PUT_OBJ = 5;// Release locker's locks on obj.
+
+ // Flag values for DbLock.vec()
+ public static final int DB_LOCK_NOWAIT; // Don't wait on unavailable lock.
+
+ // Flag values for DbLock.detect()
+ public static final int DB_LOCK_CONFLICT; // Run on any conflict.
+
+ //
+ // Flag values for DbLog.archive()
+ //
+ public static final int DB_ARCH_ABS; // Absolute pathnames.
+ public static final int DB_ARCH_DATA; // Data files.
+ public static final int DB_ARCH_LOG; // Log files.
+
+ //
+ // DB access method and cursor operation values.
+ // Each value is an operation code to which
+ // additional bit flags are added.
+ //
+ public static final int DB_AFTER; // Dbc.put()
+ public static final int DB_APPEND; // Db.put()
+ public static final int DB_BEFORE; // Dbc.put()
+ public static final int DB_CACHED_COUNTS; // Db.stat()
+ public static final int DB_CHECKPOINT; // DbLog.put(), DbLog.get()
+ public static final int DB_CONSUME; // Db.get()
+ public static final int DB_CONSUME_WAIT; // Db.get()
+ public static final int DB_CURLSN; // DbLog.put()
+ public static final int DB_CURRENT; // Dbc.get(), Dbc.put(), DbLog.get()
+ public static final int DB_FIRST; // Dbc.get(), DbLog.get()
+ public static final int DB_FLUSH; // DbLog.put()
+ public static final int DB_GET_BOTH; // Db.get(), Dbc.get()
+ public static final int DB_GET_RECNO; // Dbc.get()
+ public static final int DB_JOIN_ITEM; // Dbc.get()
+ public static final int DB_KEYFIRST; // Dbc.put()
+ public static final int DB_KEYLAST; // Dbc.put()
+ public static final int DB_LAST; // Dbc.get(), DbLog.get()
+ public static final int DB_NEXT; // Dbc.get(), DbLog.get()
+ public static final int DB_NEXT_DUP; // Dbc.get()
+ public static final int DB_NEXT_NODUP; // Dbc.get()
+ public static final int DB_NODUPDATA; // Don't permit duplicated data
+ public static final int DB_NOOVERWRITE;// Db.put()
+ public static final int DB_NOSYNC; // Db.close()
+ public static final int DB_POSITION; // Dbc.dup()
+ public static final int DB_PREV; // Dbc.get(), DbLog.get()
+ public static final int DB_PREV_NODUP; // Dbc.get()
+ public static final int DB_RECORDCOUNT;// Db.stat()
+ public static final int DB_SET; // Dbc.get(), DbLog.get()
+ public static final int DB_SET_RANGE; // Dbc.get()
+ public static final int DB_SET_RECNO; // Dbc.get()
+ public static final int DB_WRITECURSOR;// Db.cursor()
+
+ // Other flags that can be added to an operation codes above.
+ //
+ public static final int DB_RMW; // Acquire write flag immediately.
+
+ // Collectively, these values are used for Dbt flags
+ //
+ // Return in allocated memory.
+ public static final int DB_DBT_MALLOC;
+
+ // Partial put/get.
+ public static final int DB_DBT_PARTIAL;
+
+ // Return in realloc'd memory.
+ public static final int DB_DBT_REALLOC;
+
+ // Return in user's memory.
+ public static final int DB_DBT_USERMEM;
+
+ // Note: the env can be null
+ //
+ public Db(DbEnv env, int flags)
+ throws DbException
+ {
+ constructor_env_ = env;
+ _init(env, flags);
+ if (env == null) {
+ dbenv_ = new DbEnv(this);
+ }
+ else {
+ dbenv_ = env;
+ }
+ dbenv_._add_db(this);
+ }
+
+ //
+ // Our parent DbEnv is notifying us that the environment is closing.
+ //
+ /*package*/ void _notify_dbenv_close()
+ {
+ dbenv_ = null;
+ _notify_internal();
+ }
+
+ private native void _init(DbEnv env, int flags)
+ throws DbException;
+
+ private native void _notify_internal();
+
+ // methods
+ //
+
+ public synchronized int close(int flags)
+ throws DbException
+ {
+ int err;
+
+ dbenv_._remove_db(this);
+ err = _close(flags);
+ if (constructor_env_ == null) {
+ dbenv_._notify_db_close();
+ }
+ return err;
+ }
+
+ public native int _close(int flags)
+ throws DbException;
+
+ public native Dbc cursor(DbTxn txnid, int flags)
+ throws DbException;
+
+ public native int del(DbTxn txnid, Dbt key, int flags)
+ throws DbException;
+
+ public native void err(int errcode, String message);
+
+ public native void errx(String message);
+
+ public native int fd()
+ throws DbException;
+
+ // overrides Object.finalize
+ protected void finalize()
+ throws Throwable
+ {
+ _finalize(dbenv_.errcall_, dbenv_.errpfx_);
+ }
+
+ protected native void _finalize(DbErrcall errcall, String errpfx)
+ throws Throwable;
+
+ // returns: 0, DB_NOTFOUND, or throws error
+ public native int get(DbTxn txnid, Dbt key, Dbt data, int flags)
+ throws DbException;
+
+ public native boolean get_byteswapped();
+
+ public native /*DBTYPE*/ int get_type();
+
+ public native Dbc join(Dbc curslist[], int flags)
+ throws DbException;
+
+ public native void key_range(DbTxn txn, Dbt key,
+ DbKeyRange range, int flags)
+ throws DbException;
+
+ public synchronized void open(String file, String database,
+ /*DBTYPE*/ int type,
+ int flags, int mode)
+ throws DbException, FileNotFoundException
+ {
+ _open(file, database, type, flags, mode);
+ }
+
+ // (Internal)
+ public native void _open(String file, String database,
+ /*DBTYPE*/ int type,
+ int flags, int mode)
+ throws DbException, FileNotFoundException;
+
+
+ // returns: 0, DB_KEYEXIST, or throws error
+ public native int put(DbTxn txnid, Dbt key, Dbt data, int flags)
+ throws DbException;
+
+ public synchronized native void rename(String file, String database,
+ String newname, int flags)
+ throws DbException, FileNotFoundException;
+
+ public synchronized native void remove(String file, String database,
+ int flags)
+ throws DbException, FileNotFoundException;
+
+ // Comparison function.
+ public void set_append_recno(DbAppendRecno append_recno)
+ throws DbException
+ {
+ append_recno_ = append_recno;
+ append_recno_changed(append_recno);
+ }
+
+ // (Internal)
+ private native void append_recno_changed(DbAppendRecno append_recno)
+ throws DbException;
+
+ // Comparison function.
+ public void set_bt_compare(DbBtreeCompare bt_compare)
+ throws DbException
+ {
+ bt_compare_ = bt_compare;
+ bt_compare_changed(bt_compare);
+ }
+
+ // (Internal)
+ private native void bt_compare_changed(DbBtreeCompare bt_compare)
+ throws DbException;
+
+ // Maximum keys per page.
+ public native void set_bt_maxkey(int maxkey)
+ throws DbException;
+
+ // Minimum keys per page.
+ public native void set_bt_minkey(int minkey)
+ throws DbException;
+
+ // Prefix function.
+ public void set_bt_prefix(DbBtreePrefix bt_prefix)
+ throws DbException
+ {
+ bt_prefix_ = bt_prefix;
+ bt_prefix_changed(bt_prefix);
+ }
+
+ // (Internal)
+ private native void bt_prefix_changed(DbBtreePrefix bt_prefix)
+ throws DbException;
+
+ // Set cache size
+ public native void set_cachesize(int gbytes, int bytes, int ncaches)
+ throws DbException;
+
+ // Duplication resolution
+ public void set_dup_compare(DbDupCompare dup_compare)
+ throws DbException
+ {
+ dup_compare_ = dup_compare;
+ dup_compare_changed(dup_compare);
+ }
+
+ // (Internal)
+ private native void dup_compare_changed(DbDupCompare dup_compare)
+ throws DbException;
+
+ // Error message callback.
+ public void set_errcall(DbErrcall errcall)
+ {
+ if (dbenv_ != null)
+ dbenv_.set_errcall(errcall);
+ }
+
+ // Error stream.
+ public void set_error_stream(OutputStream s)
+ {
+ DbOutputStreamErrcall errcall = new DbOutputStreamErrcall(s);
+ set_errcall(errcall);
+ }
+
+ // Error message prefix.
+ public void set_errpfx(String errpfx)
+ {
+ if (dbenv_ != null)
+ dbenv_.set_errpfx(errpfx);
+ }
+
+
+ // Feedback
+ public void set_feedback(DbFeedback feedback)
+ throws DbException
+ {
+ feedback_ = feedback;
+ feedback_changed(feedback);
+ }
+
+ // (Internal)
+ private native void feedback_changed(DbFeedback feedback)
+ throws DbException;
+
+ // Flags.
+ public native void set_flags(/*u_int32_t*/ int flags);
+
+ // Fill factor.
+ public native void set_h_ffactor(/*unsigned*/ int h_ffactor);
+
+ // Hash function.
+ public void set_h_hash(DbHash h_hash)
+ throws DbException
+ {
+ h_hash_ = h_hash;
+ hash_changed(h_hash);
+ }
+
+ // (Internal)
+ private native void hash_changed(DbHash hash)
+ throws DbException;
+
+ // Number of elements.
+ public native void set_h_nelem(/*unsigned*/ int h_nelem);
+
+ // Byte order.
+ public native void set_lorder(int lorder);
+
+ // Underlying page size.
+ public native void set_pagesize(/*size_t*/ long pagesize);
+
+ // Variable-length delimiting byte.
+ public native void set_re_delim(int re_delim);
+
+ // Length for fixed-length records.
+ public native void set_re_len(/*u_int32_t*/ int re_len);
+
+ // Fixed-length padding byte.
+ public native void set_re_pad(int re_pad);
+
+ // Source file name.
+ public native void set_re_source(String re_source);
+
+ // Extent size of Queue
+ public native void set_q_extentsize(/*u_int32_t*/ int extent_size);
+
+ // returns a DbBtreeStat or DbHashStat
+ public native Object stat(int flags)
+ throws DbException;
+
+ public native int sync(int flags)
+ throws DbException;
+
+ public native void upgrade(String name, int flags)
+ throws DbException;
+
+ public native void verify(String name, String subdb,
+ OutputStream outstr, int flags)
+ throws DbException;
+
+ ////////////////////////////////////////////////////////////////
+ //
+ // private data
+ //
+ private long private_dbobj_ = 0;
+ private long private_info_ = 0;
+ private DbEnv dbenv_ = null;
+ private DbEnv constructor_env_ = null;
+ private DbFeedback feedback_ = null;
+ private DbAppendRecno append_recno_ = null;
+ private DbBtreeCompare bt_compare_ = null;
+ private DbBtreePrefix bt_prefix_ = null;
+ private DbDupCompare dup_compare_ = null;
+ private DbHash h_hash_ = null;
+
+ ////////////////////////////////////////////////////////////////
+ //
+ // static methods and data that implement
+ // loading the native library and doing any
+ // extra sanity checks on startup.
+ //
+ private static boolean already_loaded_ = false;
+
+ public static void load_db()
+ {
+ if (already_loaded_)
+ return;
+
+ // An alternate library name can be specified via a property.
+ //
+ String overrideLibname = System.getProperty("sleepycat.db.libname");
+ if (overrideLibname != null) {
+ System.loadLibrary(overrideLibname);
+ }
+ else {
+ String os = System.getProperty("os.name");
+ if (os != null && os.startsWith("Windows")) {
+ // library name is "libdb_java30.dll" (for example) on Win/*
+ System.loadLibrary("libdb_java" +
+ DbConstants.DB_VERSION_MAJOR +
+ DbConstants.DB_VERSION_MINOR);
+ }
+ else {
+ // library name is "libdb_java-3.0.so" (for example) on UNIX
+ // Note: "db_java" isn't good enough;
+ // some Unixes require us to use the explicit SONAME.
+ System.loadLibrary("db_java-" +
+ DbConstants.DB_VERSION_MAJOR + "." +
+ DbConstants.DB_VERSION_MINOR);
+ }
+ }
+
+ already_loaded_ = true;
+ }
+
+ static private native void one_time_init();
+
+ static private void check_constant(int c1, int c2)
+ {
+ if (c1 != c2) {
+ System.err.println("Db: constant mismatch");
+ System.exit(1);
+ }
+ }
+
+ static {
+ Db.load_db();
+
+ // Note: constant values are stored in DbConstants, which
+ // is automatically generated. Initializing constants in
+ // static code insulates users from the possibility of
+ // changing constants.
+ //
+ DB_CXX_NO_EXCEPTIONS = DbConstants.DB_CXX_NO_EXCEPTIONS;
+ DB_CLIENT = DbConstants.DB_CLIENT;
+ DB_XA_CREATE = DbConstants.DB_XA_CREATE;
+
+ DB_CREATE = DbConstants.DB_CREATE;
+ DB_NOMMAP = DbConstants.DB_NOMMAP;
+ DB_THREAD = DbConstants.DB_THREAD;
+
+ DB_LOCKDOWN = DbConstants.DB_LOCKDOWN;
+ DB_PRIVATE = DbConstants.DB_PRIVATE;
+ DB_TXN_NOWAIT = DbConstants.DB_TXN_NOWAIT;
+ DB_TXN_SYNC = DbConstants.DB_TXN_SYNC;
+ DB_CDB_ALLDB = DbConstants.DB_CDB_ALLDB;
+
+ DB_EXCL = DbConstants.DB_EXCL;
+ DB_RDONLY = DbConstants.DB_RDONLY;
+ DB_TRUNCATE = DbConstants.DB_TRUNCATE;
+ DB_UPGRADE = DbConstants.DB_UPGRADE;
+
+ // These constants are not assigned, but rather checked.
+ // Having initialized constants for these values allows
+ // them to be used as case values in switch statements.
+ //
+ check_constant(DB_INCOMPLETE, DbConstants.DB_INCOMPLETE);
+ check_constant(DB_KEYEMPTY, DbConstants.DB_KEYEMPTY);
+ check_constant(DB_KEYEXIST, DbConstants.DB_KEYEXIST);
+ check_constant(DB_LOCK_DEADLOCK, DbConstants.DB_LOCK_DEADLOCK);
+ check_constant(DB_LOCK_NOTGRANTED, DbConstants.DB_LOCK_NOTGRANTED);
+ check_constant(DB_NOSERVER, DbConstants.DB_NOSERVER);
+ check_constant(DB_NOSERVER_HOME, DbConstants.DB_NOSERVER_HOME);
+ check_constant(DB_NOSERVER_ID, DbConstants.DB_NOSERVER_ID);
+ check_constant(DB_NOTFOUND, DbConstants.DB_NOTFOUND);
+ check_constant(DB_OLD_VERSION, DbConstants.DB_OLD_VERSION);
+ check_constant(DB_RUNRECOVERY, DbConstants.DB_RUNRECOVERY);
+ check_constant(DB_VERIFY_BAD, DbConstants.DB_VERIFY_BAD);
+ check_constant(DB_TXN_BACKWARD_ROLL, DbConstants.DB_TXN_BACKWARD_ROLL);
+ check_constant(DB_TXN_FORWARD_ROLL, DbConstants.DB_TXN_FORWARD_ROLL);
+ check_constant(DB_TXN_OPENFILES, DbConstants.DB_TXN_OPENFILES);
+ check_constant(DB_TXN_REDO, DbConstants.DB_TXN_REDO);
+ check_constant(DB_TXN_UNDO, DbConstants.DB_TXN_UNDO);
+
+ DB_FORCE = DbConstants.DB_FORCE;
+ DB_INIT_CDB = DbConstants.DB_INIT_CDB;
+ DB_INIT_LOCK = DbConstants.DB_INIT_LOCK;
+ DB_INIT_LOG = DbConstants.DB_INIT_LOG;
+ DB_INIT_MPOOL = DbConstants.DB_INIT_MPOOL;
+ DB_INIT_TXN = DbConstants.DB_INIT_TXN;
+ DB_JOINENV = DbConstants.DB_JOINENV;
+ DB_RECOVER = DbConstants.DB_RECOVER;
+ DB_RECOVER_FATAL = DbConstants.DB_RECOVER_FATAL;
+ DB_SYSTEM_MEM = DbConstants.DB_SYSTEM_MEM;
+ DB_TXN_NOSYNC = DbConstants.DB_TXN_NOSYNC;
+ DB_USE_ENVIRON = DbConstants.DB_USE_ENVIRON;
+ DB_USE_ENVIRON_ROOT = DbConstants.DB_USE_ENVIRON_ROOT;
+
+ DB_VERB_CHKPOINT = DbConstants.DB_VERB_CHKPOINT;
+ DB_VERB_DEADLOCK = DbConstants.DB_VERB_DEADLOCK;
+ DB_VERB_RECOVERY = DbConstants.DB_VERB_RECOVERY;
+ DB_VERB_WAITSFOR = DbConstants.DB_VERB_WAITSFOR;
+
+ DB_LOCK_NORUN = DbConstants.DB_LOCK_NORUN;
+ DB_LOCK_DEFAULT = DbConstants.DB_LOCK_DEFAULT;
+ DB_LOCK_OLDEST = DbConstants.DB_LOCK_OLDEST;
+ DB_LOCK_RANDOM = DbConstants.DB_LOCK_RANDOM;
+ DB_LOCK_YOUNGEST = DbConstants.DB_LOCK_YOUNGEST;
+
+ DB_DUP = DbConstants.DB_DUP;
+ DB_DUPSORT = DbConstants.DB_DUPSORT;
+ DB_RECNUM = DbConstants.DB_RECNUM;
+ DB_RENUMBER = DbConstants.DB_RENUMBER;
+ DB_REVSPLITOFF = DbConstants.DB_REVSPLITOFF;
+ DB_SNAPSHOT = DbConstants.DB_SNAPSHOT;
+
+ DB_JOIN_NOSORT = DbConstants.DB_JOIN_NOSORT;
+
+ DB_NOORDERCHK = DbConstants.DB_NOORDERCHK;
+ DB_ORDERCHKONLY = DbConstants.DB_ORDERCHKONLY;
+ DB_SALVAGE = DbConstants.DB_SALVAGE;
+ DB_AGGRESSIVE = DbConstants.DB_AGGRESSIVE;
+
+ DB_LOCK_NOWAIT = DbConstants.DB_LOCK_NOWAIT;
+ DB_LOCK_CONFLICT = DbConstants.DB_LOCK_CONFLICT;
+
+ DB_ARCH_ABS = DbConstants.DB_ARCH_ABS;
+ DB_ARCH_DATA = DbConstants.DB_ARCH_DATA;
+ DB_ARCH_LOG = DbConstants.DB_ARCH_LOG;
+
+ DB_AFTER = DbConstants.DB_AFTER;
+ DB_APPEND = DbConstants.DB_APPEND;
+ DB_BEFORE = DbConstants.DB_BEFORE;
+ DB_CACHED_COUNTS = DbConstants.DB_CACHED_COUNTS;
+ DB_CHECKPOINT = DbConstants.DB_CHECKPOINT;
+ DB_CONSUME = DbConstants.DB_CONSUME;
+ DB_CONSUME_WAIT = DbConstants.DB_CONSUME_WAIT;
+ DB_CURLSN = DbConstants.DB_CURLSN;
+ DB_CURRENT = DbConstants.DB_CURRENT;
+ DB_FIRST = DbConstants.DB_FIRST;
+ DB_FLUSH = DbConstants.DB_FLUSH;
+ DB_GET_BOTH = DbConstants.DB_GET_BOTH;
+ DB_GET_RECNO = DbConstants.DB_GET_RECNO;
+ DB_JOIN_ITEM = DbConstants.DB_JOIN_ITEM;
+ DB_KEYFIRST = DbConstants.DB_KEYFIRST;
+ DB_KEYLAST = DbConstants.DB_KEYLAST;
+ DB_LAST = DbConstants.DB_LAST;
+ DB_NEXT = DbConstants.DB_NEXT;
+ DB_NEXT_DUP = DbConstants.DB_NEXT_DUP;
+ DB_NEXT_NODUP = DbConstants.DB_NEXT_NODUP;
+ DB_NODUPDATA = DbConstants.DB_NODUPDATA;
+ DB_NOOVERWRITE = DbConstants.DB_NOOVERWRITE;
+ DB_NOSYNC = DbConstants.DB_NOSYNC;
+ DB_POSITION = DbConstants.DB_POSITION;
+ DB_PREV = DbConstants.DB_PREV;
+ DB_PREV_NODUP = DbConstants.DB_PREV_NODUP;
+ DB_RECORDCOUNT = DbConstants.DB_RECORDCOUNT;
+ DB_RMW = DbConstants.DB_RMW;
+ DB_SET = DbConstants.DB_SET;
+ DB_SET_RANGE = DbConstants.DB_SET_RANGE;
+ DB_SET_RECNO = DbConstants.DB_SET_RECNO;
+ DB_WRITECURSOR = DbConstants.DB_WRITECURSOR;
+
+ DB_DBT_MALLOC = DbConstants.DB_DBT_MALLOC;
+ DB_DBT_PARTIAL = DbConstants.DB_DBT_PARTIAL;
+ DB_DBT_REALLOC = DbConstants.DB_DBT_REALLOC;
+ DB_DBT_USERMEM = DbConstants.DB_DBT_USERMEM;
+
+ one_time_init();
+ }
+}
+
+// end of Db.java
diff --git a/db/java/src/com/sleepycat/db/DbAppendRecno.java b/db/java/src/com/sleepycat/db/DbAppendRecno.java
new file mode 100644
index 000000000..ffe40e95f
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbAppendRecno.java
@@ -0,0 +1,22 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbAppendRecno.java,v 11.1 2000/07/31 20:28:30 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This interface is used by Db.set_append_recno()
+ *
+ */
+public interface DbAppendRecno
+{
+ public abstract void db_append_recno(Db db, Dbt data, int recno)
+ throws DbException;
+}
+
+// end of DbAppendRecno.java
diff --git a/db/java/src/com/sleepycat/db/DbBtreeCompare.java b/db/java/src/com/sleepycat/db/DbBtreeCompare.java
new file mode 100644
index 000000000..2e5306af2
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbBtreeCompare.java
@@ -0,0 +1,21 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbBtreeCompare.java,v 11.2 2000/07/04 20:53:19 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This interface is used by DbEnv.set_bt_compare()
+ *
+ */
+public interface DbBtreeCompare
+{
+ public abstract int bt_compare(Db db, Dbt dbt1, Dbt dbt2);
+}
+
+// end of DbBtreeCompare.java
diff --git a/db/java/src/com/sleepycat/db/DbBtreePrefix.java b/db/java/src/com/sleepycat/db/DbBtreePrefix.java
new file mode 100644
index 000000000..27e630543
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbBtreePrefix.java
@@ -0,0 +1,21 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbBtreePrefix.java,v 11.2 2000/07/04 20:53:19 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This interface is used by DbEnv.set_bt_prefix()
+ *
+ */
+public interface DbBtreePrefix
+{
+ public abstract int bt_prefix(Db db, Dbt dbt1, Dbt dbt2);
+}
+
+// end of DbBtreePrefix.java
diff --git a/db/java/src/com/sleepycat/db/DbBtreeStat.java b/db/java/src/com/sleepycat/db/DbBtreeStat.java
new file mode 100644
index 000000000..8dea8da10
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbBtreeStat.java
@@ -0,0 +1,40 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbBtreeStat.java,v 11.5 2000/05/04 02:54:55 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * Db.stat() method.
+ */
+public class DbBtreeStat
+{
+ public int bt_magic; // Magic number.
+ public int bt_version; // Version number.
+ public int bt_metaflags; // Meta-data flags.
+ public int bt_nkeys; // Number of unique keys.
+ public int bt_ndata; // Number of data items.
+ public int bt_pagesize; // Page size.
+ public int bt_maxkey; // Maxkey value.
+ public int bt_minkey; // Minkey value.
+ public int bt_re_len; // Fixed-length record length.
+ public int bt_re_pad; // Fixed-length record pad.
+ public int bt_levels; // Tree levels.
+ public int bt_int_pg; // Internal pages.
+ public int bt_leaf_pg; // Leaf pages.
+ public int bt_dup_pg; // Duplicate pages.
+ public int bt_over_pg; // Overflow pages.
+ public int bt_free; // Pages on the free list.
+ public int bt_int_pgfree; // Bytes free in internal pages.
+ public int bt_leaf_pgfree; // Bytes free in leaf pages.
+ public int bt_dup_pgfree; // Bytes free in duplicate pages.
+ public int bt_over_pgfree; // Bytes free in overflow pages.
+}
+
+// end of DbBtreeStat.java
diff --git a/db/java/src/com/sleepycat/db/DbConstants.java b/db/java/src/com/sleepycat/db/DbConstants.java
new file mode 100644
index 000000000..491b1fce2
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbConstants.java
@@ -0,0 +1,217 @@
+// DO NOT EDIT: automatically built by dist/s_java.
+
+package com.sleepycat.db;
+
+public class DbConstants
+{
+ public static final int DB_MAX_PAGES = 0xffffffff;
+ public static final int DB_MAX_RECORDS = 0xffffffff;
+ public static final int DB_DBT_ISSET = 0x001;
+ public static final int DB_DBT_MALLOC = 0x002;
+ public static final int DB_DBT_PARTIAL = 0x004;
+ public static final int DB_DBT_REALLOC = 0x008;
+ public static final int DB_DBT_USERMEM = 0x010;
+ public static final int DB_DBT_DUPOK = 0x020;
+ public static final int DB_CREATE = 0x000001;
+ public static final int DB_CXX_NO_EXCEPTIONS = 0x000002;
+ public static final int DB_FORCE = 0x000004;
+ public static final int DB_NOMMAP = 0x000008;
+ public static final int DB_RDONLY = 0x000010;
+ public static final int DB_RECOVER = 0x000020;
+ public static final int DB_THREAD = 0x000040;
+ public static final int DB_TXN_NOSYNC = 0x000080;
+ public static final int DB_USE_ENVIRON = 0x000100;
+ public static final int DB_USE_ENVIRON_ROOT = 0x000200;
+ public static final int DB_CLIENT = 0x000400;
+ public static final int DB_XA_CREATE = 0x000400;
+ public static final int DB_INIT_CDB = 0x000400;
+ public static final int DB_INIT_LOCK = 0x000800;
+ public static final int DB_INIT_LOG = 0x001000;
+ public static final int DB_INIT_MPOOL = 0x002000;
+ public static final int DB_INIT_TXN = 0x004000;
+ public static final int DB_JOINENV = 0x008000;
+ public static final int DB_LOCKDOWN = 0x010000;
+ public static final int DB_PRIVATE = 0x020000;
+ public static final int DB_RECOVER_FATAL = 0x040000;
+ public static final int DB_SYSTEM_MEM = 0x080000;
+ public static final int DB_EXCL = 0x000400;
+ public static final int DB_FCNTL_LOCKING = 0x000800;
+ public static final int DB_ODDFILESIZE = 0x001000;
+ public static final int DB_RDWRMASTER = 0x002000;
+ public static final int DB_TRUNCATE = 0x004000;
+ public static final int DB_EXTENT = 0x008000;
+ public static final int DB_TXN_NOWAIT = 0x000400;
+ public static final int DB_TXN_SYNC = 0x000800;
+ public static final int DB_CDB_ALLDB = 0x000400;
+ public static final int DB_UPGRADE = 0x000400;
+ public static final int DB_VERIFY = 0x000800;
+ public static final int DB_DUP = 0x0001;
+ public static final int DB_DUPSORT = 0x0002;
+ public static final int DB_RECNUM = 0x0004;
+ public static final int DB_RENUMBER = 0x0008;
+ public static final int DB_REVSPLITOFF = 0x0010;
+ public static final int DB_SNAPSHOT = 0x0020;
+ public static final int DB_JOIN_NOSORT = 0x0001;
+ public static final int DB_AGGRESSIVE = 0x0001;
+ public static final int DB_NOORDERCHK = 0x0002;
+ public static final int DB_ORDERCHKONLY = 0x0004;
+ public static final int DB_PR_PAGE = 0x0008;
+ public static final int DB_PR_HEADERS = 0x0010;
+ public static final int DB_PR_RECOVERYTEST = 0x0020;
+ public static final int DB_SALVAGE = 0x0040;
+ public static final int DB_VRFY_FLAGMASK = 0xffff;
+ public static final int DB_LOCK_NORUN = 0;
+ public static final int DB_LOCK_DEFAULT = 1;
+ public static final int DB_LOCK_OLDEST = 2;
+ public static final int DB_LOCK_RANDOM = 3;
+ public static final int DB_LOCK_YOUNGEST = 4;
+ public static final int DB_REGION_MAGIC = 0x120897;
+ public static final int DB_VERB_CHKPOINT = 0x0001;
+ public static final int DB_VERB_DEADLOCK = 0x0002;
+ public static final int DB_VERB_RECOVERY = 0x0004;
+ public static final int DB_VERB_WAITSFOR = 0x0008;
+ public static final int DB_TEST_PREOPEN = 1;
+ public static final int DB_TEST_POSTOPEN = 2;
+ public static final int DB_TEST_POSTLOGMETA = 3;
+ public static final int DB_TEST_POSTLOG = 4;
+ public static final int DB_TEST_POSTSYNC = 5;
+ public static final int DB_TEST_PRERENAME = 6;
+ public static final int DB_TEST_POSTRENAME = 7;
+ public static final int DB_ENV_CDB = 0x00001;
+ public static final int DB_ENV_CDB_ALLDB = 0x00002;
+ public static final int DB_ENV_CREATE = 0x00004;
+ public static final int DB_ENV_DBLOCAL = 0x00008;
+ public static final int DB_ENV_LOCKDOWN = 0x00010;
+ public static final int DB_ENV_NOMMAP = 0x00020;
+ public static final int DB_ENV_OPEN_CALLED = 0x00040;
+ public static final int DB_ENV_PRIVATE = 0x00080;
+ public static final int DB_ENV_RPCCLIENT = 0x00100;
+ public static final int DB_ENV_STANDALONE = 0x00200;
+ public static final int DB_ENV_SYSTEM_MEM = 0x00400;
+ public static final int DB_ENV_THREAD = 0x00800;
+ public static final int DB_ENV_TXN_NOSYNC = 0x01000;
+ public static final int DB_ENV_USER_ALLOC = 0x02000;
+ public static final int DB_BTREEVERSION = 8;
+ public static final int DB_BTREEOLDVER = 6;
+ public static final int DB_BTREEMAGIC = 0x053162;
+ public static final int DB_HASHVERSION = 7;
+ public static final int DB_HASHOLDVER = 4;
+ public static final int DB_HASHMAGIC = 0x061561;
+ public static final int DB_QAMVERSION = 3;
+ public static final int DB_QAMOLDVER = 1;
+ public static final int DB_QAMMAGIC = 0x042253;
+ public static final int DB_LOGVERSION = 3;
+ public static final int DB_LOGOLDVER = 3;
+ public static final int DB_LOGMAGIC = 0x040988;
+ public static final int DB_AFTER = 1;
+ public static final int DB_APPEND = 2;
+ public static final int DB_BEFORE = 3;
+ public static final int DB_CACHED_COUNTS = 4;
+ public static final int DB_CHECKPOINT = 5;
+ public static final int DB_CONSUME = 6;
+ public static final int DB_CONSUME_WAIT = 7;
+ public static final int DB_CURLSN = 8;
+ public static final int DB_CURRENT = 9;
+ public static final int DB_FIRST = 10;
+ public static final int DB_FLUSH = 11;
+ public static final int DB_GET_BOTH = 12;
+ public static final int DB_GET_BOTHC = 13;
+ public static final int DB_GET_RECNO = 14;
+ public static final int DB_JOIN_ITEM = 15;
+ public static final int DB_KEYFIRST = 16;
+ public static final int DB_KEYLAST = 17;
+ public static final int DB_LAST = 18;
+ public static final int DB_NEXT = 19;
+ public static final int DB_NEXT_DUP = 20;
+ public static final int DB_NEXT_NODUP = 21;
+ public static final int DB_NODUPDATA = 22;
+ public static final int DB_NOOVERWRITE = 23;
+ public static final int DB_NOSYNC = 24;
+ public static final int DB_POSITION = 25;
+ public static final int DB_POSITIONI = 26;
+ public static final int DB_PREV = 27;
+ public static final int DB_PREV_NODUP = 28;
+ public static final int DB_RECORDCOUNT = 29;
+ public static final int DB_SET = 30;
+ public static final int DB_SET_RANGE = 31;
+ public static final int DB_SET_RECNO = 32;
+ public static final int DB_WRITECURSOR = 33;
+ public static final int DB_WRITELOCK = 34;
+ public static final int DB_OPFLAGS_MASK = 0x000000ff;
+ public static final int DB_RMW = 0x80000000;
+ public static final int DB_INCOMPLETE = -30999;
+ public static final int DB_KEYEMPTY = -30998;
+ public static final int DB_KEYEXIST = -30997;
+ public static final int DB_LOCK_DEADLOCK = -30996;
+ public static final int DB_LOCK_NOTGRANTED = -30995;
+ public static final int DB_NOSERVER = -30994;
+ public static final int DB_NOSERVER_HOME = -30993;
+ public static final int DB_NOSERVER_ID = -30992;
+ public static final int DB_NOTFOUND = -30991;
+ public static final int DB_OLD_VERSION = -30990;
+ public static final int DB_RUNRECOVERY = -30989;
+ public static final int DB_VERIFY_BAD = -30988;
+ public static final int DB_ALREADY_ABORTED = -30899;
+ public static final int DB_DELETED = -30898;
+ public static final int DB_JAVA_CALLBACK = -30897;
+ public static final int DB_NEEDSPLIT = -30896;
+ public static final int DB_SWAPBYTES = -30895;
+ public static final int DB_TXN_CKP = -30894;
+ public static final int DB_VERIFY_FATAL = -30893;
+ public static final int DB_FILE_ID_LEN = 20;
+ public static final int DB_LOGFILEID_INVALID = -1;
+ public static final int DB_OK_BTREE = 0x01;
+ public static final int DB_OK_HASH = 0x02;
+ public static final int DB_OK_QUEUE = 0x04;
+ public static final int DB_OK_RECNO = 0x08;
+ public static final int DB_AM_DISCARD = 0x00001;
+ public static final int DB_AM_DUP = 0x00002;
+ public static final int DB_AM_DUPSORT = 0x00004;
+ public static final int DB_AM_INMEM = 0x00008;
+ public static final int DB_AM_PGDEF = 0x00010;
+ public static final int DB_AM_RDONLY = 0x00020;
+ public static final int DB_AM_RECOVER = 0x00040;
+ public static final int DB_AM_SUBDB = 0x00080;
+ public static final int DB_AM_SWAP = 0x00100;
+ public static final int DB_AM_TXN = 0x00200;
+ public static final int DB_AM_VERIFYING = 0x00400;
+ public static final int DB_BT_RECNUM = 0x00800;
+ public static final int DB_BT_REVSPLIT = 0x01000;
+ public static final int DB_DBM_ERROR = 0x02000;
+ public static final int DB_OPEN_CALLED = 0x04000;
+ public static final int DB_RE_DELIMITER = 0x08000;
+ public static final int DB_RE_FIXEDLEN = 0x10000;
+ public static final int DB_RE_PAD = 0x20000;
+ public static final int DB_RE_RENUMBER = 0x40000;
+ public static final int DB_RE_SNAPSHOT = 0x80000;
+ public static final int DB_RECORD_LOCK = 1;
+ public static final int DB_PAGE_LOCK = 2;
+ public static final int DB_LOCKVERSION = 1;
+ public static final int DB_LOCK_NOWAIT = 0x01;
+ public static final int DB_LOCK_RECORD = 0x02;
+ public static final int DB_LOCK_UPGRADE = 0x04;
+ public static final int DB_LOCK_SWITCH = 0x08;
+ public static final int DB_LOCK_CONFLICT = 0x01;
+ public static final int DB_LOCK_RIW_N = 7;
+ public static final int DB_ARCH_ABS = 0x001;
+ public static final int DB_ARCH_DATA = 0x002;
+ public static final int DB_ARCH_LOG = 0x004;
+ public static final int DB_MPOOL_CREATE = 0x001;
+ public static final int DB_MPOOL_LAST = 0x002;
+ public static final int DB_MPOOL_NEW = 0x004;
+ public static final int DB_MPOOL_NEW_GROUP = 0x008;
+ public static final int DB_MPOOL_EXTENT = 0x010;
+ public static final int DB_MPOOL_CLEAN = 0x001;
+ public static final int DB_MPOOL_DIRTY = 0x002;
+ public static final int DB_MPOOL_DISCARD = 0x004;
+ public static final int DB_TXNVERSION = 1;
+ public static final int DB_TXN_BACKWARD_ROLL = 1;
+ public static final int DB_TXN_FORWARD_ROLL = 2;
+ public static final int DB_TXN_OPENFILES = 3;
+ public static final int DB_TXN_REDO = 4;
+ public static final int DB_TXN_UNDO = 5;
+ public static final int DB_DBM_HSEARCH = 0;
+ public static final int DB_VERSION_MAJOR = 3;
+ public static final int DB_VERSION_MINOR = 2;
+ public static final int DB_VERSION_PATCH = 9;
+}
diff --git a/db/java/src/com/sleepycat/db/DbDeadlockException.java b/db/java/src/com/sleepycat/db/DbDeadlockException.java
new file mode 100644
index 000000000..beab2ad62
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbDeadlockException.java
@@ -0,0 +1,28 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbDeadlockException.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+public class DbDeadlockException extends DbException
+{
+ // methods
+ //
+
+ public DbDeadlockException(String s)
+ {
+ super(s);
+ }
+
+ public DbDeadlockException(String s, int errno)
+ {
+ super(s, errno);
+ }
+}
+
+// end of DbDeadlockException.java
diff --git a/db/java/src/com/sleepycat/db/DbDupCompare.java b/db/java/src/com/sleepycat/db/DbDupCompare.java
new file mode 100644
index 000000000..3d4b5a736
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbDupCompare.java
@@ -0,0 +1,21 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbDupCompare.java,v 11.2 2000/07/04 20:53:19 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This interface is used by DbEnv.set_dup_compare()
+ *
+ */
+public interface DbDupCompare
+{
+ public abstract int dup_compare(Db db, Dbt dbt1, Dbt dbt2);
+}
+
+// end of DbDupCompare.java
diff --git a/db/java/src/com/sleepycat/db/DbEnv.java b/db/java/src/com/sleepycat/db/DbEnv.java
new file mode 100644
index 000000000..6e9ce7ae3
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbEnv.java
@@ -0,0 +1,392 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbEnv.java,v 11.25 2001/01/04 14:23:30 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+import java.io.OutputStream;
+import java.io.FileNotFoundException;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class DbEnv
+{
+ // methods
+ //
+
+ //
+ // After using this constructor, set any parameters via
+ // the set_* access methods below, and finally open
+ // the environment by calling open().
+ //
+ public DbEnv(int flags)
+ {
+ constructor_flags_ = flags;
+ _init(errstream_, constructor_flags_);
+ }
+
+ //
+ // This constructor is purposely not public.
+ // It is used internally to create a DbEnv wrapper
+ // when an underlying environment already exists.
+ //
+ /*package*/ DbEnv(Db db)
+ {
+ _init_using_db(errstream_, db);
+ }
+
+ //
+ // When a Db is created, it is kept in a private list,
+ // so that Db's can be notified when the environment
+ // is closed. This allows us to detect and guard
+ // against the following situation:
+ // DbEnv env = new DbEnv(0);
+ // Db db = new Db(0);
+ // env.close();
+ // db.close();
+ //
+ // This *is* a programming error, but not protecting
+ // against it will crash the VM.
+ //
+ /*package*/ void _add_db(Db db)
+ {
+ dblist_.addElement(db);
+ }
+
+ //
+ // Remove from the private list of Db's.
+ //
+ /*package*/ void _remove_db(Db db)
+ {
+ dblist_.removeElement(db);
+ }
+
+ //
+ // Iterate all the Db's in the list, and
+ // notify them that the environment is closing,
+ // so they can clean up.
+ //
+ /*package*/ void _notify_dbs()
+ {
+ Enumeration enum = dblist_.elements();
+ while (enum.hasMoreElements()) {
+ Db db = (Db)enum.nextElement();
+ db._notify_dbenv_close();
+ }
+ dblist_.removeAllElements();
+ }
+
+ // close discards any internal memory.
+ // After using close, the DbEnv can be reopened.
+ //
+ public synchronized void close(int flags)
+ throws DbException
+ {
+ _notify_dbs();
+ _close(flags);
+ }
+
+ // (Internal)
+ private native void _close(int flags)
+ throws DbException;
+
+ public native void err(int errcode, String message);
+
+ public native void errx(String message);
+
+ // overrides Object.finalize
+ protected void finalize()
+ throws Throwable
+ {
+ _notify_dbs();
+ _finalize(errcall_, errpfx_);
+ }
+
+ // (Internal)
+ protected native void _finalize(DbErrcall errcall, String errpfx)
+ throws Throwable;
+
+ // (Internal)
+ private native void _init(DbErrcall errcall, int flags);
+
+ // (Internal)
+ private native void _init_using_db(DbErrcall errcall, Db db);
+
+ /*package*/ native void _notify_db_close();
+
+ public native void open(String db_home, int flags, int mode)
+ throws DbException, FileNotFoundException;
+
+ // remove removes any files and discards any internal memory.
+ // (i.e. implicitly it does a close, if the environment is open).
+ // After using close, the DbEnv can no longer be used;
+ // create another one if needed.
+ //
+ public native synchronized void remove(String db_home, int flags)
+ throws DbException, FileNotFoundException;
+
+ ////////////////////////////////////////////////////////////////
+ // simple get/set access methods
+ //
+ // If you are calling set_ methods, you need to
+ // use the constructor with one argument along with open().
+
+ public native void set_cachesize(int gbytes, int bytes, int ncaches)
+ throws DbException;
+
+ // Error message callback.
+ public void set_errcall(DbErrcall errcall)
+ {
+ errcall_ = errcall;
+ _set_errcall(errcall);
+ }
+
+ public native void _set_errcall(DbErrcall errcall);
+
+ // Error stream.
+ public void set_error_stream(OutputStream s)
+ {
+ DbOutputStreamErrcall errcall = new DbOutputStreamErrcall(s);
+ set_errcall(errcall);
+ }
+
+ // Error message prefix.
+ public void set_errpfx(String errpfx)
+ {
+ errpfx_ = errpfx;
+ _set_errpfx(errpfx);
+ }
+
+ private native void _set_errpfx(String errpfx);
+
+ // Feedback
+ public void set_feedback(DbFeedback feedback)
+ throws DbException
+ {
+ feedback_ = feedback;
+ feedback_changed(feedback);
+ }
+
+ // (Internal)
+ private native void feedback_changed(DbFeedback feedback)
+ throws DbException;
+
+ // Generate debugging messages.
+ public native void set_verbose(int which, int onoff)
+ throws DbException;
+
+ public native void set_data_dir(String data_dir)
+ throws DbException;
+
+ // Log buffer size.
+ public native void set_lg_bsize(/*u_int32_t*/ int lg_max)
+ throws DbException;
+
+ // Log directory.
+ public native void set_lg_dir(String lg_dir)
+ throws DbException;
+
+ // Maximum log file size.
+ public native void set_lg_max(/*u_int32_t*/ int lg_max)
+ throws DbException;
+
+ // Two dimensional conflict matrix.
+ public native void set_lk_conflicts(byte[][] lk_conflicts)
+ throws DbException;
+
+ // Deadlock detect on every conflict.
+ public native void set_lk_detect(/*u_int32_t*/ int lk_detect)
+ throws DbException;
+
+ /**
+ * @deprecated DB 3.2.6, see the online documentation.
+ */
+ // Maximum number of locks.
+ public native void set_lk_max(/*unsigned*/ int lk_max)
+ throws DbException;
+
+ // Maximum number of lockers.
+ public native void set_lk_max_lockers(/*unsigned*/ int lk_max_lockers)
+ throws DbException;
+
+ // Maximum number of locks.
+ public native void set_lk_max_locks(/*unsigned*/ int lk_max_locks)
+ throws DbException;
+
+ // Maximum number of locked objects.
+ public native void set_lk_max_objects(/*unsigned*/ int lk_max_objects)
+ throws DbException;
+
+ // Maximum file size for mmap.
+ public native void set_mp_mmapsize(/*size_t*/ long mmapsize)
+ throws DbException;
+
+ public native void set_mutexlocks(int mutexlocks)
+ throws DbException;
+
+ public native static void set_pageyield(int pageyield)
+ throws DbException;
+
+ public native static void set_panicstate(int panicstate)
+ throws DbException;
+
+ public void set_recovery_init(DbRecoveryInit recovery_init)
+ throws DbException
+ {
+ recovery_init_ = recovery_init;
+ recovery_init_changed(recovery_init);
+ }
+
+ // (Internal)
+ private native void recovery_init_changed(DbRecoveryInit recovery_init)
+ throws DbException;
+
+ public native static void set_region_init(int region_init)
+ throws DbException;
+
+ public native void set_flags(int flags, int onoff)
+ throws DbException;
+
+ public native void set_server(String host, long cl_timeout,
+ long sv_timeout, int flags)
+ throws DbException;
+
+ public native void set_shm_key(long shm_key)
+ throws DbException;
+
+ public native static void set_tas_spins(int tas_spins)
+ throws DbException;
+
+ public native void set_tmp_dir(String tmp_dir)
+ throws DbException;
+
+ // Feedback
+ public void set_tx_recover(DbTxnRecover tx_recover)
+ throws DbException
+ {
+ tx_recover_ = tx_recover;
+ tx_recover_changed(tx_recover);
+ }
+
+ // (Internal)
+ private native void tx_recover_changed(DbTxnRecover tx_recover)
+ throws DbException;
+
+ // Maximum number of transactions.
+ public native void set_tx_max(/*unsigned*/ int tx_max)
+ throws DbException;
+
+ // Note: only the seconds (not milliseconds) of the timestamp
+ // are used in this API.
+ public void set_tx_timestamp(Date timestamp)
+ throws DbException
+ {
+ _set_tx_timestamp(timestamp.getTime()/1000);
+ }
+
+ // (Internal)
+ private native void _set_tx_timestamp(long seconds)
+ throws DbException;
+
+ // Versioning information
+ public native static int get_version_major();
+ public native static int get_version_minor();
+ public native static int get_version_patch();
+ public native static String get_version_string();
+
+ // Convert DB error codes to strings
+ public native static String strerror(int errcode);
+
+ public native int lock_detect(int flags, int atype)
+ throws DbException;
+
+ public native DbLock lock_get(/*u_int32_t*/ int locker,
+ int flags,
+ Dbt obj,
+ /*db_lockmode_t*/ int lock_mode)
+ throws DbException;
+
+ public native /*u_int32_t*/ int lock_id()
+ throws DbException;
+
+ public native DbLockStat lock_stat()
+ throws DbException;
+
+ public native String[] log_archive(int flags)
+ throws DbException;
+
+ public native static int log_compare(DbLsn lsn0, DbLsn lsn1);
+
+ public native String log_file(DbLsn lsn)
+ throws DbException;
+
+ public native void log_flush(DbLsn lsn)
+ throws DbException;
+
+ public native void log_get(DbLsn lsn, Dbt data, int flags)
+ throws DbException;
+
+ public native void log_put(DbLsn lsn, Dbt data, int flags)
+ throws DbException;
+
+ public native DbLogStat log_stat()
+ throws DbException;
+
+ public native void log_register(Db dbp, String name)
+ throws DbException;
+
+ public native void log_unregister(Db dbp)
+ throws DbException;
+
+ public native DbMpoolStat memp_stat()
+ throws DbException;
+
+ public native DbMpoolFStat[] memp_fstat()
+ throws DbException;
+
+ public native int memp_trickle(int pct)
+ throws DbException;
+
+ public native DbTxn txn_begin(DbTxn pid, int flags)
+ throws DbException;
+
+ public native int txn_checkpoint(int kbyte, int min, int flags)
+ throws DbException;
+
+
+ public native DbTxnStat txn_stat()
+ throws DbException;
+
+ ////////////////////////////////////////////////////////////////
+ //
+ // private data
+ //
+ private long private_dbobj_ = 0;
+ private long private_info_ = 0;
+ private int constructor_flags_ = 0;
+ private Vector dblist_ = new Vector(); // Db's that are open
+ private DbFeedback feedback_ = null;
+ private DbRecoveryInit recovery_init_ = null;
+ private DbTxnRecover tx_recover_ = null;
+ private DbOutputStreamErrcall errstream_ =
+ new DbOutputStreamErrcall(System.err);
+ /*package*/ DbErrcall errcall_ = errstream_;
+ /*package*/ String errpfx_;
+
+ static {
+ Db.load_db();
+ }
+
+}
+
+// end of DbEnv.java
diff --git a/db/java/src/com/sleepycat/db/DbEnvFeedback.java b/db/java/src/com/sleepycat/db/DbEnvFeedback.java
new file mode 100644
index 000000000..9eec2b819
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbEnvFeedback.java
@@ -0,0 +1,19 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbEnvFeedback.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+public interface DbEnvFeedback
+{
+ // methods
+ //
+ public abstract void feedback(DbEnv env, int opcode, int pct);
+}
+
+// end of DbFeedback.java
diff --git a/db/java/src/com/sleepycat/db/DbErrcall.java b/db/java/src/com/sleepycat/db/DbErrcall.java
new file mode 100644
index 000000000..62d3a3e08
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbErrcall.java
@@ -0,0 +1,23 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbErrcall.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public interface DbErrcall
+{
+ // methods
+ //
+ public abstract void errcall(String prefix, String buffer);
+}
+
+// end of DbErrcall.java
diff --git a/db/java/src/com/sleepycat/db/DbException.java b/db/java/src/com/sleepycat/db/DbException.java
new file mode 100644
index 000000000..ed4d020b6
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbException.java
@@ -0,0 +1,56 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbException.java,v 11.4 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class DbException extends Exception
+{
+ // methods
+ //
+
+ public DbException(String s)
+ {
+ super(s);
+ }
+
+ public DbException(String s, int errno)
+ {
+ super(s);
+ this.errno_ = errno;
+ }
+
+ public String toString()
+ {
+ String s = super.toString();
+ if (errno_ == 0)
+ return s;
+ else
+ return s + ": " + DbEnv.strerror(errno_);
+
+ }
+
+ // get/set methods
+ //
+
+ public int get_errno()
+ {
+ return errno_;
+ }
+
+ // private data
+ //
+
+ private int errno_ = 0;
+}
+
+// end of DbException.java
diff --git a/db/java/src/com/sleepycat/db/DbFeedback.java b/db/java/src/com/sleepycat/db/DbFeedback.java
new file mode 100644
index 000000000..d932d951a
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbFeedback.java
@@ -0,0 +1,23 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbFeedback.java,v 11.4 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public interface DbFeedback
+{
+ // methods
+ //
+ public abstract void feedback(Db db, int opcode, int pct);
+}
+
+// end of DbFeedback.java
diff --git a/db/java/src/com/sleepycat/db/DbHash.java b/db/java/src/com/sleepycat/db/DbHash.java
new file mode 100644
index 000000000..a72c2070b
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbHash.java
@@ -0,0 +1,21 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbHash.java,v 11.1 2000/07/04 20:53:19 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This interface is used by DbEnv.set_bt_compare()
+ *
+ */
+public interface DbHash
+{
+ public abstract int hash(Db db, byte[] data, int len);
+}
+
+// end of DbHash.java
diff --git a/db/java/src/com/sleepycat/db/DbHashStat.java b/db/java/src/com/sleepycat/db/DbHashStat.java
new file mode 100644
index 000000000..621543447
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbHashStat.java
@@ -0,0 +1,37 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbHashStat.java,v 11.6 2000/05/04 02:54:55 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * Db.stat() method.
+ */
+public class DbHashStat
+{
+ public int hash_magic; // Magic number.
+ public int hash_version; // Version number.
+ public int hash_metaflags; // Metadata flags.
+ public int hash_nkeys; // Number of unique keys.
+ public int hash_ndata; // Number of data items.
+ public int hash_pagesize; // Page size.
+ public int hash_nelem; // Original nelem specified.
+ public int hash_ffactor; // Fill factor specified at create.
+ public int hash_buckets; // Number of hash buckets.
+ public int hash_free; // Pages on the free list.
+ public int hash_bfree; // Bytes free on bucket pages.
+ public int hash_bigpages; // Number of big key/data pages.
+ public int hash_big_bfree; // Bytes free on big item pages.
+ public int hash_overflows; // Number of overflow pages.
+ public int hash_ovfl_free; // Bytes free on ovfl pages.
+ public int hash_dup; // Number of dup pages.
+ public int hash_dup_free; // Bytes free on duplicate pages.
+}
+
+// end of DbHashStat.java
diff --git a/db/java/src/com/sleepycat/db/DbKeyRange.java b/db/java/src/com/sleepycat/db/DbKeyRange.java
new file mode 100644
index 000000000..6a86afd91
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbKeyRange.java
@@ -0,0 +1,23 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbKeyRange.java,v 1.1 2000/04/12 15:07:02 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class DbKeyRange
+{
+ public double less;
+ public double equal;
+ public double greater;
+}
+
+// end of DbKeyRange.java
diff --git a/db/java/src/com/sleepycat/db/DbLock.java b/db/java/src/com/sleepycat/db/DbLock.java
new file mode 100644
index 000000000..bc467913e
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbLock.java
@@ -0,0 +1,38 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbLock.java,v 11.4 2000/05/25 04:18:13 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class DbLock
+{
+ protected native void finalize()
+ throws Throwable;
+
+ // methods
+ //
+ public native void put(DbEnv env)
+ throws DbException;
+
+ // get/set methods
+ //
+
+ // private data
+ //
+ private long private_dbobj_ = 0;
+
+ static {
+ Db.load_db();
+ }
+}
+
+// end of DbLock.java
diff --git a/db/java/src/com/sleepycat/db/DbLockStat.java b/db/java/src/com/sleepycat/db/DbLockStat.java
new file mode 100644
index 000000000..f23f2ad5d
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbLockStat.java
@@ -0,0 +1,30 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbLockStat.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * DbLockTab.stat() method.
+ */
+public class DbLockStat
+{
+ public int st_maxlocks; // Maximum number of locks in table.
+ public int st_nmodes; // Number of lock modes.
+ public int st_nlockers; // Number of lockers.
+ public int st_nconflicts; // Number of lock conflicts.
+ public int st_nrequests; // Number of lock gets.
+ public int st_nreleases; // Number of lock puts.
+ public int st_ndeadlocks; // Number of lock deadlocks.
+ public int st_region_wait; // Region lock granted after wait.
+ public int st_region_nowait; // Region lock granted without wait.
+ public int st_regsize; // Region size.
+}
+
+// end of DbLockStat.java
diff --git a/db/java/src/com/sleepycat/db/DbLogStat.java b/db/java/src/com/sleepycat/db/DbLogStat.java
new file mode 100644
index 000000000..d708f1c41
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbLogStat.java
@@ -0,0 +1,35 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbLogStat.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * DbLog.stat() method.
+ */
+public class DbLogStat
+{
+ public int st_magic; // Log file magic number.
+ public int st_version; // Log file version number.
+ public int st_mode; // Log file mode.
+ public int st_lg_max; // Maximum log file size.
+ public int st_w_bytes; // Bytes to log.
+ public int st_w_mbytes; // Megabytes to log.
+ public int st_wc_bytes; // Bytes to log since checkpoint.
+ public int st_wc_mbytes; // Megabytes to log since checkpoint.
+ public int st_wcount; // Total syncs to the log.
+ public int st_scount; // Total writes to the log.
+ public int st_region_wait; // Region lock granted after wait.
+ public int st_region_nowait; // Region lock granted without wait.
+ public int st_cur_file; // Current log file number.
+ public int st_cur_offset; // Current log file offset.
+ public int st_regsize; // Region size.
+}
+
+// end of DbLogStat.java
diff --git a/db/java/src/com/sleepycat/db/DbLsn.java b/db/java/src/com/sleepycat/db/DbLsn.java
new file mode 100644
index 000000000..ff36ac61c
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbLsn.java
@@ -0,0 +1,42 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbLsn.java,v 11.5 2000/09/11 16:21:37 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class DbLsn
+{
+ // methods
+ //
+ public DbLsn()
+ {
+ init_lsn();
+ }
+
+ protected native void finalize()
+ throws Throwable;
+
+ private native void init_lsn();
+
+ // get/set methods
+ //
+
+ // private data
+ //
+ private long private_dbobj_ = 0;
+
+ static {
+ Db.load_db();
+ }
+}
+
+// end of DbLsn.java
diff --git a/db/java/src/com/sleepycat/db/DbMemoryException.java b/db/java/src/com/sleepycat/db/DbMemoryException.java
new file mode 100644
index 000000000..67a29a1f1
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbMemoryException.java
@@ -0,0 +1,28 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbMemoryException.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+public class DbMemoryException extends DbException
+{
+ // methods
+ //
+
+ public DbMemoryException(String s)
+ {
+ super(s);
+ }
+
+ public DbMemoryException(String s, int errno)
+ {
+ super(s, errno);
+ }
+}
+
+// end of DbMemoryException.java
diff --git a/db/java/src/com/sleepycat/db/DbMpoolFStat.java b/db/java/src/com/sleepycat/db/DbMpoolFStat.java
new file mode 100644
index 000000000..44497b3bf
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbMpoolFStat.java
@@ -0,0 +1,28 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbMpoolFStat.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * DbMpool.fstat() method.
+ */
+public class DbMpoolFStat
+{
+ public String file_name; // File name.
+ public int st_pagesize; // Page size.
+ public int st_cache_hit; // Pages found in the cache.
+ public int st_cache_miss; // Pages not found in the cache.
+ public int st_map; // Pages from mapped files.
+ public int st_page_create; // Pages created in the cache.
+ public int st_page_in; // Pages read in.
+ public int st_page_out; // Pages written out.
+}
+
+// end of DbMpoolFStat.java
diff --git a/db/java/src/com/sleepycat/db/DbMpoolStat.java b/db/java/src/com/sleepycat/db/DbMpoolStat.java
new file mode 100644
index 000000000..8a6d75e36
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbMpoolStat.java
@@ -0,0 +1,42 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbMpoolStat.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * DbMpool.stat() method.
+ */
+public class DbMpoolStat
+{
+ /**
+ * @deprecated As of Berkeley DB 2.8.2, cachesize for mpool unavailable.
+ */
+ public int st_cachesize; // Cache size.
+ public int st_cache_hit; // Pages found in the cache.
+ public int st_cache_miss; // Pages not found in the cache.
+ public int st_map; // Pages from mapped files.
+ public int st_page_create; // Pages created in the cache.
+ public int st_page_in; // Pages read in.
+ public int st_page_out; // Pages written out.
+ public int st_ro_evict; // Clean pages forced from the cache.
+ public int st_rw_evict; // Dirty pages forced from the cache.
+ public int st_hash_buckets; // Number of hash buckets.
+ public int st_hash_searches; // Total hash chain searches.
+ public int st_hash_longest; // Longest hash chain searched.
+ public int st_hash_examined; // Total hash entries searched.
+ public int st_page_clean; // Clean pages.
+ public int st_page_dirty; // Dirty pages.
+ public int st_page_trickle; // Pages written by memp_trickle.
+ public int st_region_wait; // Region lock granted after wait.
+ public int st_region_nowait; // Region lock granted without wait.
+ public int st_regsize; // Region size.
+}
+
+// end of DbMpoolStat.java
diff --git a/db/java/src/com/sleepycat/db/DbOutputStreamErrcall.java b/db/java/src/com/sleepycat/db/DbOutputStreamErrcall.java
new file mode 100644
index 000000000..4f962d9a3
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbOutputStreamErrcall.java
@@ -0,0 +1,58 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbOutputStreamErrcall.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ *
+ * @author Donald D. Anderson
+ *
+ * This class is not public, as it is only used internally
+ * by Db to implement a default error handler.
+ */
+
+/*package*/ class DbOutputStreamErrcall implements DbErrcall
+{
+ DbOutputStreamErrcall(OutputStream stream)
+ {
+ this.stream_ = stream;
+ }
+
+ // errcall implements DbErrcall
+ //
+ public void errcall(String prefix, String buffer)
+ {
+ try {
+ if (prefix != null) {
+ stream_.write(prefix.getBytes());
+ stream_.write((new String(": ")).getBytes());
+ }
+ stream_.write(buffer.getBytes());
+ stream_.write((new String("\n")).getBytes());
+ }
+ catch (IOException e) {
+
+ // well, we tried.
+ // Do our best to report the problem by other means.
+ //
+ System.err.println("DbOutputStreamErrcall Exception: " + e);
+ if (prefix != null)
+ System.err.print(prefix + ": ");
+ System.err.println(buffer + "\n");
+ }
+ }
+
+ // private data
+ //
+ private OutputStream stream_;
+}
+
+// end of DbOutputStreamErrcall.java
diff --git a/db/java/src/com/sleepycat/db/DbQueueStat.java b/db/java/src/com/sleepycat/db/DbQueueStat.java
new file mode 100644
index 000000000..652878b1a
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbQueueStat.java
@@ -0,0 +1,32 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbQueueStat.java,v 11.5 2000/11/07 18:45:27 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * Db.stat() method.
+ */
+public class DbQueueStat
+{
+ public int qs_magic; // Magic number.
+ public int qs_version; // Version number.
+ public int qs_metaflags; // Metadata flags.
+ public int qs_nkeys; // Number of unique keys.
+ public int qs_ndata; // Number of data items.
+ public int qs_pagesize; // Page size.
+ public int qs_pages; // Data pages.
+ public int qs_re_len; // Fixed-length record length.
+ public int qs_re_pad; // Fixed-length record pad.
+ public int qs_pgfree; // Bytes free in data pages.
+ public int qs_first_recno; // First not deleted record.
+ public int qs_cur_recno; // Last allocated record number.
+}
+
+// end of DbQueueStat.java
diff --git a/db/java/src/com/sleepycat/db/DbRecoveryInit.java b/db/java/src/com/sleepycat/db/DbRecoveryInit.java
new file mode 100644
index 000000000..b32eebcaa
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbRecoveryInit.java
@@ -0,0 +1,23 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbRecoveryInit.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public interface DbRecoveryInit
+{
+ // methods
+ //
+ public abstract void recovery_init(DbEnv dbenv);
+}
+
+// end of DbRecoveryInit.java
diff --git a/db/java/src/com/sleepycat/db/DbRunRecoveryException.java b/db/java/src/com/sleepycat/db/DbRunRecoveryException.java
new file mode 100644
index 000000000..78736b6ed
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbRunRecoveryException.java
@@ -0,0 +1,32 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbRunRecoveryException.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class DbRunRecoveryException extends DbException
+{
+ // methods
+ //
+
+ public DbRunRecoveryException(String s)
+ {
+ super(s);
+ }
+
+ public DbRunRecoveryException(String s, int errno)
+ {
+ super(s, errno);
+ }
+}
+
+// end of DbRunRecoveryException.java
diff --git a/db/java/src/com/sleepycat/db/DbTxn.java b/db/java/src/com/sleepycat/db/DbTxn.java
new file mode 100644
index 000000000..201ff94c8
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbTxn.java
@@ -0,0 +1,47 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbTxn.java,v 11.5 2000/05/25 04:18:13 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class DbTxn
+{
+ // methods
+ //
+ public native void abort()
+ throws DbException;
+
+ public native void commit(int flags)
+ throws DbException;
+
+ public native /*u_int32_t*/ int id()
+ throws DbException;
+
+ public native void prepare()
+ throws DbException;
+
+ protected native void finalize()
+ throws Throwable;
+
+ // get/set methods
+ //
+
+ // private data
+ //
+ private long private_dbobj_ = 0;
+
+ static {
+ Db.load_db();
+ }
+}
+
+// end of DbTxn.java
diff --git a/db/java/src/com/sleepycat/db/DbTxnRecover.java b/db/java/src/com/sleepycat/db/DbTxnRecover.java
new file mode 100644
index 000000000..ee4793594
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbTxnRecover.java
@@ -0,0 +1,22 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbTxnRecover.java,v 11.1 2000/06/29 18:08:17 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This interface is used by DbEnv.set_tx_recover()
+ *
+ */
+public interface DbTxnRecover
+{
+ // The value of recops is one of the Db.DB_TXN_* constants
+ public abstract int tx_recover(DbEnv env, Dbt dbt, DbLsn lsn, int recops);
+}
+
+// end of DbBtreeCompare.java
diff --git a/db/java/src/com/sleepycat/db/DbTxnStat.java b/db/java/src/com/sleepycat/db/DbTxnStat.java
new file mode 100644
index 000000000..e72addb00
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/DbTxnStat.java
@@ -0,0 +1,40 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: DbTxnStat.java,v 11.3 2000/02/14 02:59:56 bostic Exp $
+ */
+
+package com.sleepycat.db;
+
+/*
+ * This is filled in and returned by the
+ * DbTxnMgr.fstat() method.
+ */
+public class DbTxnStat
+{
+ public static class Active {
+ public int txnid; // Transaction ID
+ public int parentid; // Transaction ID of parent
+ public DbLsn lsn; // Lsn of the begin record
+ };
+
+ public DbLsn st_last_ckp; // lsn of the last checkpoint
+ public DbLsn st_pending_ckp; // last checkpoint did not finish
+ public long st_time_ckp; // time of last checkpoint (UNIX secs)
+ public int st_last_txnid; // last transaction id given out
+ public int st_maxtxns; // maximum number of active txns
+ public int st_naborts; // number of aborted transactions
+ public int st_nbegins; // number of begun transactions
+ public int st_ncommits; // number of committed transactions
+ public int st_nactive; // number of active transactions
+ public int st_maxnactive; // maximum active transactions
+ public Active st_txnarray[]; // array of active transactions
+ public int st_region_wait; // Region lock granted after wait.
+ public int st_region_nowait; // Region lock granted without wait.
+ public int st_regsize; // Region size.
+}
+
+// end of DbTxnStat.java
diff --git a/db/java/src/com/sleepycat/db/Dbc.java b/db/java/src/com/sleepycat/db/Dbc.java
new file mode 100644
index 000000000..b097cbad8
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/Dbc.java
@@ -0,0 +1,56 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: Dbc.java,v 11.5 2000/05/25 04:18:13 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class Dbc
+{
+ // methods
+ //
+ public native void close()
+ throws DbException;
+
+ public native int count(int flags)
+ throws DbException;
+
+ // returns: 0, DB_KEYEMPTY, or throws error
+ public native int del(int flags)
+ throws DbException;
+
+ public native Dbc dup(int flags)
+ throws DbException;
+
+ // returns: 0, DB_NOTFOUND, or throws error
+ public native int get(Dbt key, Dbt data, int flags)
+ throws DbException;
+
+ // returns: 0, DB_KEYEXIST, or throws error
+ public native int put(Dbt key, Dbt data, int flags)
+ throws DbException;
+
+ protected native void finalize()
+ throws Throwable;
+
+ // get/set methods
+ //
+
+ // private data
+ //
+ private long private_dbobj_ = 0;
+
+ static {
+ Db.load_db();
+ }
+}
+
+// end of Dbc.java
diff --git a/db/java/src/com/sleepycat/db/Dbt.java b/db/java/src/com/sleepycat/db/Dbt.java
new file mode 100644
index 000000000..bbb478cd5
--- /dev/null
+++ b/db/java/src/com/sleepycat/db/Dbt.java
@@ -0,0 +1,110 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: Dbt.java,v 11.6 2000/06/16 03:34:01 dda Exp $
+ */
+
+package com.sleepycat.db;
+
+/**
+ *
+ * @author Donald D. Anderson
+ */
+public class Dbt
+{
+ // methods
+ //
+
+ protected native void finalize()
+ throws Throwable;
+
+ // get/set methods
+ //
+
+ // key/data
+
+ public void set_data(byte[] data)
+ {
+ // internal_set_data is separated from set_data in case
+ // we want to have set_data automatically set some other
+ // fields (size, etc.) someday.
+ //
+ internal_set_data(data);
+ }
+
+ public native byte[] get_data();
+ private native void internal_set_data(byte[] data);
+
+ // These are not in the original DB interface,
+ // but they can be used to get/set the offset
+ // into the attached byte array.
+ //
+ public native void set_offset(int off);
+ public native int get_offset();
+
+ // key/data length
+ public native /*u_int32_t*/ int get_size();
+ public native void set_size(/*u_int32_t*/ int size);
+
+ // RO: length of user buffer.
+ public native /*u_int32_t*/ int get_ulen();
+ public native void set_ulen(/*u_int32_t*/ int ulen);
+
+ // RO: get/put record length.
+ public native /*u_int32_t*/ int get_dlen();
+ public native void set_dlen(/*u_int32_t*/ int dlen);
+
+ // RO: get/put record offset.
+ public native /*u_int32_t*/ int get_doff();
+ public native void set_doff(/*u_int32_t*/ int doff);
+
+ // flags
+ public native /*u_int32_t*/ int get_flags();
+ public native void set_flags(/*u_int32_t*/ int flags);
+
+ // These are not in the original DB interface.
+ // They can be used to set the recno key for a Dbt.
+ // Note: you must set the data field to an array of
+ // at least four bytes before calling either of these.
+ //
+ public native void set_recno_key_data(int recno);
+ public native int get_recno_key_data();
+
+ public Dbt(byte[] data)
+ {
+ init();
+ internal_set_data(data);
+ if (data != null)
+ set_size(data.length);
+ }
+
+ public Dbt(byte[] data, int off, int len)
+ {
+ this(data);
+ set_ulen(len);
+ set_offset(off);
+ }
+
+ public Dbt()
+ {
+ init();
+ }
+
+ // private methods
+ //
+ private native void init();
+
+ // private data
+ //
+ private long private_dbobj_ = 0;
+
+ static {
+ Db.load_db();
+ }
+}
+
+
+// end of Dbt.java
diff --git a/db/java/src/com/sleepycat/examples/AccessExample.java b/db/java/src/com/sleepycat/examples/AccessExample.java
new file mode 100644
index 000000000..f3a98c2c7
--- /dev/null
+++ b/db/java/src/com/sleepycat/examples/AccessExample.java
@@ -0,0 +1,186 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: AccessExample.java,v 11.5 2000/12/13 07:09:42 krinsky Exp $
+ */
+
+package com.sleepycat.examples;
+
+import com.sleepycat.db.*;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.PrintStream;
+
+class AccessExample
+{
+ private static final String FileName = "access.db";
+
+ public AccessExample()
+ {
+ }
+
+ private static void usage()
+ {
+ System.err.println("usage: AccessExample\n");
+ System.exit(1);
+ }
+
+ public static void main(String argv[])
+ {
+ try
+ {
+ AccessExample app = new AccessExample();
+ app.run();
+ }
+ catch (DbException dbe)
+ {
+ System.err.println("AccessExample: " + dbe.toString());
+ System.exit(1);
+ }
+ catch (FileNotFoundException fnfe)
+ {
+ System.err.println("AccessExample: " + fnfe.toString());
+ System.exit(1);
+ }
+ System.exit(0);
+ }
+
+ // Prompts for a line, and keeps prompting until a non blank
+ // line is returned. Returns null on error.
+ //
+ static public String askForLine(InputStreamReader reader,
+ PrintStream out, String prompt)
+ {
+ String result = "";
+ while (result != null && result.length() == 0) {
+ out.print(prompt);
+ out.flush();
+ result = getLine(reader);
+ }
+ return result;
+ }
+
+ // Not terribly efficient, but does the job.
+ // Works for reading a line from stdin or a file.
+ // Returns null on EOF. If EOF appears in the middle
+ // of a line, returns that line, then null on next call.
+ //
+ static public String getLine(InputStreamReader reader)
+ {
+ StringBuffer b = new StringBuffer();
+ int c;
+ try {
+ while ((c = reader.read()) != -1 && c != '\n') {
+ if (c != '\r')
+ b.append((char)c);
+ }
+ }
+ catch (IOException ioe) {
+ c = -1;
+ }
+
+ if (c == -1 && b.length() == 0)
+ return null;
+ else
+ return b.toString();
+ }
+
+ public void run()
+ throws DbException, FileNotFoundException
+ {
+ // Remove the previous database.
+ new File(FileName).delete();
+
+ // Create the database object.
+ // There is no environment for this simple example.
+ Db table = new Db(null, 0);
+ table.set_error_stream(System.err);
+ table.set_errpfx("AccessExample");
+ table.open(FileName, null, Db.DB_BTREE, Db.DB_CREATE, 0644);
+
+ //
+ // Insert records into the database, where the key is the user
+ // input and the data is the user input in reverse order.
+ //
+ InputStreamReader reader = new InputStreamReader(System.in);
+
+ for (;;) {
+ String line = askForLine(reader, System.out, "input> ");
+ if (line == null)
+ break;
+
+ String reversed = (new StringBuffer(line)).reverse().toString();
+
+ // See definition of StringDbt below
+ //
+ StringDbt key = new StringDbt(line);
+ StringDbt data = new StringDbt(reversed);
+
+ try
+ {
+ int err;
+ if ((err = table.put(null,
+ key, data, Db.DB_NOOVERWRITE)) == Db.DB_KEYEXIST) {
+ System.out.println("Key " + line + " already exists.");
+ }
+ }
+ catch (DbException dbe)
+ {
+ System.out.println(dbe.toString());
+ }
+ System.out.println("");
+ }
+
+ // Acquire an iterator for the table.
+ Dbc iterator;
+ iterator = table.cursor(null, 0);
+
+ // Walk through the table, printing the key/data pairs.
+ // See class StringDbt defined below.
+ //
+ StringDbt key = new StringDbt();
+ StringDbt data = new StringDbt();
+ while (iterator.get(key, data, Db.DB_NEXT) == 0)
+ {
+ System.out.println(key.getString() + " : " + data.getString());
+ }
+ iterator.close();
+ table.close(0);
+ }
+
+ // Here's an example of how you can extend a Dbt in a straightforward
+ // way to allow easy storage/retrieval of strings, or whatever
+ // kind of data you wish. We've declared it as a static inner
+ // class, but it need not be.
+ //
+ static /*inner*/
+ class StringDbt extends Dbt
+ {
+ StringDbt()
+ {
+ set_flags(Db.DB_DBT_MALLOC); // tell Db to allocate on retrieval
+ }
+
+ StringDbt(String value)
+ {
+ setString(value);
+ set_flags(Db.DB_DBT_MALLOC); // tell Db to allocate on retrieval
+ }
+
+ void setString(String value)
+ {
+ set_data(value.getBytes());
+ set_size(value.length());
+ }
+
+ String getString()
+ {
+ return new String(get_data(), 0, get_size());
+ }
+ }
+}
diff --git a/db/java/src/com/sleepycat/examples/BtRecExample.java b/db/java/src/com/sleepycat/examples/BtRecExample.java
new file mode 100644
index 000000000..5101f676a
--- /dev/null
+++ b/db/java/src/com/sleepycat/examples/BtRecExample.java
@@ -0,0 +1,348 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: BtRecExample.java,v 11.6 2000/02/19 20:58:02 bostic Exp $
+ */
+
+package com.sleepycat.examples;
+
+import com.sleepycat.db.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.PrintStream;
+
+public class BtRecExample
+{
+ static final String progname = "BtRecExample"; // Program name.
+ static final String database = "access.db";
+ static final String wordlist = "../test/wordlist";
+
+ BtRecExample(BufferedReader reader)
+ throws DbException, IOException, FileNotFoundException
+ {
+ int ret;
+
+ // Remove the previous database.
+ File f = new File(database);
+ f.delete();
+
+ dbp = new Db(null, 0);
+
+ dbp.set_error_stream(System.err);
+ dbp.set_errpfx(progname);
+ dbp.set_pagesize(1024); // 1K page sizes.
+
+ dbp.set_flags(Db.DB_RECNUM); // Record numbers.
+ dbp.open(database, null, Db.DB_BTREE, Db.DB_CREATE, 0664);
+
+ //
+ // Insert records into the database, where the key is the word
+ // preceded by its record number, and the data is the same, but
+ // in reverse order.
+ //
+
+ for (int cnt = 1; cnt <= 1000; ++cnt) {
+ String numstr = String.valueOf(cnt);
+ while (numstr.length() < 4)
+ numstr = "0" + numstr;
+ String buf = numstr + '_' + reader.readLine();
+ StringBuffer rbuf = new StringBuffer(buf).reverse();
+
+ StringDbt key = new StringDbt(buf);
+ StringDbt data = new StringDbt(rbuf.toString());
+
+ if ((ret = dbp.put(null, key, data, Db.DB_NOOVERWRITE)) != 0) {
+ if (ret != Db.DB_KEYEXIST)
+ throw new DbException("Db.put failed" + ret);
+ }
+ }
+ }
+
+ void run()
+ throws DbException
+ {
+ int recno;
+ int ret;
+
+ // Acquire a cursor for the database.
+ dbcp = dbp.cursor(null, 0);
+
+ //
+ // Prompt the user for a record number, then retrieve and display
+ // that record.
+ //
+ InputStreamReader reader = new InputStreamReader(System.in);
+
+ for (;;) {
+ // Get a record number.
+ String line = askForLine(reader, System.out, "recno #> ");
+ if (line == null)
+ break;
+
+ try {
+ recno = Integer.parseInt(line);
+ }
+ catch (NumberFormatException nfe) {
+ System.err.println("Bad record number: " + nfe);
+ continue;
+ }
+
+ //
+ // Start with a fresh key each time, the dbp.get() routine returns
+ // the key and data pair, not just the key!
+ //
+ RecnoStringDbt key = new RecnoStringDbt(recno, 100);
+ RecnoStringDbt data = new RecnoStringDbt(100);
+
+ if ((ret = dbcp.get(key, data, Db.DB_SET_RECNO)) != 0) {
+ throw new DbException("Dbc.get failed", ret);
+ }
+
+ // Display the key and data.
+ show("k/d\t", key, data);
+
+ // Move the cursor a record forward.
+ if ((ret = dbcp.get(key, data, Db.DB_NEXT)) != 0) {
+ throw new DbException("Dbc.get failed", ret);
+ }
+
+ // Display the key and data.
+ show("next\t", key, data);
+
+ RecnoStringDbt datano = new RecnoStringDbt(100);
+
+ //
+ // Retrieve the record number for the following record into
+ // local memory.
+ //
+ if ((ret = dbcp.get(key, datano, Db.DB_GET_RECNO)) != 0) {
+ if (ret != Db.DB_NOTFOUND && ret != Db.DB_KEYEMPTY) {
+ throw new DbException("Dbc.get failed", ret);
+ }
+ }
+ else {
+ recno = datano.getRecno();
+ System.out.println("retrieved recno: " + recno);
+ }
+ }
+
+ dbcp.close();
+ dbcp = null;
+ }
+
+ //
+ // Print out the number of records in the database.
+ //
+ void stats()
+ throws DbException
+ {
+ DbBtreeStat statp;
+
+ statp = (DbBtreeStat)dbp.stat(0);
+ System.out.println(progname + ": database contains " +
+ statp.bt_ndata + " records");
+ }
+
+ void show(String msg, RecnoStringDbt key, RecnoStringDbt data)
+ throws DbException
+ {
+ System.out.println(msg + key.getString() + ": " + data.getString());
+ }
+
+ public void shutdown()
+ throws DbException
+ {
+ if (dbcp != null) {
+ dbcp.close();
+ dbcp = null;
+ }
+ if (dbp != null) {
+ dbp.close(0);
+ dbp = null;
+ }
+ }
+
+ public static void main(String argv[])
+ {
+
+ try {
+ // Open the word database.
+ FileReader freader = new FileReader(wordlist);
+
+ BtRecExample app = new BtRecExample(new BufferedReader(freader));
+
+ // Close the word database.
+ freader.close();
+ freader = null;
+
+ app.stats();
+ app.run();
+ }
+ catch (FileNotFoundException fnfe) {
+ System.err.println(progname + ": unexpected open error " + fnfe);
+ System.exit (1);
+ }
+ catch (IOException ioe) {
+ System.err.println(progname + ": open " + wordlist + ": " + ioe);
+ System.exit (1);
+ }
+ catch (DbException dbe) {
+ System.err.println("Exception: " + dbe);
+ System.exit(dbe.get_errno());
+ }
+
+ System.exit(0);
+ }
+
+ void
+ usage()
+ {
+ System.err.println("usage: " + progname);
+ System.exit(1);
+ }
+
+ // Prompts for a line, and keeps prompting until a non blank
+ // line is returned. Returns null on error.
+ //
+ static public String askForLine(InputStreamReader reader,
+ PrintStream out, String prompt)
+ {
+ String result = "";
+ while (result != null && result.length() == 0) {
+ out.print(prompt);
+ out.flush();
+ result = getLine(reader);
+ }
+ return result;
+ }
+
+ // Not terribly efficient, but does the job.
+ // Works for reading a line from stdin or a file.
+ // Returns null on EOF. If EOF appears in the middle
+ // of a line, returns that line, then null on next call.
+ //
+ static public String getLine(InputStreamReader reader)
+ {
+ StringBuffer b = new StringBuffer();
+ int c;
+ try {
+ while ((c = reader.read()) != -1 && c != '\n') {
+ if (c != '\r')
+ b.append((char)c);
+ }
+ }
+ catch (IOException ioe) {
+ c = -1;
+ }
+
+ if (c == -1 && b.length() == 0)
+ return null;
+ else
+ return b.toString();
+ }
+
+ private Dbc dbcp;
+ private Db dbp;
+
+ // Here's an example of how you can extend a Dbt in a straightforward
+ // way to allow easy storage/retrieval of strings.
+ // We've declared it as a static inner class, but it need not be.
+ //
+ static /*inner*/
+ class StringDbt extends Dbt
+ {
+ StringDbt(byte[] arr)
+ {
+ set_flags(Db.DB_DBT_USERMEM);
+ set_data(arr);
+ set_size(arr.length);
+ }
+
+ StringDbt()
+ {
+ set_flags(Db.DB_DBT_MALLOC); // tell Db to allocate on retrieval
+ }
+
+ StringDbt(String value)
+ {
+ setString(value);
+ set_flags(Db.DB_DBT_MALLOC); // tell Db to allocate on retrieval
+ }
+
+ void setString(String value)
+ {
+ set_data(value.getBytes());
+ set_size(value.length());
+ // must set ulen because sometimes a string is returned
+ set_ulen(value.length());
+ }
+
+ String getString()
+ {
+ return new String(get_data(), 0, get_size());
+ }
+ }
+
+ // Here's an example of how you can extend a Dbt to store
+ // (potentially) both recno's and strings in the same
+ // structure.
+ //
+ static /*inner*/
+ class RecnoStringDbt extends Dbt
+ {
+ RecnoStringDbt(int maxsize)
+ {
+ this(0, maxsize); // let other constructor do most of the work
+ }
+
+ RecnoStringDbt(int value, int maxsize)
+ {
+ set_flags(Db.DB_DBT_USERMEM); // do not allocate on retrieval
+ arr = new byte[maxsize];
+ set_data(arr); // use our local array for data
+ set_ulen(maxsize); // size of return storage
+ setRecno(value);
+ }
+
+ RecnoStringDbt(String value, int maxsize)
+ {
+ set_flags(Db.DB_DBT_USERMEM); // do not allocate on retrieval
+ arr = new byte[maxsize];
+ set_data(arr); // use our local array for data
+ set_ulen(maxsize); // size of return storage
+ setString(value);
+ }
+
+ void setRecno(int value)
+ {
+ set_recno_key_data(value);
+ set_size(arr.length);
+ }
+
+ void setString(String value)
+ {
+ set_data(value.getBytes());
+ set_size(value.length());
+ }
+
+ int getRecno()
+ {
+ return get_recno_key_data();
+ }
+
+ String getString()
+ {
+ return new String(get_data(), 0, get_size());
+ }
+
+ byte arr[];
+ }
+}
diff --git a/db/java/src/com/sleepycat/examples/EnvExample.java b/db/java/src/com/sleepycat/examples/EnvExample.java
new file mode 100644
index 000000000..f1b855836
--- /dev/null
+++ b/db/java/src/com/sleepycat/examples/EnvExample.java
@@ -0,0 +1,128 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: EnvExample.java,v 11.7 2000/09/25 13:16:51 dda Exp $
+ */
+
+package com.sleepycat.examples;
+
+import com.sleepycat.db.*;
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
+
+/*
+ * An example of a program using DbEnv to configure its DB
+ * environment.
+ *
+ * For comparison purposes, this example uses a similar structure
+ * as examples/ex_env.c and examples_cxx/EnvExample.cpp.
+ */
+public class EnvExample
+{
+ private static final String progname = "EnvExample";
+ private static final String DATABASE_HOME = "/tmp/database";
+
+ private static void db_application()
+ throws DbException
+ {
+ // Do something interesting...
+ // Your application goes here.
+ }
+
+ private static void db_setup(String home, String data_dir,
+ OutputStream errs)
+ throws DbException, FileNotFoundException
+ {
+ //
+ // Create an environment object and initialize it for error
+ // reporting.
+ //
+ DbEnv dbenv = new DbEnv(0);
+ dbenv.set_error_stream(errs);
+ dbenv.set_errpfx(progname);
+
+ //
+ // We want to specify the shared memory buffer pool cachesize,
+ // but everything else is the default.
+ //
+ dbenv.set_cachesize(0, 64 * 1024, 0);
+
+ // Databases are in a subdirectory.
+ dbenv.set_data_dir(data_dir);
+
+ // Open the environment with full transactional support.
+ //
+ // open() will throw a DbException if there is an error.
+ //
+ // open is declared to throw a FileNotFoundException, which normally
+ // shouldn't occur with the DB_CREATE option.
+ //
+ dbenv.open(DATABASE_HOME,
+ Db.DB_CREATE | Db.DB_INIT_LOCK | Db.DB_INIT_LOG |
+ Db.DB_INIT_MPOOL | Db.DB_INIT_TXN, 0);
+
+ try {
+
+ // Start your application.
+ db_application();
+
+ }
+ finally {
+
+ // Close the environment. Doing this in the
+ // finally block ensures it is done, even if
+ // an error is thrown.
+ //
+ dbenv.close(0);
+ }
+ }
+
+ private static void db_teardown(String home, String data_dir,
+ OutputStream errs)
+ throws DbException, FileNotFoundException
+ {
+ // Remove the shared database regions.
+
+ DbEnv dbenv = new DbEnv(0);
+
+ dbenv.set_error_stream(errs);
+ dbenv.set_errpfx(progname);
+ dbenv.set_data_dir(data_dir);
+ dbenv.remove(home, 0);
+ }
+
+ public static void main(String[] args)
+ {
+ //
+ // All of the shared database files live in /tmp/database,
+ // but data files live in /database.
+ //
+ // Using Berkeley DB in C/C++, we need to allocate two elements
+ // in the array and set config[1] to NULL. This is not
+ // necessary in Java.
+ //
+ String home = DATABASE_HOME;
+ String config = "/database/files";
+
+ try {
+ System.out.println("Setup env");
+ db_setup(home, config, System.err);
+
+ System.out.println("Teardown env");
+ db_teardown(home, config, System.err);
+ }
+ catch (DbException dbe) {
+ System.err.println(progname + ": environment open: " + dbe.toString());
+ System.exit (1);
+ }
+ catch (FileNotFoundException fnfe) {
+ System.err.println(progname +
+ ": unexpected open environment error " + fnfe);
+ System.exit (1);
+ }
+ }
+
+}
diff --git a/db/java/src/com/sleepycat/examples/LockExample.java b/db/java/src/com/sleepycat/examples/LockExample.java
new file mode 100644
index 000000000..33b7d0538
--- /dev/null
+++ b/db/java/src/com/sleepycat/examples/LockExample.java
@@ -0,0 +1,235 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: LockExample.java,v 11.5 2001/01/04 14:23:30 dda Exp $
+ */
+
+package com.sleepycat.examples;
+
+import com.sleepycat.db.*;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Vector;
+
+//
+// An example of a program using DbLock and related classes.
+//
+class LockExample extends DbEnv
+{
+ private static final String progname = "LockExample";
+ private static final String LOCK_HOME = "TESTDIR";
+
+ public LockExample(String home, int maxlocks, boolean do_unlink)
+ throws DbException, FileNotFoundException
+ {
+ super(0);
+ if (do_unlink) {
+ remove(home, Db.DB_FORCE);
+ }
+ else {
+ set_error_stream(System.err);
+ set_errpfx("LockExample");
+ if (maxlocks != 0)
+ set_lk_max_locks(maxlocks);
+ open(home, Db.DB_CREATE|Db.DB_INIT_LOCK, 0);
+ }
+ }
+
+ // Prompts for a line, and keeps prompting until a non blank
+ // line is returned. Returns null on error.
+ //
+ static public String askForLine(InputStreamReader reader,
+ PrintStream out, String prompt)
+ {
+ String result = "";
+ while (result != null && result.length() == 0) {
+ out.print(prompt);
+ out.flush();
+ result = getLine(reader);
+ }
+ return result;
+ }
+
+ // Not terribly efficient, but does the job.
+ // Works for reading a line from stdin or a file.
+ // Returns null on EOF. If EOF appears in the middle
+ // of a line, returns that line, then null on next call.
+ //
+ static public String getLine(InputStreamReader reader)
+ {
+ StringBuffer b = new StringBuffer();
+ int c;
+ try {
+ while ((c = reader.read()) != -1 && c != '\n') {
+ if (c != '\r')
+ b.append((char)c);
+ }
+ }
+ catch (IOException ioe) {
+ c = -1;
+ }
+
+ if (c == -1 && b.length() == 0)
+ return null;
+ else
+ return b.toString();
+ }
+
+ public void run()
+ throws DbException
+ {
+ long held;
+ int len = 0, locker;
+ int ret;
+ boolean did_get = false;
+ int lockid = 0;
+ InputStreamReader in = new InputStreamReader(System.in);
+ Vector locks = new Vector();
+
+ //
+ // Accept lock requests.
+ //
+ locker = lock_id();
+ for (held = 0;;) {
+ String opbuf = askForLine(in, System.out,
+ "Operation get/release [get]> ");
+ if (opbuf == null)
+ break;
+
+ try {
+ if (opbuf.equals("get")) {
+ // Acquire a lock.
+ String objbuf = askForLine(in, System.out,
+ "input object (text string) to lock> ");
+ if (objbuf == null)
+ break;
+
+ String lockbuf;
+ do {
+ lockbuf = askForLine(in, System.out,
+ "lock type read/write [read]> ");
+ if (lockbuf == null)
+ break;
+ len = lockbuf.length();
+ } while (len >= 1 &&
+ !lockbuf.equals("read") &&
+ !lockbuf.equals("write"));
+
+ int lock_type;
+ if (len <= 1 || lockbuf.equals("read"))
+ lock_type = Db.DB_LOCK_READ;
+ else
+ lock_type = Db.DB_LOCK_WRITE;
+
+ Dbt dbt = new Dbt(objbuf.getBytes());
+
+ DbLock lock;
+ did_get = true;
+ lock = lock_get(locker, Db.DB_LOCK_NOWAIT,
+ dbt, lock_type);
+ lockid = locks.size();
+ locks.addElement(lock);
+ } else {
+ // Release a lock.
+ String objbuf;
+ objbuf = askForLine(in, System.out,
+ "input lock to release> ");
+ if (objbuf == null)
+ break;
+
+ lockid = Integer.parseInt(objbuf, 16);
+ if (lockid < 0 || lockid >= locks.size()) {
+ System.out.println("Lock #" + lockid + " out of range");
+ continue;
+ }
+ did_get = false;
+ DbLock lock = (DbLock)locks.elementAt(lockid);
+ lock.put(this);
+ }
+ System.out.println("Lock #" + lockid + " " +
+ (did_get ? "granted" : "released"));
+ held += did_get ? 1 : -1;
+ }
+ catch (DbException dbe) {
+ switch (dbe.get_errno()) {
+ case Db.DB_LOCK_NOTGRANTED:
+ System.out.println("Lock not granted");
+ break;
+ case Db.DB_LOCK_DEADLOCK:
+ System.err.println("LockExample: lock_" +
+ (did_get ? "get" : "put") +
+ ": returned DEADLOCK");
+ break;
+ default:
+ System.err.println("LockExample: lock_get: " + dbe.toString());
+ }
+ }
+ }
+ System.out.println();
+ System.out.println("Closing lock region " + String.valueOf(held) +
+ " locks held");
+ }
+
+ private static void usage()
+ {
+ System.err.println("usage: LockExample [-u] [-h home] [-m maxlocks]");
+ System.exit(1);
+ }
+
+ public static void main(String argv[])
+ {
+ String home = LOCK_HOME;
+ boolean do_unlink = false;
+ int maxlocks = 0;
+
+ for (int i = 0; i < argv.length; ++i) {
+ if (argv[i].equals("-h")) {
+ if (++i >= argv.length)
+ usage();
+ home = argv[i];
+ }
+ else if (argv[i].equals("-m")) {
+ if (++i >= argv.length)
+ usage();
+
+ try {
+ maxlocks = Integer.parseInt(argv[i]);
+ }
+ catch (NumberFormatException nfe) {
+ usage();
+ }
+ }
+ else if (argv[i].equals("-u")) {
+ do_unlink = true;
+ }
+ else {
+ usage();
+ }
+ }
+
+ try {
+ if (do_unlink) {
+ // Create an environment that immediately
+ // removes all files.
+ LockExample tmp = new LockExample(home, maxlocks, do_unlink);
+ }
+
+ LockExample app = new LockExample(home, maxlocks, do_unlink);
+ app.run();
+ app.close(0);
+ }
+ catch (DbException dbe) {
+ System.err.println(progname + ": " + dbe.toString());
+ }
+ catch (Throwable t) {
+ System.err.println(progname + ": " + t.toString());
+ }
+ System.out.println("LockExample completed");
+ }
+}
diff --git a/db/java/src/com/sleepycat/examples/TpcbExample.java b/db/java/src/com/sleepycat/examples/TpcbExample.java
new file mode 100644
index 000000000..29a907908
--- /dev/null
+++ b/db/java/src/com/sleepycat/examples/TpcbExample.java
@@ -0,0 +1,831 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997, 1998, 1999, 2000
+ * Sleepycat Software. All rights reserved.
+ *
+ * $Id: TpcbExample.java,v 11.9 2000/04/01 15:52:15 dda Exp $
+ */
+
+package com.sleepycat.examples;
+
+import com.sleepycat.db.*;
+import java.io.FileNotFoundException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Random;
+import java.util.GregorianCalendar;
+import java.math.BigDecimal;
+
+//
+// This program implements a basic TPC/B driver program. To create the
+// TPC/B database, run with the -i (init) flag. The number of records
+// with which to populate the account, history, branch, and teller tables
+// is specified by the a, s, b, and t flags respectively. To run a TPC/B
+// test, use the n flag to indicate a number of transactions to run (note
+// that you can run many of these processes in parallel to simulate a
+// multiuser test run).
+//
+class TpcbExample extends DbEnv
+{
+ public static final int TELLERS_PER_BRANCH = 10;
+ public static final int ACCOUNTS_PER_TELLER = 10000;
+ public static final int HISTORY_PER_BRANCH = 2592000;
+
+ //
+ // The default configuration that adheres to TPCB scaling rules requires
+ // nearly 3 GB of space. To avoid requiring that much space for testing,
+ // we set the parameters much lower. If you want to run a valid 10 TPS
+ // configuration, uncomment the VALID_SCALING configuration
+ //
+
+ // VALID_SCALING configuration
+ /*
+ public static final int ACCOUNTS = 1000000;
+ public static final int BRANCHES = 10;
+ public static final int TELLERS = 100;
+ public static final int HISTORY = 25920000;
+ */
+
+ // TINY configuration
+ /*
+ public static final int ACCOUNTS = 1000;
+ public static final int BRANCHES = 10;
+ public static final int TELLERS = 100;
+ public static final int HISTORY = 10000;
+ */
+
+ // Default configuration
+ public static final int ACCOUNTS = 100000;
+ public static final int BRANCHES = 10;
+ public static final int TELLERS = 100;
+ public static final int HISTORY = 259200;
+
+ public static final int HISTORY_LEN = 100;
+ public static final int RECLEN = 100;
+ public static final int BEGID = 1000000;
+
+ // used by random_id()
+ public static final int ACCOUNT = 0;
+ public static final int BRANCH = 1;
+ public static final int TELLER = 2;
+
+ private static boolean verbose = false;
+ private static final String progname = "TpcbExample"; // Program name.
+
+ public TpcbExample(String home, int cachesize,
+ boolean initializing, int flags)
+ throws DbException, FileNotFoundException
+ {
+ super(0);
+ set_error_stream(System.err);
+ set_errpfx(progname);
+ set_cachesize(0, cachesize == 0 ? 4 * 1024 * 1024 : cachesize, 0);
+
+ int local_flags = flags | Db.DB_CREATE;
+ if (initializing)
+ local_flags |= Db.DB_INIT_MPOOL;
+ else
+ local_flags |= Db.DB_INIT_TXN | Db.DB_INIT_LOCK |
+ Db.DB_INIT_LOG | Db.DB_INIT_MPOOL;
+
+ open(home, local_flags, 0); // may throw DbException
+ }
+
+ //
+ // Initialize the database to the specified number of accounts, branches,
+ // history records, and tellers.
+ //
+ // Note: num_h was unused in the original ex_tpcb.c example.
+ //
+ public void
+ populate(int num_a, int num_b, int num_h, int num_t)
+ {
+ Db dbp = null;
+
+ int err;
+ int balance, idnum;
+ int end_anum, end_bnum, end_tnum;
+ int start_anum, start_bnum, start_tnum;
+ int h_nelem;
+
+ idnum = BEGID;
+ balance = 500000;
+
+ h_nelem = num_a;
+
+ try {
+ dbp = new Db(this, 0);
+ dbp.set_h_nelem(h_nelem);
+ dbp.open("account", null,
+ Db.DB_HASH, Db.DB_CREATE | Db.DB_TRUNCATE, 0644);
+ }
+ // can be DbException or FileNotFoundException
+ catch (Exception e1) {
+ errExit(e1, "Open of account file failed");
+ }
+
+ start_anum = idnum;
+ populateTable(dbp, idnum, balance, h_nelem, "account");
+ idnum += h_nelem;
+ end_anum = idnum - 1;
+ try {
+ dbp.close(0);
+ }
+ catch (DbException e2) {
+ errExit(e2, "Account file close failed");
+ }
+
+ if (verbose)
+ System.out.println("Populated accounts: "
+ + String.valueOf(start_anum) + " - " + String.valueOf(end_anum));
+
+ //
+ // Since the number of branches is very small, we want to use very
+ // small pages and only 1 key per page. This is the poor-man's way
+ // of getting key locking instead of page locking.
+ //
+ h_nelem = (int)num_b;
+
+ try {
+ dbp = new Db(this, 0);
+
+ dbp.set_h_nelem(h_nelem);
+ dbp.set_h_ffactor(1);
+ dbp.set_pagesize(512);
+
+ dbp.open("branch", null,
+ Db.DB_HASH, Db.DB_CREATE | Db.DB_TRUNCATE, 0644);
+ }
+ // can be DbException or FileNotFoundException
+ catch (Exception e3) {
+ errExit(e3, "Branch file create failed");
+ }
+ start_bnum = idnum;
+ populateTable(dbp, idnum, balance, h_nelem, "branch");
+ idnum += h_nelem;
+ end_bnum = idnum - 1;
+
+ try {
+ dbp.close(0);
+ }
+ catch (DbException dbe4) {
+ errExit(dbe4, "Close of branch file failed");
+ }
+
+ if (verbose)
+ System.out.println("Populated branches: "
+ + String.valueOf(start_bnum) + " - " + String.valueOf(end_bnum));
+
+ //
+ // In the case of tellers, we also want small pages, but we'll let
+ // the fill factor dynamically adjust itself.
+ //
+ h_nelem = (int)num_t;
+
+ try {
+
+ dbp = new Db(this, 0);
+
+ dbp.set_h_nelem(h_nelem);
+ dbp.set_h_ffactor(0);
+ dbp.set_pagesize(512);
+
+ dbp.open("teller", null,
+ Db.DB_HASH, Db.DB_CREATE | Db.DB_TRUNCATE, 0644);
+ }
+ // can be DbException or FileNotFoundException
+ catch (Exception e5) {
+ errExit(e5, "Teller file create failed");
+ }
+
+ start_tnum = idnum;
+ populateTable(dbp, idnum, balance, h_nelem, "teller");
+ idnum += h_nelem;
+ end_tnum = idnum - 1;
+
+ try {
+ dbp.close(0);
+ }
+ catch (DbException e6) {
+ errExit(e6, "Close of teller file failed");
+ }
+
+ if (verbose)
+ System.out.println("Populated tellers: "
+ + String.valueOf(start_tnum) + " - " + String.valueOf(end_tnum));
+
+ try {
+ dbp = new Db(this, 0);
+ dbp.set_re_len(HISTORY_LEN);
+ dbp.open("history", null,
+ Db.DB_RECNO, Db.DB_CREATE | Db.DB_TRUNCATE, 0644);
+ }
+ // can be DbException or FileNotFoundException
+ catch (Exception e7) {
+ errExit(e7, "Create of history file failed");
+ }
+
+ populateHistory(dbp, num_h, num_a, num_b, num_t);
+
+ try {
+ dbp.close(0);
+ }
+ catch (DbException e8) {
+ errExit(e8, "Close of history file failed");
+ }
+ }
+
+ public void
+ populateTable(Db dbp,
+ int start_id, int balance,
+ int nrecs, String msg)
+ {
+ Defrec drec = new Defrec();
+
+ Dbt kdbt = new Dbt(drec.data);
+ kdbt.set_size(4); // sizeof(int)
+ Dbt ddbt = new Dbt(drec.data);
+ ddbt.set_size(drec.data.length); // uses whole array
+
+ try {
+ for (int i = 0; i < nrecs; i++) {
+ kdbt.set_recno_key_data(start_id + (int)i);
+ drec.set_balance(balance);
+ dbp.put(null, kdbt, ddbt, Db.DB_NOOVERWRITE);
+ }
+ }
+ catch (DbException dbe) {
+ System.err.println("Failure initializing " + msg + " file: " +
+ dbe.toString());
+ System.exit(1);
+ }
+ }
+
+ public void
+ populateHistory(Db dbp, int nrecs,
+ int anum, int bnum, int tnum)
+ {
+ Histrec hrec = new Histrec();
+ hrec.set_amount(10);
+
+ byte arr[] = new byte[4]; // sizeof(int)
+ int i;
+ Dbt kdbt = new Dbt(arr);
+ kdbt.set_size(arr.length);
+ Dbt ddbt = new Dbt(hrec.data);
+ ddbt.set_size(hrec.data.length);
+
+ try {
+ for (i = 1; i <= nrecs; i++) {
+ kdbt.set_recno_key_data(i);
+
+ hrec.set_aid(random_id(ACCOUNT, anum, bnum, tnum));
+ hrec.set_bid(random_id(BRANCH, anum, bnum, tnum));
+ hrec.set_tid(random_id(TELLER, anum, bnum, tnum));
+
+ dbp.put(null, kdbt, ddbt, Db.DB_APPEND);
+ }
+ }
+ catch (DbException dbe) {
+ errExit(dbe, "Failure initializing history file");
+ }
+ }
+
+ static Random rand = new Random();
+
+ public static int
+ random_int(int lo, int hi)
+ {
+ int ret;
+ int t;
+
+ t = rand.nextInt();
+ if (t < 0)
+ t = -t;
+ ret = (int)(((double)t / ((double)(Integer.MAX_VALUE) + 1)) *
+ (hi - lo + 1));
+ ret += lo;
+ return (ret);
+ }
+
+ public static int
+ random_id(int type, int accounts, int branches, int tellers)
+ {
+ int min, max, num;
+
+ max = min = BEGID;
+ num = accounts;
+ switch(type) {
+ case TELLER:
+ min += branches;
+ num = tellers;
+ // Fallthrough
+ case BRANCH:
+ if (type == BRANCH)
+ num = branches;
+ min += accounts;
+ // Fallthrough
+ case ACCOUNT:
+ max = min + num - 1;
+ }
+ return (random_int(min, max));
+ }
+
+ public void
+ run(int n, int accounts, int branches, int tellers)
+ {
+ Db adb = null;
+ Db bdb = null;
+ Db hdb = null;
+ Db tdb = null;
+ double gtps, itps;
+ int failed, ifailed, ret, txns;
+ long starttime, curtime, lasttime;
+
+ //
+ // Open the database files.
+ //
+ int err;
+ try {
+ adb = new Db(this, 0);
+ adb.open("account", null, Db.DB_UNKNOWN, 0, 0);
+ bdb = new Db(this, 0);
+ bdb.open("branch", null, Db.DB_UNKNOWN, 0, 0);
+ tdb = new Db(this, 0);
+ tdb.open("teller", null, Db.DB_UNKNOWN, 0, 0);
+ hdb = new Db(this, 0);
+ hdb.open("history", null, Db.DB_UNKNOWN, 0, 0);
+ }
+ catch (DbException dbe) {
+ errExit(dbe, "Open of db files failed");
+ }
+ catch (FileNotFoundException fnfe) {
+ errExit(fnfe, "Open of db files failed, missing file");
+ }
+
+ txns = failed = ifailed = 0;
+ starttime = (new Date()).getTime();
+ lasttime = starttime;
+ while (n-- > 0) {
+ txns++;
+ ret = txn(adb, bdb, tdb, hdb, accounts, branches, tellers);
+ if (ret != 0) {
+ failed++;
+ ifailed++;
+ }
+ if (n % 5000 == 0) {
+ curtime = (new Date()).getTime();
+ gtps = (double)(txns - failed) /
+ ((curtime - starttime) / 1000.0);
+ itps = (double)(5000 - ifailed) /
+ ((curtime - lasttime) / 1000.0);
+ System.out.print(String.valueOf(txns) + " txns " +
+ String.valueOf(failed) + " failed ");
+ System.out.println(showRounded(gtps, 2) + " TPS (gross) " +
+ showRounded(itps, 2) + " TPS (interval)");
+ lasttime = curtime;
+ ifailed = 0;
+ }
+ }
+
+ try {
+ adb.close(0);
+ bdb.close(0);
+ tdb.close(0);
+ hdb.close(0);
+ }
+ catch (DbException dbe2) {
+ errExit(dbe2, "Close of db files failed");
+ }
+
+ System.out.println((long)txns + " transactions begun "
+ + String.valueOf(failed) + " failed");
+
+ }
+
+ //
+ // XXX Figure out the appropriate way to pick out IDs.
+ //
+ public int
+ txn(Db adb, Db bdb, Db tdb, Db hdb,
+ int anum, int bnum, int tnum)
+ {
+ Dbc acurs = null;
+ Dbc bcurs = null;
+ Dbc hcurs = null;
+ Dbc tcurs = null;
+ DbTxn t = null;
+
+ Defrec rec = new Defrec();
+ Histrec hrec = new Histrec();
+ int account, branch, teller;
+
+ Dbt d_dbt = new Dbt();
+ Dbt d_histdbt = new Dbt();
+ Dbt k_dbt = new Dbt();
+ Dbt k_histdbt = new Dbt();
+
+ account = random_id(ACCOUNT, anum, bnum, tnum);
+ branch = random_id(BRANCH, anum, bnum, tnum);
+ teller = random_id(TELLER, anum, bnum, tnum);
+
+ // The history key will not actually be retrieved,
+ // but it does need to be set to something.
+ byte hist_key[] = new byte[4];
+ k_histdbt.set_data(hist_key);
+ k_histdbt.set_size(4 /* == sizeof(int)*/);
+
+ byte key_bytes[] = new byte[4];
+ k_dbt.set_data(key_bytes);
+ k_dbt.set_size(4 /* == sizeof(int)*/);
+
+ d_dbt.set_flags(Db.DB_DBT_USERMEM);
+ d_dbt.set_data(rec.data);
+ d_dbt.set_ulen(rec.length());
+
+ hrec.set_aid(account);
+ hrec.set_bid(branch);
+ hrec.set_tid(teller);
+ hrec.set_amount(10);
+ // Request 0 bytes since we're just positioning.
+ d_histdbt.set_flags(Db.DB_DBT_PARTIAL);
+
+ // START TIMING
+
+ try {
+ t = txn_begin(null, 0);
+
+ acurs = adb.cursor(t, 0);
+ bcurs = bdb.cursor(t, 0);
+ tcurs = tdb.cursor(t, 0);
+ hcurs = hdb.cursor(t, 0);
+
+ // Account record
+ k_dbt.set_recno_key_data(account);
+ if (acurs.get(k_dbt, d_dbt, Db.DB_SET) != 0)
+ throw new TpcbException("acurs get failed");
+ rec.set_balance(rec.get_balance() + 10);
+ acurs.put(k_dbt, d_dbt, Db.DB_CURRENT);
+
+ // Branch record
+ k_dbt.set_recno_key_data(branch);
+ if (bcurs.get(k_dbt, d_dbt, Db.DB_SET) != 0)
+ throw new TpcbException("bcurs get failed");
+ rec.set_balance(rec.get_balance() + 10);
+ bcurs.put(k_dbt, d_dbt, Db.DB_CURRENT);
+
+ // Teller record
+ k_dbt.set_recno_key_data(teller);
+ if (tcurs.get(k_dbt, d_dbt, Db.DB_SET) != 0)
+ throw new TpcbException("ccurs get failed");
+ rec.set_balance(rec.get_balance() + 10);
+ tcurs.put(k_dbt, d_dbt, Db.DB_CURRENT);
+
+ // History record
+ d_histdbt.set_flags(0);
+ d_histdbt.set_data(hrec.data);
+ d_histdbt.set_ulen(hrec.length());
+ if (hdb.put(t, k_histdbt, d_histdbt, Db.DB_APPEND) != 0)
+ throw(new DbException("put failed"));
+
+ acurs.close();
+ bcurs.close();
+ tcurs.close();
+ hcurs.close();
+
+ t.commit(0);
+
+ // END TIMING
+ return (0);
+
+ }
+ catch (Exception e) {
+ try {
+ if (acurs != null)
+ acurs.close();
+ if (bcurs != null)
+ bcurs.close();
+ if (tcurs != null)
+ tcurs.close();
+ if (hcurs != null)
+ hcurs.close();
+ if (t != null)
+ t.abort();
+ }
+ catch (DbException dbe) {
+ // not much we can do here.
+ }
+
+ if (verbose) {
+ System.out.println("Transaction A=" + String.valueOf(account)
+ + " B=" + String.valueOf(branch)
+ + " T=" + String.valueOf(teller) + " failed");
+ System.out.println("Reason: " + e.toString());
+ }
+ return (-1);
+ }
+ }
+
+ static void errExit(Exception err, String s)
+ {
+ System.err.print(progname + ": ");
+ if (s != null) {
+ System.err.print(s + ": ");
+ }
+ System.err.println(err.toString());
+ System.exit(1);
+ }
+
+ public static void main(String argv[])
+ {
+ long seed;
+ int accounts, branches, tellers, history;
+ boolean iflag, txn_no_sync;
+ int mpool, ntxns;
+ String home, endarg;
+
+ home = "TESTDIR";
+ accounts = branches = history = tellers = 0;
+ txn_no_sync = false;
+ mpool = ntxns = 0;
+ verbose = false;
+ iflag = false;
+ seed = (new GregorianCalendar()).get(Calendar.SECOND);
+
+ for (int i = 0; i < argv.length; ++i)
+ {
+ if (argv[i].equals("-a")) {
+ // Number of account records
+ if ((accounts = Integer.parseInt(argv[++i])) <= 0)
+ invarg(argv[i]);
+ }
+ else if (argv[i].equals("-b")) {
+ // Number of branch records
+ if ((branches = Integer.parseInt(argv[++i])) <= 0)
+ invarg(argv[i]);
+ }
+ else if (argv[i].equals("-c")) {
+ // Cachesize in bytes
+ if ((mpool = Integer.parseInt(argv[++i])) <= 0)
+ invarg(argv[i]);
+ }
+ else if (argv[i].equals("-f")) {
+ // Fast mode: no txn sync.
+ txn_no_sync = true;
+ }
+ else if (argv[i].equals("-h")) {
+ // DB home.
+ home = argv[++i];
+ }
+ else if (argv[i].equals("-i")) {
+ // Initialize the test.
+ iflag = true;
+ }
+ else if (argv[i].equals("-n")) {
+ // Number of transactions
+ if ((ntxns = Integer.parseInt(argv[++i])) <= 0)
+ invarg(argv[i]);
+ }
+ else if (argv[i].equals("-S")) {
+ // Random number seed.
+ seed = Long.parseLong(argv[++i]);
+ if (seed <= 0)
+ invarg(argv[i]);
+ }
+ else if (argv[i].equals("-s")) {
+ // Number of history records
+ if ((history = Integer.parseInt(argv[++i])) <= 0)
+ invarg(argv[i]);
+ }
+ else if (argv[i].equals("-t")) {
+ // Number of teller records
+ if ((tellers = Integer.parseInt(argv[++i])) <= 0)
+ invarg(argv[i]);
+ }
+ else if (argv[i].equals("-v")) {
+ // Verbose option.
+ verbose = true;
+ }
+ else
+ {
+ usage();
+ }
+ }
+
+ rand.setSeed((int)seed);
+
+ TpcbExample app = null;
+
+ // Initialize the database environment.
+ // Must be done in within a try block.
+ //
+ try {
+ app = new TpcbExample(home, mpool, iflag,
+ txn_no_sync ? Db.DB_TXN_NOSYNC : 0);
+ }
+ catch (Exception e1) {
+ errExit(e1, "initializing environment failed");
+ }
+
+ accounts = accounts == 0 ? ACCOUNTS : accounts;
+ branches = branches == 0 ? BRANCHES : branches;
+ tellers = tellers == 0 ? TELLERS : tellers;
+ history = history == 0 ? HISTORY : history;
+
+ if (verbose)
+ System.out.println((long)accounts + " Accounts "
+ + String.valueOf(branches) + " Branches "
+ + String.valueOf(tellers) + " Tellers "
+ + String.valueOf(history) + " History");
+
+ if (iflag) {
+ if (ntxns != 0)
+ usage();
+ app.populate(accounts, branches, history, tellers);
+ }
+ else {
+ if (ntxns == 0)
+ usage();
+ app.run(ntxns, accounts, branches, tellers);
+ }
+
+ // Shut down the application.
+
+ try {
+ app.close(0);
+ }
+ catch (DbException dbe2) {
+ errExit(dbe2, "appexit failed");
+ }
+
+ System.exit(0);
+ }
+
+ private static void invarg(String str)
+ {
+ System.err.println("TpcbExample: invalid argument: " + str);
+ System.exit(1);
+ }
+
+ private static void usage()
+ {
+ System.err.println(
+ "usage: TpcbExample [-fiv] [-a accounts] [-b branches]\n" +
+ " [-c cachesize] [-h home] [-n transactions ]\n" +
+ " [-S seed] [-s history] [-t tellers]");
+ System.exit(1);
+ }
+
+ // round 'd' to 'scale' digits, and return result as string
+ private String showRounded(double d, int scale)
+ {
+ return new BigDecimal(d).
+ setScale(scale, BigDecimal.ROUND_HALF_DOWN).toString();
+ }
+
+ // The byte order is our choice.
+ //
+ static long get_int_in_array(byte[] array, int offset)
+ {
+ return
+ ((0xff & array[offset+0]) << 0) |
+ ((0xff & array[offset+1]) << 8) |
+ ((0xff & array[offset+2]) << 16) |
+ ((0xff & array[offset+3]) << 24);
+ }
+
+ // Note: Value needs to be long to avoid sign extension
+ static void set_int_in_array(byte[] array, int offset, long value)
+ {
+ array[offset+0] = (byte)((value >> 0) & 0x0ff);
+ array[offset+1] = (byte)((value >> 8) & 0x0ff);
+ array[offset+2] = (byte)((value >> 16) & 0x0ff);
+ array[offset+3] = (byte)((value >> 24) & 0x0ff);
+ }
+
+};
+
+// Simulate the following C struct:
+// struct Defrec {
+// u_int32_t id;
+// u_int32_t balance;
+// u_int8_t pad[RECLEN - sizeof(int) - sizeof(int)];
+// };
+
+class Defrec
+{
+ public Defrec()
+ {
+ data = new byte[TpcbExample.RECLEN];
+ }
+
+ public int length()
+ {
+ return TpcbExample.RECLEN;
+ }
+
+ public long get_id()
+ {
+ return TpcbExample.get_int_in_array(data, 0);
+ }
+
+ public void set_id(long value)
+ {
+ TpcbExample.set_int_in_array(data, 0, value);
+ }
+
+ public long get_balance()
+ {
+ return TpcbExample.get_int_in_array(data, 4);
+ }
+
+ public void set_balance(long value)
+ {
+ TpcbExample.set_int_in_array(data, 4, value);
+ }
+
+ static {
+ Defrec d = new Defrec();
+ d.set_balance(500000);
+ }
+
+ public byte[] data;
+}
+
+// Simulate the following C struct:
+// struct Histrec {
+// u_int32_t aid;
+// u_int32_t bid;
+// u_int32_t tid;
+// u_int32_t amount;
+// u_int8_t pad[RECLEN - 4 * sizeof(u_int32_t)];
+// };
+
+class Histrec
+{
+ public Histrec()
+ {
+ data = new byte[TpcbExample.RECLEN];
+ }
+
+ public int length()
+ {
+ return TpcbExample.RECLEN;
+ }
+
+ public long get_aid()
+ {
+ return TpcbExample.get_int_in_array(data, 0);
+ }
+
+ public void set_aid(long value)
+ {
+ TpcbExample.set_int_in_array(data, 0, value);
+ }
+
+ public long get_bid()
+ {
+ return TpcbExample.get_int_in_array(data, 4);
+ }
+
+ public void set_bid(long value)
+ {
+ TpcbExample.set_int_in_array(data, 4, value);
+ }
+
+ public long get_tid()
+ {
+ return TpcbExample.get_int_in_array(data, 8);
+ }
+
+ public void set_tid(long value)
+ {
+ TpcbExample.set_int_in_array(data, 8, value);
+ }
+
+ public long get_amount()
+ {
+ return TpcbExample.get_int_in_array(data, 12);
+ }
+
+ public void set_amount(long value)
+ {
+ TpcbExample.set_int_in_array(data, 12, value);
+ }
+
+ public byte[] data;
+}
+
+class TpcbException extends Exception
+{
+ TpcbException()
+ {
+ super();
+ }
+
+ TpcbException(String s)
+ {
+ super(s);
+ }
+}