1/* ----------------------------------------------------------------------------
2 * This file was automatically generated by SWIG (http://www.swig.org).
3 * Version 1.3.33
4 *
5 * Do not make changes to this file unless you know what you are doing--modify
6 * the SWIG interface file instead.
7 * ----------------------------------------------------------------------------- */
8
9package com.sleepycat.db.internal;
10
11import com.sleepycat.db.*;
12import java.util.Comparator;
13
14public class Db {
15  private long swigCPtr;
16  protected boolean swigCMemOwn;
17
18  protected Db(long cPtr, boolean cMemoryOwn) {
19    swigCMemOwn = cMemoryOwn;
20    swigCPtr = cPtr;
21  }
22
23  protected static long getCPtr(Db obj) {
24    return (obj == null) ? 0 : obj.swigCPtr;
25  }
26
27  /* package */ synchronized void delete() {
28    if(swigCPtr != 0 && swigCMemOwn) {
29      swigCMemOwn = false;
30      throw new UnsupportedOperationException("C++ destructor does not have public access");
31    }
32    swigCPtr = 0;
33  }
34
35	/* package */ static final int GIGABYTE = 1 << 30;
36	/*
37	 * Internally, the JNI layer creates a global reference to each Db,
38	 * which can potentially be different to this.  We keep a copy here so
39	 * we can clean up after destructors.
40	 */
41	private long db_ref;
42	private DbEnv dbenv;
43	private boolean private_dbenv;
44
45	public Database wrapper;
46	private RecordNumberAppender append_recno_handler;
47	private Comparator bt_compare_handler;
48	private BtreePrefixCalculator bt_prefix_handler;
49	private Comparator dup_compare_handler;
50	private FeedbackHandler db_feedback_handler;
51	private Comparator h_compare_handler;
52	private Hasher h_hash_handler;
53	private SecondaryKeyCreator seckey_create_handler;
54	private SecondaryMultiKeyCreator secmultikey_create_handler;
55	private ForeignKeyNullifier foreignkey_nullify_handler;
56	private ForeignMultiKeyNullifier foreignmultikey_nullify_handler;
57
58	/* Called by the Db constructor */
59	private void initialize(DbEnv dbenv) {
60		if (dbenv == null) {
61			private_dbenv = true;
62			dbenv = db_java.getDbEnv0(this);
63			dbenv.initialize();
64		}
65		this.dbenv = dbenv;
66		db_ref = db_java.initDbRef0(this, this);
67	}
68
69	private void cleanup() {
70		swigCPtr = 0;
71		db_java.deleteRef0(db_ref);
72		db_ref = 0L;
73		if (private_dbenv)
74			dbenv.cleanup();
75		dbenv = null;
76	}
77
78	public boolean getPrivateDbEnv() throws com.sleepycat.db.DatabaseException {
79		return private_dbenv;
80	}
81
82	public synchronized void close(int flags) throws DatabaseException {
83		try {
84			close0(flags);
85		} finally {
86			cleanup();
87		}
88	}
89
90	public DbEnv get_env() throws DatabaseException {
91		return dbenv;
92	}
93
94	private final void handle_append_recno(DatabaseEntry data, int recno)
95	    throws DatabaseException {
96		append_recno_handler.appendRecordNumber(wrapper, data, recno);
97	}
98
99	public RecordNumberAppender get_append_recno() throws com.sleepycat.db.DatabaseException {
100		return append_recno_handler;
101	}
102
103	private final int handle_bt_compare(byte[] arr1, byte[] arr2) {
104		return bt_compare_handler.compare(arr1, arr2);
105	}
106
107	public Comparator get_bt_compare() throws com.sleepycat.db.DatabaseException {
108		return bt_compare_handler;
109	}
110
111	private final int handle_bt_prefix(DatabaseEntry dbt1,
112					   DatabaseEntry dbt2) {
113		return bt_prefix_handler.prefix(wrapper, dbt1, dbt2);
114	}
115
116	public BtreePrefixCalculator get_bt_prefix() throws com.sleepycat.db.DatabaseException {
117		return bt_prefix_handler;
118	}
119
120	private final void handle_db_feedback(int opcode, int percent) {
121		if (opcode == DbConstants.DB_UPGRADE)
122			db_feedback_handler.upgradeFeedback(wrapper, percent);
123		else if (opcode == DbConstants.DB_VERIFY)
124			db_feedback_handler.upgradeFeedback(wrapper, percent);
125		/* No other database feedback types known. */
126	}
127
128	public FeedbackHandler get_feedback() throws com.sleepycat.db.DatabaseException {
129		return db_feedback_handler;
130	}
131
132	private final int handle_h_compare(byte[] arr1, byte[] arr2) {
133		return h_compare_handler.compare(arr1, arr2);
134	}
135
136	public Comparator get_h_compare() throws com.sleepycat.db.DatabaseException {
137		return h_compare_handler;
138	}
139
140	private final int handle_dup_compare(byte[] arr1, byte[] arr2) {
141		return dup_compare_handler.compare(arr1, arr2);
142	}
143
144	public Comparator get_dup_compare() throws com.sleepycat.db.DatabaseException {
145		return dup_compare_handler;
146	}
147
148	private final int handle_h_hash(byte[] data, int len) {
149		return h_hash_handler.hash(wrapper, data, len);
150	}
151
152	public Hasher get_h_hash() throws com.sleepycat.db.DatabaseException {
153		return h_hash_handler;
154	}
155
156	private final boolean handle_foreignkey_nullify(
157					       DatabaseEntry key,
158					       DatabaseEntry data,
159					       DatabaseEntry seckey)
160	    throws DatabaseException {
161		if (foreignmultikey_nullify_handler != null)
162			return foreignmultikey_nullify_handler.nullifyForeignKey(
163			    (SecondaryDatabase)wrapper, key, data, seckey);
164		else
165			return foreignkey_nullify_handler.nullifyForeignKey(
166			    (SecondaryDatabase)wrapper, data);
167	}
168
169	private final DatabaseEntry[] handle_seckey_create(
170					       DatabaseEntry key,
171					       DatabaseEntry data)
172	    throws DatabaseException {
173
174		if (secmultikey_create_handler != null) {
175			java.util.HashSet keySet = new java.util.HashSet();
176			secmultikey_create_handler.createSecondaryKeys(
177			    (SecondaryDatabase)wrapper, key, data, keySet);
178			if (!keySet.isEmpty())
179				return (DatabaseEntry[])keySet.toArray(
180				    new DatabaseEntry[keySet.size()]);
181		} else {
182			DatabaseEntry result = new DatabaseEntry();
183			if (seckey_create_handler.createSecondaryKey(
184			    (SecondaryDatabase)wrapper, key, data, result)) {
185				DatabaseEntry[] results = { result };
186				return results;
187			}
188		}
189
190		return null;
191	}
192
193	public SecondaryKeyCreator get_seckey_create() throws com.sleepycat.db.DatabaseException {
194		return seckey_create_handler;
195	}
196
197	public SecondaryMultiKeyCreator get_secmultikey_create() throws com.sleepycat.db.DatabaseException {
198		return secmultikey_create_handler;
199	}
200
201	public void set_secmultikey_create(
202	    SecondaryMultiKeyCreator secmultikey_create_handler) {
203		this.secmultikey_create_handler = secmultikey_create_handler;
204	}
205
206	public void set_foreignmultikey_nullifier(ForeignMultiKeyNullifier nullify){
207		this.foreignmultikey_nullify_handler = nullify;
208	}
209
210	public synchronized void remove(String file, String database, int flags)
211	    throws DatabaseException, java.io.FileNotFoundException {
212		try {
213			remove0(file, database, flags);
214		} finally {
215			cleanup();
216		}
217	}
218
219	public synchronized void rename(String file, String database,
220	    String newname, int flags)
221	    throws DatabaseException, java.io.FileNotFoundException {
222		try {
223			rename0(file, database, newname, flags);
224		} finally {
225			cleanup();
226		}
227	}
228
229	public synchronized boolean verify(String file, String database,
230	    java.io.OutputStream outfile, int flags)
231	    throws DatabaseException, java.io.FileNotFoundException {
232		try {
233			return verify0(file, database, outfile, flags);
234		} finally {
235			cleanup();
236		}
237	}
238
239	public ErrorHandler get_errcall() /* no exception */ {
240		return dbenv.get_errcall();
241	}
242
243	public void set_errcall(ErrorHandler db_errcall_fcn) /* no exception */ {
244		dbenv.set_errcall(db_errcall_fcn);
245	}
246
247	public java.io.OutputStream get_error_stream() /* no exception */ {
248		return dbenv.get_error_stream();
249	}
250
251	public void set_error_stream(java.io.OutputStream stream) /* no exception */ {
252		dbenv.set_error_stream(stream);
253	}
254
255	public void set_errpfx(String errpfx) /* no exception */ {
256		dbenv.set_errpfx(errpfx);
257	}
258
259	public String get_errpfx() /* no exception */ {
260		return dbenv.get_errpfx();
261	}
262
263	public java.io.OutputStream get_message_stream() /* no exception */ {
264		return dbenv.get_message_stream();
265	}
266
267	public void set_message_stream(java.io.OutputStream stream) /* no exception */ {
268		dbenv.set_message_stream(stream);
269	}
270
271	public MessageHandler get_msgcall() /* no exception */ {
272		return dbenv.get_msgcall();
273	}
274
275	public void set_msgcall(MessageHandler db_msgcall_fcn) /* no exception */ {
276		dbenv.set_msgcall(db_msgcall_fcn);
277	}
278
279	public void set_paniccall(PanicHandler db_panic_fcn)
280	    throws DatabaseException {
281		dbenv.set_paniccall(db_panic_fcn);
282	}
283
284	public PanicHandler get_paniccall() throws com.sleepycat.db.DatabaseException {
285		return dbenv.get_paniccall();
286	}
287
288  public Db(DbEnv dbenv, int flags) throws com.sleepycat.db.DatabaseException {
289    this(db_javaJNI.new_Db(DbEnv.getCPtr(dbenv), dbenv, flags), true);
290    initialize(dbenv);
291  }
292
293  public void associate(DbTxn txnid, Db secondary, com.sleepycat.db.SecondaryKeyCreator callback, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_associate(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, Db.getCPtr(secondary), secondary,  (secondary.seckey_create_handler = callback) != null ||
294	(secondary.secmultikey_create_handler != null) , flags); }
295
296  public void associate_foreign(Db primary, com.sleepycat.db.ForeignKeyNullifier callback, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_associate_foreign(swigCPtr, this, Db.getCPtr(primary), primary,  (primary.foreignkey_nullify_handler = callback) != null ||
297	(primary.foreignmultikey_nullify_handler != null) , flags); }
298
299  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, this, DbTxn.getCPtr(txnid), txnid, start, stop, c_data, flags, end); }
300
301  /* package */ int close0(int flags) {
302    return db_javaJNI.Db_close0(swigCPtr, this, flags);
303  }
304
305  public Dbc cursor(DbTxn txnid, int flags) throws com.sleepycat.db.DatabaseException {
306    long cPtr = db_javaJNI.Db_cursor(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, flags);
307    return (cPtr == 0) ? null : new Dbc(cPtr, false);
308  }
309
310  public int del(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, int flags) throws com.sleepycat.db.DatabaseException {
311    return db_javaJNI.Db_del(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, key, flags);
312  }
313
314  public void err(int error, String message) /* no exception */ {
315    db_javaJNI.Db_err(swigCPtr, this, error, message);
316  }
317
318  public void errx(String message) /* no exception */ {
319    db_javaJNI.Db_errx(swigCPtr, this, message);
320  }
321
322  public int exists(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, int flags) throws com.sleepycat.db.DatabaseException {
323    return db_javaJNI.Db_exists(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, key, flags);
324  }
325
326  public int get(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, com.sleepycat.db.DatabaseEntry data, int flags) throws com.sleepycat.db.DatabaseException {
327    return db_javaJNI.Db_get(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, key, data, flags);
328  }
329
330  public boolean get_byteswapped() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_byteswapped(swigCPtr, this); }
331
332  public long get_cachesize() throws com.sleepycat.db.DatabaseException {
333    return db_javaJNI.Db_get_cachesize(swigCPtr, this);
334  }
335
336  public int get_cachesize_ncache() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_cachesize_ncache(swigCPtr, this); }
337
338  public String get_filename() throws com.sleepycat.db.DatabaseException {
339    return db_javaJNI.Db_get_filename(swigCPtr, this);
340  }
341
342  public String get_dbname() throws com.sleepycat.db.DatabaseException {
343    return db_javaJNI.Db_get_dbname(swigCPtr, this);
344  }
345
346  public int get_encrypt_flags() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_encrypt_flags(swigCPtr, this); }
347
348  public int get_flags() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_flags(swigCPtr, this); }
349
350  public int get_lorder() throws com.sleepycat.db.DatabaseException {
351    return db_javaJNI.Db_get_lorder(swigCPtr, this);
352  }
353
354  public DbMpoolFile get_mpf() throws com.sleepycat.db.DatabaseException {
355    long cPtr = db_javaJNI.Db_get_mpf(swigCPtr, this);
356    return (cPtr == 0) ? null : new DbMpoolFile(cPtr, false);
357  }
358
359  public int get_open_flags() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_open_flags(swigCPtr, this); }
360
361  public int get_pagesize() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_pagesize(swigCPtr, this); }
362
363  public int get_bt_minkey() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_bt_minkey(swigCPtr, this); }
364
365  public int get_h_ffactor() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_h_ffactor(swigCPtr, this); }
366
367  public int get_h_nelem() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_h_nelem(swigCPtr, this); }
368
369  public int get_re_delim() throws com.sleepycat.db.DatabaseException {
370    return db_javaJNI.Db_get_re_delim(swigCPtr, this);
371  }
372
373  public int get_priority() throws com.sleepycat.db.DatabaseException {
374    return db_javaJNI.Db_get_priority(swigCPtr, this);
375  }
376
377  public int get_re_len() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_re_len(swigCPtr, this); }
378
379  public int get_re_pad() throws com.sleepycat.db.DatabaseException {
380    return db_javaJNI.Db_get_re_pad(swigCPtr, this);
381  }
382
383  public String get_re_source() throws com.sleepycat.db.DatabaseException {
384    return db_javaJNI.Db_get_re_source(swigCPtr, this);
385  }
386
387  public int get_q_extentsize() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_q_extentsize(swigCPtr, this); }
388
389  public boolean get_multiple() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_multiple(swigCPtr, this); }
390
391  public boolean get_transactional() throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_get_transactional(swigCPtr, this); }
392
393  public int get_type() throws com.sleepycat.db.DatabaseException {
394    return db_javaJNI.Db_get_type(swigCPtr, this);
395  }
396
397  public Dbc join(Dbc[] curslist, int flags) throws com.sleepycat.db.DatabaseException {
398    long cPtr = db_javaJNI.Db_join(swigCPtr, this, curslist, flags);
399    return (cPtr == 0) ? null : new Dbc(cPtr, true);
400  }
401
402  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, this, DbTxn.getCPtr(txnid), txnid, key, key_range, flags); }
403
404  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, this, DbTxn.getCPtr(txnid), txnid, file, database, type, flags, mode); }
405
406  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 {
407    return db_javaJNI.Db_pget(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, key, pkey, data, flags);
408  }
409
410  public int put(DbTxn txnid, com.sleepycat.db.DatabaseEntry key, com.sleepycat.db.DatabaseEntry data, int flags) throws com.sleepycat.db.DatabaseException {
411    return db_javaJNI.Db_put(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, key, data, flags);
412  }
413
414  /* package */ void remove0(String file, String database, int flags) { db_javaJNI.Db_remove0(swigCPtr, this, file, database, flags); }
415
416  /* package */ void rename0(String file, String database, String newname, int flags) { db_javaJNI.Db_rename0(swigCPtr, this, file, database, newname, flags); }
417
418  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, this,  (append_recno_handler = db_append_recno_fcn) != null ); }
419
420  public void set_bt_compare(java.util.Comparator bt_compare_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_bt_compare(swigCPtr, this,  (bt_compare_handler = bt_compare_fcn) != null ); }
421
422  public void set_bt_minkey(int bt_minkey) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_bt_minkey(swigCPtr, this, bt_minkey); }
423
424  public void set_bt_prefix(com.sleepycat.db.BtreePrefixCalculator bt_prefix_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_bt_prefix(swigCPtr, this,  (bt_prefix_handler = bt_prefix_fcn) != null ); }
425
426  public void set_cachesize(long bytes, int ncache) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_cachesize(swigCPtr, this, bytes, ncache); }
427
428  public void set_dup_compare(java.util.Comparator dup_compare_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_dup_compare(swigCPtr, this,  (dup_compare_handler = dup_compare_fcn) != null ); }
429
430  public void set_encrypt(String passwd, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_encrypt(swigCPtr, this, passwd, flags); }
431
432  public void set_feedback(com.sleepycat.db.FeedbackHandler db_feedback_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_feedback(swigCPtr, this,  (db_feedback_handler = db_feedback_fcn) != null ); }
433
434  public void set_flags(int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_flags(swigCPtr, this, flags); }
435
436  public void set_h_compare(java.util.Comparator h_compare_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_h_compare(swigCPtr, this,  (h_compare_handler = h_compare_fcn) != null ); }
437
438  public void set_h_ffactor(int h_ffactor) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_h_ffactor(swigCPtr, this, h_ffactor); }
439
440  public void set_h_hash(com.sleepycat.db.Hasher h_hash_fcn) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_h_hash(swigCPtr, this,  (h_hash_handler = h_hash_fcn) != null ); }
441
442  public void set_h_nelem(int h_nelem) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_h_nelem(swigCPtr, this, h_nelem); }
443
444  public void set_lorder(int lorder) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_lorder(swigCPtr, this, lorder); }
445
446  public void set_pagesize(long pagesize) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_pagesize(swigCPtr, this, pagesize); }
447
448  public void set_priority(int priority) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_priority(swigCPtr, this, priority); }
449
450  public void set_re_delim(int re_delim) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_delim(swigCPtr, this, re_delim); }
451
452  public void set_re_len(int re_len) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_len(swigCPtr, this, re_len); }
453
454  public void set_re_pad(int re_pad) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_pad(swigCPtr, this, re_pad); }
455
456  public void set_re_source(String source) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_re_source(swigCPtr, this, source); }
457
458  public void set_q_extentsize(int extentsize) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_set_q_extentsize(swigCPtr, this, extentsize); }
459
460  public Object stat(DbTxn txnid, int flags) throws com.sleepycat.db.DatabaseException { return db_javaJNI.Db_stat(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, flags); }
461
462  public void sync(int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_sync(swigCPtr, this, flags); }
463
464  public int truncate(DbTxn txnid, int flags) throws com.sleepycat.db.DatabaseException {
465    return db_javaJNI.Db_truncate(swigCPtr, this, DbTxn.getCPtr(txnid), txnid, flags);
466  }
467
468  public void upgrade(String file, int flags) throws com.sleepycat.db.DatabaseException { db_javaJNI.Db_upgrade(swigCPtr, this, file, flags); }
469
470  /* package */ boolean verify0(String file, String database, java.io.OutputStream outfile, int flags) { return db_javaJNI.Db_verify0(swigCPtr, this, file, database, outfile, flags); }
471
472}
473