00001
00002
00003
00004
00005
00006
00007
00008
00009 package com.sleepycat.db.internal;
00010
00011 import com.sleepycat.db.*;
00012 import java.util.Comparator;
00013
00014 public class Db {
00015 private long swigCPtr;
00016 protected boolean swigCMemOwn;
00017
00018 protected Db(long cPtr, boolean cMemoryOwn) {
00019 swigCMemOwn = cMemoryOwn;
00020 swigCPtr = cPtr;
00021 }
00022
00023 protected static long getCPtr(Db obj) {
00024 return (obj == null) ? 0 : obj.swigCPtr;
00025 }
00026
00027 void delete() {
00028 if(swigCPtr != 0 && swigCMemOwn) {
00029 swigCMemOwn = false;
00030 throw new UnsupportedOperationException("C++ destructor does not have public access");
00031 }
00032 swigCPtr = 0;
00033 }
00034
00035 static final int GIGABYTE = 1 << 30;
00036
00037
00038
00039
00040
00041 private long db_ref;
00042 private DbEnv dbenv;
00043 private boolean private_dbenv;
00044
00045 public Database wrapper;
00046 private RecordNumberAppender append_recno_handler;
00047 private Comparator bt_compare_handler;
00048 private BtreePrefixCalculator bt_prefix_handler;
00049 private Comparator dup_compare_handler;
00050 private FeedbackHandler db_feedback_handler;
00051 private Hasher h_hash_handler;
00052 private SecondaryKeyCreator seckey_create_handler;
00053
00054
00055 private void initialize(DbEnv dbenv) {
00056 if (dbenv == null) {
00057 private_dbenv = true;
00058 dbenv = db_java.getDbEnv0(this);
00059 dbenv.initialize();
00060 }
00061 this.dbenv = dbenv;
00062 db_ref = db_java.initDbRef0(this, this);
00063 }
00064
00065 private void cleanup() {
00066 swigCPtr = 0;
00067 db_java.deleteRef0(db_ref);
00068 db_ref = 0L;
00069 if (private_dbenv)
00070 dbenv.cleanup();
00071 dbenv = null;
00072 }
00073
00074 public synchronized void close(int flags) throws DatabaseException {
00075 try {
00076 close0(flags);
00077 } finally {
00078 cleanup();
00079 }
00080 }
00081
00082 public DbEnv get_env() throws DatabaseException {
00083 return dbenv;
00084 }
00085
00086 private final void handle_append_recno(DatabaseEntry data, int recno)
00087 throws DatabaseException {
00088 append_recno_handler.appendRecordNumber(wrapper, data, recno);
00089 }
00090
00091 public RecordNumberAppender get_append_recno() throws com.sleepycat.db.DatabaseException {
00092 return append_recno_handler;
00093 }
00094
00095 private final int handle_bt_compare(byte[] arr1, byte[] arr2) {
00096 return bt_compare_handler.compare(arr1, arr2);
00097 }
00098
00099 public Comparator get_bt_compare() throws com.sleepycat.db.DatabaseException {
00100 return bt_compare_handler;
00101 }
00102
00103 private final int handle_bt_prefix(DatabaseEntry dbt1,
00104 DatabaseEntry dbt2) {
00105 return bt_prefix_handler.prefix(wrapper, dbt1, dbt2);
00106 }
00107
00108 public BtreePrefixCalculator get_bt_prefix() throws com.sleepycat.db.DatabaseException {
00109 return bt_prefix_handler;
00110 }
00111
00112 private final void handle_db_feedback(int opcode, int percent) {
00113 if (opcode == DbConstants.DB_UPGRADE)
00114 db_feedback_handler.upgradeFeedback(wrapper, percent);
00115 else if (opcode == DbConstants.DB_VERIFY)
00116 db_feedback_handler.upgradeFeedback(wrapper, percent);
00117
00118 }
00119
00120 public FeedbackHandler get_feedback() throws com.sleepycat.db.DatabaseException {
00121 return db_feedback_handler;
00122 }
00123
00124 private final int handle_dup_compare(byte[] arr1, byte[] arr2) {
00125 return dup_compare_handler.compare(arr1, arr2);
00126 }
00127
00128 public Comparator get_dup_compare() throws com.sleepycat.db.DatabaseException {
00129 return dup_compare_handler;
00130 }
00131
00132 private final int handle_h_hash(byte[] data, int len) {
00133 return h_hash_handler.hash(wrapper, data, len);
00134 }
00135
00136 public Hasher get_h_hash() throws com.sleepycat.db.DatabaseException {
00137 return h_hash_handler;
00138 }
00139
00140 private final int handle_seckey_create(DatabaseEntry key,
00141 DatabaseEntry data,
00142 DatabaseEntry result)
00143 throws DatabaseException {
00144 return seckey_create_handler.createSecondaryKey(
00145 (SecondaryDatabase)wrapper, key, data, result) ?
00146 0 : DbConstants.DB_DONOTINDEX;
00147 }
00148
00149 public SecondaryKeyCreator get_seckey_create() throws com.sleepycat.db.DatabaseException {
00150 return seckey_create_handler;
00151 }
00152
00153 public synchronized void remove(String file, String database, int flags)
00154 throws DatabaseException, java.io.FileNotFoundException {
00155 try {
00156 remove0(file, database, flags);
00157 } finally {
00158 cleanup();
00159 }
00160 }
00161
00162 public synchronized void rename(String file, String database,
00163 String newname, int flags)
00164 throws DatabaseException, java.io.FileNotFoundException {
00165 try {
00166 rename0(file, database, newname, flags);
00167 } finally {
00168 cleanup();
00169 }
00170 }
00171
00172 public synchronized boolean verify(String file, String database,
00173 java.io.OutputStream outfile, int flags)
00174 throws DatabaseException, java.io.FileNotFoundException {
00175 try {
00176 return verify0(file, database, outfile, flags);
00177 } finally {
00178 cleanup();
00179 }
00180 }
00181
00182 public ErrorHandler get_errcall() {
00183 return dbenv.get_errcall();
00184 }
00185
00186 public void set_errcall(ErrorHandler db_errcall_fcn) {
00187 dbenv.set_errcall(db_errcall_fcn);
00188 }
00189
00190 public java.io.OutputStream get_error_stream() {
00191 return dbenv.get_error_stream();
00192 }
00193
00194 public void set_error_stream(java.io.OutputStream stream) {
00195 dbenv.set_error_stream(stream);
00196 }
00197
00198 public void set_errpfx(String errpfx) {
00199 dbenv.set_errpfx(errpfx);
00200 }
00201
00202 public String get_errpfx() {
00203 return dbenv.get_errpfx();
00204 }
00205
00206 public java.io.OutputStream get_message_stream() {
00207 return dbenv.get_message_stream();
00208 }
00209
00210 public void set_message_stream(java.io.OutputStream stream) {
00211 dbenv.set_message_stream(stream);
00212 }
00213
00214 public MessageHandler get_msgcall() {
00215 return dbenv.get_msgcall();
00216 }
00217
00218 public void set_msgcall(MessageHandler db_msgcall_fcn) {
00219 dbenv.set_msgcall(db_msgcall_fcn);
00220 }
00221
00222 public void set_paniccall(PanicHandler db_panic_fcn)
00223 throws DatabaseException {
00224 dbenv.set_paniccall(db_panic_fcn);
00225 }
00226
00227 public PanicHandler get_paniccall() throws com.sleepycat.db.DatabaseException {
00228 return dbenv.get_paniccall();
00229 }
00230
00231 public Db(DbEnv dbenv, int flags) throws com.sleepycat.db.DatabaseException {
00232 this(db_javaJNI.new_Db(DbEnv.getCPtr(dbenv), flags), true);
00233 initialize(dbenv);
00234 }
00235
00236 public void associate(DbTxn txnid, Db secondary, com.sleepycat.db.SecondaryKeyCreator callback, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_associate(swigCPtr, DbTxn.getCPtr(txnid), Db.getCPtr(secondary), (secondary.seckey_create_handler = callback) , flags); }
00237
00238 public void compact(DbTxn txnid, com.sleepycat.db.DatabaseEntry start, com.sleepycat.db.DatabaseEntry stop, com.sleepycat.db.CompactStats c_data, int flags, com.sleepycat.db.DatabaseEntry end) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_compact(swigCPtr, DbTxn.getCPtr(txnid), start, stop, c_data, flags, end); }
00239
00240 int close0(int flags) {
00241 return db_javaJNI.Db_close0(swigCPtr, flags);
00242 }
00243
00244 public Dbc cursor(DbTxn txnid, int flags) throws com.sleepycat.db.DatabaseException {
00245 long cPtr = db_javaJNI.Db_cursor(swigCPtr, DbTxn.getCPtr(txnid), flags);
00246 return (cPtr == 0) ? null : new Dbc(cPtr, false);
00247 }
00248
00249 public int del(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, int flags) throws com.sleepycat.db.DatabaseException {
00250 return db_javaJNI.Db_del(swigCPtr, DbTxn.getCPtr(txnid), key, flags);
00251 }
00252
00253 public void err(int error, String message) {
00254 db_javaJNI.Db_err(swigCPtr, error, message);
00255 }
00256
00257 public void errx(String message) {
00258 db_javaJNI.Db_errx(swigCPtr, message);
00259 }
00260
00261 public boolean get_transactional() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_transactional(swigCPtr); }
00262
00263 public int get(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, com.sleepycat.db.DatabaseEntry data, int flags) throws com.sleepycat.db.DatabaseException {
00264 return db_javaJNI.Db_get(swigCPtr, DbTxn.getCPtr(txnid), key, data, flags);
00265 }
00266
00267 public boolean get_byteswapped() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_byteswapped(swigCPtr); }
00268
00269 public long get_cachesize() throws com.sleepycat.db.DatabaseException {
00270 return db_javaJNI.Db_get_cachesize(swigCPtr);
00271 }
00272
00273 public int get_cachesize_ncache() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_cachesize_ncache(swigCPtr); }
00274
00275 public String get_filename() throws com.sleepycat.db.DatabaseException {
00276 return db_javaJNI.Db_get_filename(swigCPtr);
00277 }
00278
00279 public String get_dbname() throws com.sleepycat.db.DatabaseException {
00280 return db_javaJNI.Db_get_dbname(swigCPtr);
00281 }
00282
00283 public int get_encrypt_flags() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_encrypt_flags(swigCPtr); }
00284
00285 public int get_flags() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_flags(swigCPtr); }
00286
00287 public int get_lorder() throws com.sleepycat.db.DatabaseException {
00288 return db_javaJNI.Db_get_lorder(swigCPtr);
00289 }
00290
00291 public DbMpoolFile get_mpf() throws com.sleepycat.db.DatabaseException {
00292 long cPtr = db_javaJNI.Db_get_mpf(swigCPtr);
00293 return (cPtr == 0) ? null : new DbMpoolFile(cPtr, false);
00294 }
00295
00296 public int get_open_flags() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_open_flags(swigCPtr); }
00297
00298 public int get_pagesize() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_pagesize(swigCPtr); }
00299
00300 public int get_bt_minkey() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_bt_minkey(swigCPtr); }
00301
00302 public int get_h_ffactor() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_h_ffactor(swigCPtr); }
00303
00304 public int get_h_nelem() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_h_nelem(swigCPtr); }
00305
00306 public int get_re_delim() throws com.sleepycat.db.DatabaseException {
00307 return db_javaJNI.Db_get_re_delim(swigCPtr);
00308 }
00309
00310 public int get_re_len() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_re_len(swigCPtr); }
00311
00312 public int get_re_pad() throws com.sleepycat.db.DatabaseException {
00313 return db_javaJNI.Db_get_re_pad(swigCPtr);
00314 }
00315
00316 public String get_re_source() throws com.sleepycat.db.DatabaseException {
00317 return db_javaJNI.Db_get_re_source(swigCPtr);
00318 }
00319
00320 public int get_q_extentsize() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_q_extentsize(swigCPtr); }
00321
00322 public int get_type() throws com.sleepycat.db.DatabaseException {
00323 return db_javaJNI.Db_get_type(swigCPtr);
00324 }
00325
00326 public Dbc join(Dbc[] curslist, int flags) throws com.sleepycat.db.DatabaseException {
00327 long cPtr = db_javaJNI.Db_join(swigCPtr, curslist, flags);
00328 return (cPtr == 0) ? null : new Dbc(cPtr, true);
00329 }
00330
00331 public void key_range(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, com.sleepycat.db.KeyRange key_range, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_key_range(swigCPtr, DbTxn.getCPtr(txnid), key, key_range, flags); }
00332
00333 public void open(DbTxn txnid, String file, String database, int type, int flags, int mode) throws com.sleepycat.db.DatabaseException, java.io.FileNotFoundException { db_javaJNI.Db_open(swigCPtr, DbTxn.getCPtr(txnid), file, database, type, flags, mode); }
00334
00335 public int pget(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, com.sleepycat.db.DatabaseEntry pkey, com.sleepycat.db.DatabaseEntry data, int flags) throws com.sleepycat.db.DatabaseException {
00336 return db_javaJNI.Db_pget(swigCPtr, DbTxn.getCPtr(txnid), key, pkey, data, flags);
00337 }
00338
00339 public int put(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, com.sleepycat.db.DatabaseEntry data, int flags) throws com.sleepycat.db.DatabaseException {
00340 return db_javaJNI.Db_put(swigCPtr, DbTxn.getCPtr(txnid), key, data, flags);
00341 }
00342
00343 void remove0(String file, String database, int flags) { db_javaJNI.Db_remove0(swigCPtr, file, database, flags); }
00344
00345 void rename0(String file, String database, String newname, int flags) { db_javaJNI.Db_rename0(swigCPtr, file, database, newname, flags); }
00346
00347 public void set_append_recno(com.sleepycat.db.RecordNumberAppender db_append_recno_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_append_recno(swigCPtr, (append_recno_handler = db_append_recno_fcn) ); }
00348
00349 public void set_bt_compare(java.util.Comparator bt_compare_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_bt_compare(swigCPtr, (bt_compare_handler = bt_compare_fcn) ); }
00350
00351 public void set_bt_minkey(int bt_minkey) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_bt_minkey(swigCPtr, bt_minkey); }
00352
00353 public void set_bt_prefix(com.sleepycat.db.BtreePrefixCalculator bt_prefix_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_bt_prefix(swigCPtr, (bt_prefix_handler = bt_prefix_fcn) ); }
00354
00355 public void set_cachesize(long bytes, int ncache) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_cachesize(swigCPtr, bytes, ncache); }
00356
00357 public void set_dup_compare(java.util.Comparator dup_compare_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_dup_compare(swigCPtr, (dup_compare_handler = dup_compare_fcn) ); }
00358
00359 public void set_encrypt(String passwd, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_encrypt(swigCPtr, passwd, flags); }
00360
00361 public void set_feedback(com.sleepycat.db.FeedbackHandler db_feedback_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_feedback(swigCPtr, (db_feedback_handler = db_feedback_fcn) ); }
00362
00363 public void set_flags(int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_flags(swigCPtr, flags); }
00364
00365 public void set_h_ffactor(int h_ffactor) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_h_ffactor(swigCPtr, h_ffactor); }
00366
00367 public void set_h_hash(com.sleepycat.db.Hasher h_hash_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_h_hash(swigCPtr, (h_hash_handler = h_hash_fcn) ); }
00368
00369 public void set_h_nelem(int h_nelem) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_h_nelem(swigCPtr, h_nelem); }
00370
00371 public void set_lorder(int lorder) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_lorder(swigCPtr, lorder); }
00372
00373 public void set_pagesize(long pagesize) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_pagesize(swigCPtr, pagesize); }
00374
00375 public void set_re_delim(int re_delim) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_delim(swigCPtr, re_delim); }
00376
00377 public void set_re_len(int re_len) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_len(swigCPtr, re_len); }
00378
00379 public void set_re_pad(int re_pad) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_pad(swigCPtr, re_pad); }
00380
00381 public void set_re_source(String source) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_source(swigCPtr, source); }
00382
00383 public void set_q_extentsize(int extentsize) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_q_extentsize(swigCPtr, extentsize); }
00384
00385 public Object stat(DbTxn txnid, int flags) throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_stat(swigCPtr, DbTxn.getCPtr(txnid), flags); }
00386
00387 public void sync(int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_sync(swigCPtr, flags); }
00388
00389 public int truncate(DbTxn txnid, int flags) throws com.sleepycat.db.DatabaseException {
00390 return db_javaJNI.Db_truncate(swigCPtr, DbTxn.getCPtr(txnid), flags);
00391 }
00392
00393 public void upgrade(String file, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_upgrade(swigCPtr, file, flags); }
00394
00395 boolean verify0(String file, String database, java.io.OutputStream outfile, int flags) { return db_javaJNI.Db_verify0(swigCPtr, file, database, outfile, flags); }
00396
00397 }