1%pragma(java) jniclasscode=%{
2	static {
3		/* An alternate library name can be specified via a property. */
4		String libname;
5		int v_major, v_minor, v_patch;
6
7		v_major = DbConstants.DB_VERSION_MAJOR;
8		v_minor = DbConstants.DB_VERSION_MINOR;
9		v_patch = DbConstants.DB_VERSION_PATCH;
10
11		if ((libname =
12		    System.getProperty("sleepycat.db.libfile")) != null)
13			System.load(libname);
14		else if ((libname =
15		    System.getProperty("sleepycat.db.libname")) != null)
16			System.loadLibrary(libname);
17		else {
18			String os = System.getProperty("os.name");
19			if (os != null && os.startsWith("Windows")) {
20				/*
21				 * On Windows, library name is something like
22				 * "libdb_java42.dll" or "libdb_java42d.dll".
23				 */
24				libname = "libdb_java" + v_major + v_minor;
25
26				try {
27					System.loadLibrary(libname);
28				} catch (UnsatisfiedLinkError e) {
29					try {
30						libname += "d";
31						System.loadLibrary(libname);
32					} catch (UnsatisfiedLinkError e2) {
33						throw e;
34					}
35				}
36			} else {
37				/*
38				 * On UNIX, library name is something like
39				 * "libdb_java-3.0.so".
40				 */
41				System.loadLibrary("db_java-" +
42				    v_major + "." + v_minor);
43			}
44		}
45
46		initialize();
47
48		if (DbEnv_get_version_major() != v_major ||
49		    DbEnv_get_version_minor() != v_minor ||
50		    DbEnv_get_version_patch() != v_patch)
51			throw new RuntimeException(
52		      "Berkeley DB library version " +
53		      DbEnv_get_version_major() + "." +
54		      DbEnv_get_version_minor() + "." +
55		      DbEnv_get_version_patch() +
56		      " doesn't match Java class library version " +
57		      v_major + "." + v_minor + "." + v_patch);
58	}
59
60	static native final void initialize();
61%}
62
63%{
64/* don't use SWIG's array handling - save code space */
65#define	SWIG_NOINCLUDE 1
66
67#define	DB_ENV_INTERNAL(dbenv) ((dbenv)->api2_internal)
68#define	DB_INTERNAL(db) ((db)->api_internal)
69
70#define	DB_PKG "com/sleepycat/db/"
71
72/* Forward declarations */
73static int __dbj_throw(JNIEnv *jenv,
74    int err, const char *msg, jobject obj, jobject jdbenv);
75
76/* Global data - JVM handle, classes, fields and methods */
77static JavaVM *javavm;
78
79static jclass db_class, dbc_class, dbenv_class, dbt_class, dblsn_class;
80static jclass dbpreplist_class, dbtxn_class;
81static jclass keyrange_class;
82static jclass bt_stat_class, compact_class, h_stat_class, lock_stat_class;
83static jclass log_stat_class, mpool_stat_class, mpool_fstat_class;
84static jclass mutex_stat_class, qam_stat_class, rep_stat_class;
85static jclass repmgr_stat_class, repmgr_siteinfo_class, rephost_class;
86static jclass seq_stat_class, txn_stat_class;
87static jclass txn_active_class;
88static jclass lock_class, lockreq_class;
89static jclass dbex_class, deadex_class, lockex_class, memex_class;
90static jclass repdupmasterex_class, rephandledeadex_class;
91static jclass repholdelectionex_class, repjoinfailex_class;
92static jclass repleaseexpiredex_class, repleasetimeoutex_class;
93static jclass replockoutex_class, repunavailex_class;
94static jclass runrecex_class, versionex_class;
95static jclass filenotfoundex_class, illegalargex_class, outofmemerr_class;
96static jclass bytearray_class, string_class, outputstream_class;
97
98static jfieldID dbc_cptr_fid;
99static jfieldID dblsn_file_fid, dblsn_offset_fid;
100static jfieldID dbt_data_fid, dbt_data_nio_fid, dbt_size_fid, dbt_ulen_fid;
101static jfieldID dbt_dlen_fid, dbt_doff_fid, dbt_flags_fid, dbt_offset_fid;
102static jfieldID kr_less_fid, kr_equal_fid, kr_greater_fid;
103static jfieldID lock_cptr_fid;
104static jfieldID lockreq_op_fid, lockreq_modeflag_fid, lockreq_timeout_fid;
105static jfieldID lockreq_obj_fid, lockreq_lock_fid;
106static jfieldID repmgr_siteinfo_status_fid;
107
108/* BEGIN-STAT-FIELD-DECLS */
109static jfieldID bt_stat_bt_magic_fid;
110static jfieldID bt_stat_bt_version_fid;
111static jfieldID bt_stat_bt_metaflags_fid;
112static jfieldID bt_stat_bt_nkeys_fid;
113static jfieldID bt_stat_bt_ndata_fid;
114static jfieldID bt_stat_bt_pagecnt_fid;
115static jfieldID bt_stat_bt_pagesize_fid;
116static jfieldID bt_stat_bt_minkey_fid;
117static jfieldID bt_stat_bt_re_len_fid;
118static jfieldID bt_stat_bt_re_pad_fid;
119static jfieldID bt_stat_bt_levels_fid;
120static jfieldID bt_stat_bt_int_pg_fid;
121static jfieldID bt_stat_bt_leaf_pg_fid;
122static jfieldID bt_stat_bt_dup_pg_fid;
123static jfieldID bt_stat_bt_over_pg_fid;
124static jfieldID bt_stat_bt_empty_pg_fid;
125static jfieldID bt_stat_bt_free_fid;
126static jfieldID bt_stat_bt_int_pgfree_fid;
127static jfieldID bt_stat_bt_leaf_pgfree_fid;
128static jfieldID bt_stat_bt_dup_pgfree_fid;
129static jfieldID bt_stat_bt_over_pgfree_fid;
130static jfieldID compact_compact_fillpercent_fid;
131static jfieldID compact_compact_timeout_fid;
132static jfieldID compact_compact_pages_fid;
133static jfieldID compact_compact_pages_free_fid;
134static jfieldID compact_compact_pages_examine_fid;
135static jfieldID compact_compact_levels_fid;
136static jfieldID compact_compact_deadlock_fid;
137static jfieldID compact_compact_pages_truncated_fid;
138static jfieldID compact_compact_truncate_fid;
139static jfieldID h_stat_hash_magic_fid;
140static jfieldID h_stat_hash_version_fid;
141static jfieldID h_stat_hash_metaflags_fid;
142static jfieldID h_stat_hash_nkeys_fid;
143static jfieldID h_stat_hash_ndata_fid;
144static jfieldID h_stat_hash_pagecnt_fid;
145static jfieldID h_stat_hash_pagesize_fid;
146static jfieldID h_stat_hash_ffactor_fid;
147static jfieldID h_stat_hash_buckets_fid;
148static jfieldID h_stat_hash_free_fid;
149static jfieldID h_stat_hash_bfree_fid;
150static jfieldID h_stat_hash_bigpages_fid;
151static jfieldID h_stat_hash_big_bfree_fid;
152static jfieldID h_stat_hash_overflows_fid;
153static jfieldID h_stat_hash_ovfl_free_fid;
154static jfieldID h_stat_hash_dup_fid;
155static jfieldID h_stat_hash_dup_free_fid;
156static jfieldID lock_stat_st_id_fid;
157static jfieldID lock_stat_st_cur_maxid_fid;
158static jfieldID lock_stat_st_maxlocks_fid;
159static jfieldID lock_stat_st_maxlockers_fid;
160static jfieldID lock_stat_st_maxobjects_fid;
161static jfieldID lock_stat_st_partitions_fid;
162static jfieldID lock_stat_st_nmodes_fid;
163static jfieldID lock_stat_st_nlockers_fid;
164static jfieldID lock_stat_st_nlocks_fid;
165static jfieldID lock_stat_st_maxnlocks_fid;
166static jfieldID lock_stat_st_maxhlocks_fid;
167static jfieldID lock_stat_st_locksteals_fid;
168static jfieldID lock_stat_st_maxlsteals_fid;
169static jfieldID lock_stat_st_maxnlockers_fid;
170static jfieldID lock_stat_st_nobjects_fid;
171static jfieldID lock_stat_st_maxnobjects_fid;
172static jfieldID lock_stat_st_maxhobjects_fid;
173static jfieldID lock_stat_st_objectsteals_fid;
174static jfieldID lock_stat_st_maxosteals_fid;
175static jfieldID lock_stat_st_nrequests_fid;
176static jfieldID lock_stat_st_nreleases_fid;
177static jfieldID lock_stat_st_nupgrade_fid;
178static jfieldID lock_stat_st_ndowngrade_fid;
179static jfieldID lock_stat_st_lock_wait_fid;
180static jfieldID lock_stat_st_lock_nowait_fid;
181static jfieldID lock_stat_st_ndeadlocks_fid;
182static jfieldID lock_stat_st_locktimeout_fid;
183static jfieldID lock_stat_st_nlocktimeouts_fid;
184static jfieldID lock_stat_st_txntimeout_fid;
185static jfieldID lock_stat_st_ntxntimeouts_fid;
186static jfieldID lock_stat_st_part_wait_fid;
187static jfieldID lock_stat_st_part_nowait_fid;
188static jfieldID lock_stat_st_part_max_wait_fid;
189static jfieldID lock_stat_st_part_max_nowait_fid;
190static jfieldID lock_stat_st_objs_wait_fid;
191static jfieldID lock_stat_st_objs_nowait_fid;
192static jfieldID lock_stat_st_lockers_wait_fid;
193static jfieldID lock_stat_st_lockers_nowait_fid;
194static jfieldID lock_stat_st_region_wait_fid;
195static jfieldID lock_stat_st_region_nowait_fid;
196static jfieldID lock_stat_st_hash_len_fid;
197static jfieldID lock_stat_st_regsize_fid;
198static jfieldID log_stat_st_magic_fid;
199static jfieldID log_stat_st_version_fid;
200static jfieldID log_stat_st_mode_fid;
201static jfieldID log_stat_st_lg_bsize_fid;
202static jfieldID log_stat_st_lg_size_fid;
203static jfieldID log_stat_st_wc_bytes_fid;
204static jfieldID log_stat_st_wc_mbytes_fid;
205static jfieldID log_stat_st_record_fid;
206static jfieldID log_stat_st_w_bytes_fid;
207static jfieldID log_stat_st_w_mbytes_fid;
208static jfieldID log_stat_st_wcount_fid;
209static jfieldID log_stat_st_wcount_fill_fid;
210static jfieldID log_stat_st_rcount_fid;
211static jfieldID log_stat_st_scount_fid;
212static jfieldID log_stat_st_region_wait_fid;
213static jfieldID log_stat_st_region_nowait_fid;
214static jfieldID log_stat_st_cur_file_fid;
215static jfieldID log_stat_st_cur_offset_fid;
216static jfieldID log_stat_st_disk_file_fid;
217static jfieldID log_stat_st_disk_offset_fid;
218static jfieldID log_stat_st_maxcommitperflush_fid;
219static jfieldID log_stat_st_mincommitperflush_fid;
220static jfieldID log_stat_st_regsize_fid;
221static jfieldID mpool_fstat_file_name_fid;
222static jfieldID mpool_fstat_st_pagesize_fid;
223static jfieldID mpool_fstat_st_map_fid;
224static jfieldID mpool_fstat_st_cache_hit_fid;
225static jfieldID mpool_fstat_st_cache_miss_fid;
226static jfieldID mpool_fstat_st_page_create_fid;
227static jfieldID mpool_fstat_st_page_in_fid;
228static jfieldID mpool_fstat_st_page_out_fid;
229static jfieldID mpool_stat_st_gbytes_fid;
230static jfieldID mpool_stat_st_bytes_fid;
231static jfieldID mpool_stat_st_ncache_fid;
232static jfieldID mpool_stat_st_max_ncache_fid;
233static jfieldID mpool_stat_st_mmapsize_fid;
234static jfieldID mpool_stat_st_maxopenfd_fid;
235static jfieldID mpool_stat_st_maxwrite_fid;
236static jfieldID mpool_stat_st_maxwrite_sleep_fid;
237static jfieldID mpool_stat_st_pages_fid;
238static jfieldID mpool_stat_st_map_fid;
239static jfieldID mpool_stat_st_cache_hit_fid;
240static jfieldID mpool_stat_st_cache_miss_fid;
241static jfieldID mpool_stat_st_page_create_fid;
242static jfieldID mpool_stat_st_page_in_fid;
243static jfieldID mpool_stat_st_page_out_fid;
244static jfieldID mpool_stat_st_ro_evict_fid;
245static jfieldID mpool_stat_st_rw_evict_fid;
246static jfieldID mpool_stat_st_page_trickle_fid;
247static jfieldID mpool_stat_st_page_clean_fid;
248static jfieldID mpool_stat_st_page_dirty_fid;
249static jfieldID mpool_stat_st_hash_buckets_fid;
250static jfieldID mpool_stat_st_hash_searches_fid;
251static jfieldID mpool_stat_st_hash_longest_fid;
252static jfieldID mpool_stat_st_hash_examined_fid;
253static jfieldID mpool_stat_st_hash_nowait_fid;
254static jfieldID mpool_stat_st_hash_wait_fid;
255static jfieldID mpool_stat_st_hash_max_nowait_fid;
256static jfieldID mpool_stat_st_hash_max_wait_fid;
257static jfieldID mpool_stat_st_region_nowait_fid;
258static jfieldID mpool_stat_st_region_wait_fid;
259static jfieldID mpool_stat_st_mvcc_frozen_fid;
260static jfieldID mpool_stat_st_mvcc_thawed_fid;
261static jfieldID mpool_stat_st_mvcc_freed_fid;
262static jfieldID mpool_stat_st_alloc_fid;
263static jfieldID mpool_stat_st_alloc_buckets_fid;
264static jfieldID mpool_stat_st_alloc_max_buckets_fid;
265static jfieldID mpool_stat_st_alloc_pages_fid;
266static jfieldID mpool_stat_st_alloc_max_pages_fid;
267static jfieldID mpool_stat_st_io_wait_fid;
268static jfieldID mpool_stat_st_regsize_fid;
269static jfieldID mutex_stat_st_mutex_align_fid;
270static jfieldID mutex_stat_st_mutex_tas_spins_fid;
271static jfieldID mutex_stat_st_mutex_cnt_fid;
272static jfieldID mutex_stat_st_mutex_free_fid;
273static jfieldID mutex_stat_st_mutex_inuse_fid;
274static jfieldID mutex_stat_st_mutex_inuse_max_fid;
275static jfieldID mutex_stat_st_region_wait_fid;
276static jfieldID mutex_stat_st_region_nowait_fid;
277static jfieldID mutex_stat_st_regsize_fid;
278static jfieldID qam_stat_qs_magic_fid;
279static jfieldID qam_stat_qs_version_fid;
280static jfieldID qam_stat_qs_metaflags_fid;
281static jfieldID qam_stat_qs_nkeys_fid;
282static jfieldID qam_stat_qs_ndata_fid;
283static jfieldID qam_stat_qs_pagesize_fid;
284static jfieldID qam_stat_qs_extentsize_fid;
285static jfieldID qam_stat_qs_pages_fid;
286static jfieldID qam_stat_qs_re_len_fid;
287static jfieldID qam_stat_qs_re_pad_fid;
288static jfieldID qam_stat_qs_pgfree_fid;
289static jfieldID qam_stat_qs_first_recno_fid;
290static jfieldID qam_stat_qs_cur_recno_fid;
291static jfieldID rep_stat_st_log_queued_fid;
292static jfieldID rep_stat_st_startup_complete_fid;
293static jfieldID rep_stat_st_status_fid;
294static jfieldID rep_stat_st_next_lsn_fid;
295static jfieldID rep_stat_st_waiting_lsn_fid;
296static jfieldID rep_stat_st_max_perm_lsn_fid;
297static jfieldID rep_stat_st_next_pg_fid;
298static jfieldID rep_stat_st_waiting_pg_fid;
299static jfieldID rep_stat_st_dupmasters_fid;
300static jfieldID rep_stat_st_env_id_fid;
301static jfieldID rep_stat_st_env_priority_fid;
302static jfieldID rep_stat_st_bulk_fills_fid;
303static jfieldID rep_stat_st_bulk_overflows_fid;
304static jfieldID rep_stat_st_bulk_records_fid;
305static jfieldID rep_stat_st_bulk_transfers_fid;
306static jfieldID rep_stat_st_client_rerequests_fid;
307static jfieldID rep_stat_st_client_svc_req_fid;
308static jfieldID rep_stat_st_client_svc_miss_fid;
309static jfieldID rep_stat_st_gen_fid;
310static jfieldID rep_stat_st_egen_fid;
311static jfieldID rep_stat_st_log_duplicated_fid;
312static jfieldID rep_stat_st_log_queued_max_fid;
313static jfieldID rep_stat_st_log_queued_total_fid;
314static jfieldID rep_stat_st_log_records_fid;
315static jfieldID rep_stat_st_log_requested_fid;
316static jfieldID rep_stat_st_master_fid;
317static jfieldID rep_stat_st_master_changes_fid;
318static jfieldID rep_stat_st_msgs_badgen_fid;
319static jfieldID rep_stat_st_msgs_processed_fid;
320static jfieldID rep_stat_st_msgs_recover_fid;
321static jfieldID rep_stat_st_msgs_send_failures_fid;
322static jfieldID rep_stat_st_msgs_sent_fid;
323static jfieldID rep_stat_st_newsites_fid;
324static jfieldID rep_stat_st_nsites_fid;
325static jfieldID rep_stat_st_nthrottles_fid;
326static jfieldID rep_stat_st_outdated_fid;
327static jfieldID rep_stat_st_pg_duplicated_fid;
328static jfieldID rep_stat_st_pg_records_fid;
329static jfieldID rep_stat_st_pg_requested_fid;
330static jfieldID rep_stat_st_txns_applied_fid;
331static jfieldID rep_stat_st_startsync_delayed_fid;
332static jfieldID rep_stat_st_elections_fid;
333static jfieldID rep_stat_st_elections_won_fid;
334static jfieldID rep_stat_st_election_cur_winner_fid;
335static jfieldID rep_stat_st_election_gen_fid;
336static jfieldID rep_stat_st_election_lsn_fid;
337static jfieldID rep_stat_st_election_nsites_fid;
338static jfieldID rep_stat_st_election_nvotes_fid;
339static jfieldID rep_stat_st_election_priority_fid;
340static jfieldID rep_stat_st_election_status_fid;
341static jfieldID rep_stat_st_election_tiebreaker_fid;
342static jfieldID rep_stat_st_election_votes_fid;
343static jfieldID rep_stat_st_election_sec_fid;
344static jfieldID rep_stat_st_election_usec_fid;
345static jfieldID rep_stat_st_max_lease_sec_fid;
346static jfieldID rep_stat_st_max_lease_usec_fid;
347static jfieldID repmgr_stat_st_perm_failed_fid;
348static jfieldID repmgr_stat_st_msgs_queued_fid;
349static jfieldID repmgr_stat_st_msgs_dropped_fid;
350static jfieldID repmgr_stat_st_connection_drop_fid;
351static jfieldID repmgr_stat_st_connect_fail_fid;
352static jfieldID seq_stat_st_wait_fid;
353static jfieldID seq_stat_st_nowait_fid;
354static jfieldID seq_stat_st_current_fid;
355static jfieldID seq_stat_st_value_fid;
356static jfieldID seq_stat_st_last_value_fid;
357static jfieldID seq_stat_st_min_fid;
358static jfieldID seq_stat_st_max_fid;
359static jfieldID seq_stat_st_cache_size_fid;
360static jfieldID seq_stat_st_flags_fid;
361static jfieldID txn_stat_st_nrestores_fid;
362static jfieldID txn_stat_st_last_ckp_fid;
363static jfieldID txn_stat_st_time_ckp_fid;
364static jfieldID txn_stat_st_last_txnid_fid;
365static jfieldID txn_stat_st_maxtxns_fid;
366static jfieldID txn_stat_st_naborts_fid;
367static jfieldID txn_stat_st_nbegins_fid;
368static jfieldID txn_stat_st_ncommits_fid;
369static jfieldID txn_stat_st_nactive_fid;
370static jfieldID txn_stat_st_nsnapshot_fid;
371static jfieldID txn_stat_st_maxnactive_fid;
372static jfieldID txn_stat_st_maxnsnapshot_fid;
373static jfieldID txn_stat_st_txnarray_fid;
374static jfieldID txn_stat_st_region_wait_fid;
375static jfieldID txn_stat_st_region_nowait_fid;
376static jfieldID txn_stat_st_regsize_fid;
377static jfieldID txn_active_txnid_fid;
378static jfieldID txn_active_parentid_fid;
379static jfieldID txn_active_pid_fid;
380static jfieldID txn_active_lsn_fid;
381static jfieldID txn_active_read_lsn_fid;
382static jfieldID txn_active_mvcc_ref_fid;
383static jfieldID txn_active_status_fid;
384static jfieldID txn_active_xa_status_fid;
385static jfieldID txn_active_xid_fid;
386static jfieldID txn_active_name_fid;
387/* END-STAT-FIELD-DECLS */
388
389static jmethodID dbenv_construct, dbt_construct, dblsn_construct;
390static jmethodID dbpreplist_construct, dbtxn_construct;
391static jmethodID bt_stat_construct, get_err_msg_method, h_stat_construct;
392static jmethodID lock_stat_construct, log_stat_construct;
393static jmethodID mpool_stat_construct, mpool_fstat_construct;
394static jmethodID mutex_stat_construct, qam_stat_construct;
395static jmethodID rep_stat_construct, repmgr_stat_construct, seq_stat_construct;
396static jmethodID txn_stat_construct, txn_active_construct;
397static jmethodID dbex_construct, deadex_construct, lockex_construct;
398static jmethodID memex_construct, memex_update_method;
399static jmethodID repdupmasterex_construct, rephandledeadex_construct;
400static jmethodID repholdelectionex_construct, repjoinfailex_construct;
401static jmethodID repmgr_siteinfo_construct, rephost_construct, repleaseexpiredex_construct;
402static jmethodID repleasetimeoutex_construct, replockoutex_construct;
403static jmethodID repunavailex_construct;
404static jmethodID runrecex_construct, versionex_construct;
405static jmethodID filenotfoundex_construct, illegalargex_construct;
406static jmethodID outofmemerr_construct;
407static jmethodID lock_construct;
408
409static jmethodID app_dispatch_method, errcall_method, env_feedback_method;
410static jmethodID msgcall_method, paniccall_method, rep_transport_method;
411static jmethodID panic_event_notify_method, rep_client_event_notify_method;
412static jmethodID rep_elected_event_notify_method;
413static jmethodID rep_master_event_notify_method;
414static jmethodID rep_new_master_event_notify_method;
415static jmethodID rep_perm_failed_event_notify_method;
416static jmethodID rep_startup_done_event_notify_method;
417static jmethodID write_failed_event_notify_method;
418
419static jmethodID append_recno_method, bt_compare_method, bt_prefix_method;
420static jmethodID db_feedback_method, dup_compare_method;
421static jmethodID foreignkey_nullify_method, h_compare_method, h_hash_method;
422static jmethodID seckey_create_method;
423
424static jmethodID outputstream_write_method;
425
426const struct {
427	jclass *cl;
428	const char *name;
429} all_classes[] = {
430	{ &dbenv_class, DB_PKG "internal/DbEnv" },
431	{ &db_class, DB_PKG "internal/Db" },
432	{ &dbc_class, DB_PKG "internal/Dbc" },
433	{ &dbt_class, DB_PKG "DatabaseEntry" },
434	{ &dblsn_class, DB_PKG "LogSequenceNumber" },
435	{ &dbpreplist_class, DB_PKG "PreparedTransaction" },
436	{ &dbtxn_class, DB_PKG "internal/DbTxn" },
437
438	{ &bt_stat_class, DB_PKG "BtreeStats" },
439	{ &compact_class, DB_PKG "CompactStats" },
440	{ &h_stat_class, DB_PKG "HashStats" },
441	{ &lock_stat_class, DB_PKG "LockStats" },
442	{ &log_stat_class, DB_PKG "LogStats" },
443	{ &mpool_fstat_class, DB_PKG "CacheFileStats" },
444	{ &mpool_stat_class, DB_PKG "CacheStats" },
445	{ &mutex_stat_class, DB_PKG "MutexStats" },
446	{ &qam_stat_class, DB_PKG "QueueStats" },
447	{ &rep_stat_class, DB_PKG "ReplicationStats" },
448	{ &repmgr_stat_class, DB_PKG "ReplicationManagerStats" },
449	{ &seq_stat_class, DB_PKG "SequenceStats" },
450	{ &txn_stat_class, DB_PKG "TransactionStats" },
451	{ &txn_active_class, DB_PKG "TransactionStats$Active" },
452
453	{ &keyrange_class, DB_PKG "KeyRange" },
454	{ &lock_class, DB_PKG "internal/DbLock" },
455	{ &lockreq_class, DB_PKG "LockRequest" },
456
457	{ &dbex_class, DB_PKG "DatabaseException" },
458	{ &deadex_class, DB_PKG "DeadlockException" },
459	{ &lockex_class, DB_PKG "LockNotGrantedException" },
460	{ &memex_class, DB_PKG "MemoryException" },
461	{ &repdupmasterex_class, DB_PKG "ReplicationDuplicateMasterException" },
462	{ &rephandledeadex_class, DB_PKG "ReplicationHandleDeadException" },
463	{ &repholdelectionex_class, DB_PKG "ReplicationHoldElectionException" },
464	{ &rephost_class, DB_PKG "ReplicationHostAddress" },
465	{ &repmgr_siteinfo_class, DB_PKG "ReplicationManagerSiteInfo" },
466	{ &repjoinfailex_class, DB_PKG "ReplicationJoinFailureException" },
467	{ &repleaseexpiredex_class, DB_PKG "ReplicationLeaseExpiredException" },
468	{ &repleasetimeoutex_class, DB_PKG "ReplicationLeaseTimeoutException" },
469	{ &replockoutex_class, DB_PKG "ReplicationLockoutException" },
470	{ &repunavailex_class, DB_PKG "ReplicationSiteUnavailableException" },
471	{ &runrecex_class, DB_PKG "RunRecoveryException" },
472	{ &versionex_class, DB_PKG "VersionMismatchException" },
473	{ &filenotfoundex_class, "java/io/FileNotFoundException" },
474	{ &illegalargex_class, "java/lang/IllegalArgumentException" },
475	{ &outofmemerr_class, "java/lang/OutOfMemoryError" },
476
477	{ &bytearray_class, "[B" },
478	{ &string_class, "java/lang/String" },
479	{ &outputstream_class, "java/io/OutputStream" }
480};
481
482const struct {
483	jfieldID *fid;
484	jclass *cl;
485	const char *name;
486	const char *sig;
487} all_fields[] = {
488	{ &dbc_cptr_fid, &dbc_class, "swigCPtr", "J" },
489
490	{ &dblsn_file_fid, &dblsn_class, "file", "I" },
491	{ &dblsn_offset_fid, &dblsn_class, "offset", "I" },
492
493	{ &dbt_data_fid, &dbt_class, "data", "[B" },
494	{ &dbt_data_nio_fid, &dbt_class, "data_nio", "Ljava/nio/ByteBuffer;" },
495	{ &dbt_size_fid, &dbt_class, "size", "I" },
496	{ &dbt_ulen_fid, &dbt_class, "ulen", "I" },
497	{ &dbt_dlen_fid, &dbt_class, "dlen", "I" },
498	{ &dbt_doff_fid, &dbt_class, "doff", "I" },
499	{ &dbt_flags_fid, &dbt_class, "flags", "I" },
500	{ &dbt_offset_fid, &dbt_class, "offset", "I" },
501
502	{ &kr_less_fid, &keyrange_class, "less", "D" },
503	{ &kr_equal_fid, &keyrange_class, "equal", "D" },
504	{ &kr_greater_fid, &keyrange_class, "greater", "D" },
505
506	{ &lock_cptr_fid, &lock_class, "swigCPtr", "J" },
507
508	{ &lockreq_op_fid, &lockreq_class, "op", "I" },
509	{ &lockreq_modeflag_fid, &lockreq_class, "modeFlag", "I" },
510	{ &lockreq_timeout_fid, &lockreq_class, "timeout", "I" },
511	{ &lockreq_obj_fid, &lockreq_class, "obj",
512	    "L" DB_PKG "DatabaseEntry;" },
513	{ &lockreq_lock_fid, &lockreq_class, "lock",
514	    "L" DB_PKG "internal/DbLock;" },
515
516/* BEGIN-STAT-FIELDS */
517	{ &bt_stat_bt_magic_fid, &bt_stat_class, "bt_magic", "I" },
518	{ &bt_stat_bt_version_fid, &bt_stat_class, "bt_version", "I" },
519	{ &bt_stat_bt_metaflags_fid, &bt_stat_class, "bt_metaflags", "I" },
520	{ &bt_stat_bt_nkeys_fid, &bt_stat_class, "bt_nkeys", "I" },
521	{ &bt_stat_bt_ndata_fid, &bt_stat_class, "bt_ndata", "I" },
522	{ &bt_stat_bt_pagecnt_fid, &bt_stat_class, "bt_pagecnt", "I" },
523	{ &bt_stat_bt_pagesize_fid, &bt_stat_class, "bt_pagesize", "I" },
524	{ &bt_stat_bt_minkey_fid, &bt_stat_class, "bt_minkey", "I" },
525	{ &bt_stat_bt_re_len_fid, &bt_stat_class, "bt_re_len", "I" },
526	{ &bt_stat_bt_re_pad_fid, &bt_stat_class, "bt_re_pad", "I" },
527	{ &bt_stat_bt_levels_fid, &bt_stat_class, "bt_levels", "I" },
528	{ &bt_stat_bt_int_pg_fid, &bt_stat_class, "bt_int_pg", "I" },
529	{ &bt_stat_bt_leaf_pg_fid, &bt_stat_class, "bt_leaf_pg", "I" },
530	{ &bt_stat_bt_dup_pg_fid, &bt_stat_class, "bt_dup_pg", "I" },
531	{ &bt_stat_bt_over_pg_fid, &bt_stat_class, "bt_over_pg", "I" },
532	{ &bt_stat_bt_empty_pg_fid, &bt_stat_class, "bt_empty_pg", "I" },
533	{ &bt_stat_bt_free_fid, &bt_stat_class, "bt_free", "I" },
534	{ &bt_stat_bt_int_pgfree_fid, &bt_stat_class, "bt_int_pgfree", "I" },
535	{ &bt_stat_bt_leaf_pgfree_fid, &bt_stat_class, "bt_leaf_pgfree", "I" },
536	{ &bt_stat_bt_dup_pgfree_fid, &bt_stat_class, "bt_dup_pgfree", "I" },
537	{ &bt_stat_bt_over_pgfree_fid, &bt_stat_class, "bt_over_pgfree", "I" },
538	{ &compact_compact_fillpercent_fid, &compact_class, "compact_fillpercent", "I" },
539	{ &compact_compact_timeout_fid, &compact_class, "compact_timeout", "I" },
540	{ &compact_compact_pages_fid, &compact_class, "compact_pages", "I" },
541	{ &compact_compact_pages_free_fid, &compact_class, "compact_pages_free", "I" },
542	{ &compact_compact_pages_examine_fid, &compact_class, "compact_pages_examine", "I" },
543	{ &compact_compact_levels_fid, &compact_class, "compact_levels", "I" },
544	{ &compact_compact_deadlock_fid, &compact_class, "compact_deadlock", "I" },
545	{ &compact_compact_pages_truncated_fid, &compact_class, "compact_pages_truncated", "I" },
546	{ &compact_compact_truncate_fid, &compact_class, "compact_truncate", "I" },
547	{ &h_stat_hash_magic_fid, &h_stat_class, "hash_magic", "I" },
548	{ &h_stat_hash_version_fid, &h_stat_class, "hash_version", "I" },
549	{ &h_stat_hash_metaflags_fid, &h_stat_class, "hash_metaflags", "I" },
550	{ &h_stat_hash_nkeys_fid, &h_stat_class, "hash_nkeys", "I" },
551	{ &h_stat_hash_ndata_fid, &h_stat_class, "hash_ndata", "I" },
552	{ &h_stat_hash_pagecnt_fid, &h_stat_class, "hash_pagecnt", "I" },
553	{ &h_stat_hash_pagesize_fid, &h_stat_class, "hash_pagesize", "I" },
554	{ &h_stat_hash_ffactor_fid, &h_stat_class, "hash_ffactor", "I" },
555	{ &h_stat_hash_buckets_fid, &h_stat_class, "hash_buckets", "I" },
556	{ &h_stat_hash_free_fid, &h_stat_class, "hash_free", "I" },
557	{ &h_stat_hash_bfree_fid, &h_stat_class, "hash_bfree", "I" },
558	{ &h_stat_hash_bigpages_fid, &h_stat_class, "hash_bigpages", "I" },
559	{ &h_stat_hash_big_bfree_fid, &h_stat_class, "hash_big_bfree", "I" },
560	{ &h_stat_hash_overflows_fid, &h_stat_class, "hash_overflows", "I" },
561	{ &h_stat_hash_ovfl_free_fid, &h_stat_class, "hash_ovfl_free", "I" },
562	{ &h_stat_hash_dup_fid, &h_stat_class, "hash_dup", "I" },
563	{ &h_stat_hash_dup_free_fid, &h_stat_class, "hash_dup_free", "I" },
564	{ &lock_stat_st_id_fid, &lock_stat_class, "st_id", "I" },
565	{ &lock_stat_st_cur_maxid_fid, &lock_stat_class, "st_cur_maxid", "I" },
566	{ &lock_stat_st_maxlocks_fid, &lock_stat_class, "st_maxlocks", "I" },
567	{ &lock_stat_st_maxlockers_fid, &lock_stat_class, "st_maxlockers", "I" },
568	{ &lock_stat_st_maxobjects_fid, &lock_stat_class, "st_maxobjects", "I" },
569	{ &lock_stat_st_partitions_fid, &lock_stat_class, "st_partitions", "I" },
570	{ &lock_stat_st_nmodes_fid, &lock_stat_class, "st_nmodes", "I" },
571	{ &lock_stat_st_nlockers_fid, &lock_stat_class, "st_nlockers", "I" },
572	{ &lock_stat_st_nlocks_fid, &lock_stat_class, "st_nlocks", "I" },
573	{ &lock_stat_st_maxnlocks_fid, &lock_stat_class, "st_maxnlocks", "I" },
574	{ &lock_stat_st_maxhlocks_fid, &lock_stat_class, "st_maxhlocks", "I" },
575	{ &lock_stat_st_locksteals_fid, &lock_stat_class, "st_locksteals", "I" },
576	{ &lock_stat_st_maxlsteals_fid, &lock_stat_class, "st_maxlsteals", "I" },
577	{ &lock_stat_st_maxnlockers_fid, &lock_stat_class, "st_maxnlockers", "I" },
578	{ &lock_stat_st_nobjects_fid, &lock_stat_class, "st_nobjects", "I" },
579	{ &lock_stat_st_maxnobjects_fid, &lock_stat_class, "st_maxnobjects", "I" },
580	{ &lock_stat_st_maxhobjects_fid, &lock_stat_class, "st_maxhobjects", "I" },
581	{ &lock_stat_st_objectsteals_fid, &lock_stat_class, "st_objectsteals", "I" },
582	{ &lock_stat_st_maxosteals_fid, &lock_stat_class, "st_maxosteals", "I" },
583	{ &lock_stat_st_nrequests_fid, &lock_stat_class, "st_nrequests", "I" },
584	{ &lock_stat_st_nreleases_fid, &lock_stat_class, "st_nreleases", "I" },
585	{ &lock_stat_st_nupgrade_fid, &lock_stat_class, "st_nupgrade", "I" },
586	{ &lock_stat_st_ndowngrade_fid, &lock_stat_class, "st_ndowngrade", "I" },
587	{ &lock_stat_st_lock_wait_fid, &lock_stat_class, "st_lock_wait", "I" },
588	{ &lock_stat_st_lock_nowait_fid, &lock_stat_class, "st_lock_nowait", "I" },
589	{ &lock_stat_st_ndeadlocks_fid, &lock_stat_class, "st_ndeadlocks", "I" },
590	{ &lock_stat_st_locktimeout_fid, &lock_stat_class, "st_locktimeout", "I" },
591	{ &lock_stat_st_nlocktimeouts_fid, &lock_stat_class, "st_nlocktimeouts", "I" },
592	{ &lock_stat_st_txntimeout_fid, &lock_stat_class, "st_txntimeout", "I" },
593	{ &lock_stat_st_ntxntimeouts_fid, &lock_stat_class, "st_ntxntimeouts", "I" },
594	{ &lock_stat_st_part_wait_fid, &lock_stat_class, "st_part_wait", "I" },
595	{ &lock_stat_st_part_nowait_fid, &lock_stat_class, "st_part_nowait", "I" },
596	{ &lock_stat_st_part_max_wait_fid, &lock_stat_class, "st_part_max_wait", "I" },
597	{ &lock_stat_st_part_max_nowait_fid, &lock_stat_class, "st_part_max_nowait", "I" },
598	{ &lock_stat_st_objs_wait_fid, &lock_stat_class, "st_objs_wait", "I" },
599	{ &lock_stat_st_objs_nowait_fid, &lock_stat_class, "st_objs_nowait", "I" },
600	{ &lock_stat_st_lockers_wait_fid, &lock_stat_class, "st_lockers_wait", "I" },
601	{ &lock_stat_st_lockers_nowait_fid, &lock_stat_class, "st_lockers_nowait", "I" },
602	{ &lock_stat_st_region_wait_fid, &lock_stat_class, "st_region_wait", "I" },
603	{ &lock_stat_st_region_nowait_fid, &lock_stat_class, "st_region_nowait", "I" },
604	{ &lock_stat_st_hash_len_fid, &lock_stat_class, "st_hash_len", "I" },
605	{ &lock_stat_st_regsize_fid, &lock_stat_class, "st_regsize", "I" },
606	{ &log_stat_st_magic_fid, &log_stat_class, "st_magic", "I" },
607	{ &log_stat_st_version_fid, &log_stat_class, "st_version", "I" },
608	{ &log_stat_st_mode_fid, &log_stat_class, "st_mode", "I" },
609	{ &log_stat_st_lg_bsize_fid, &log_stat_class, "st_lg_bsize", "I" },
610	{ &log_stat_st_lg_size_fid, &log_stat_class, "st_lg_size", "I" },
611	{ &log_stat_st_wc_bytes_fid, &log_stat_class, "st_wc_bytes", "I" },
612	{ &log_stat_st_wc_mbytes_fid, &log_stat_class, "st_wc_mbytes", "I" },
613	{ &log_stat_st_record_fid, &log_stat_class, "st_record", "I" },
614	{ &log_stat_st_w_bytes_fid, &log_stat_class, "st_w_bytes", "I" },
615	{ &log_stat_st_w_mbytes_fid, &log_stat_class, "st_w_mbytes", "I" },
616	{ &log_stat_st_wcount_fid, &log_stat_class, "st_wcount", "I" },
617	{ &log_stat_st_wcount_fill_fid, &log_stat_class, "st_wcount_fill", "I" },
618	{ &log_stat_st_rcount_fid, &log_stat_class, "st_rcount", "I" },
619	{ &log_stat_st_scount_fid, &log_stat_class, "st_scount", "I" },
620	{ &log_stat_st_region_wait_fid, &log_stat_class, "st_region_wait", "I" },
621	{ &log_stat_st_region_nowait_fid, &log_stat_class, "st_region_nowait", "I" },
622	{ &log_stat_st_cur_file_fid, &log_stat_class, "st_cur_file", "I" },
623	{ &log_stat_st_cur_offset_fid, &log_stat_class, "st_cur_offset", "I" },
624	{ &log_stat_st_disk_file_fid, &log_stat_class, "st_disk_file", "I" },
625	{ &log_stat_st_disk_offset_fid, &log_stat_class, "st_disk_offset", "I" },
626	{ &log_stat_st_maxcommitperflush_fid, &log_stat_class, "st_maxcommitperflush", "I" },
627	{ &log_stat_st_mincommitperflush_fid, &log_stat_class, "st_mincommitperflush", "I" },
628	{ &log_stat_st_regsize_fid, &log_stat_class, "st_regsize", "I" },
629	{ &mpool_fstat_file_name_fid, &mpool_fstat_class, "file_name", "Ljava/lang/String;" },
630	{ &mpool_fstat_st_pagesize_fid, &mpool_fstat_class, "st_pagesize", "I" },
631	{ &mpool_fstat_st_map_fid, &mpool_fstat_class, "st_map", "I" },
632	{ &mpool_fstat_st_cache_hit_fid, &mpool_fstat_class, "st_cache_hit", "I" },
633	{ &mpool_fstat_st_cache_miss_fid, &mpool_fstat_class, "st_cache_miss", "I" },
634	{ &mpool_fstat_st_page_create_fid, &mpool_fstat_class, "st_page_create", "I" },
635	{ &mpool_fstat_st_page_in_fid, &mpool_fstat_class, "st_page_in", "I" },
636	{ &mpool_fstat_st_page_out_fid, &mpool_fstat_class, "st_page_out", "I" },
637	{ &mpool_stat_st_gbytes_fid, &mpool_stat_class, "st_gbytes", "I" },
638	{ &mpool_stat_st_bytes_fid, &mpool_stat_class, "st_bytes", "I" },
639	{ &mpool_stat_st_ncache_fid, &mpool_stat_class, "st_ncache", "I" },
640	{ &mpool_stat_st_max_ncache_fid, &mpool_stat_class, "st_max_ncache", "I" },
641	{ &mpool_stat_st_mmapsize_fid, &mpool_stat_class, "st_mmapsize", "I" },
642	{ &mpool_stat_st_maxopenfd_fid, &mpool_stat_class, "st_maxopenfd", "I" },
643	{ &mpool_stat_st_maxwrite_fid, &mpool_stat_class, "st_maxwrite", "I" },
644	{ &mpool_stat_st_maxwrite_sleep_fid, &mpool_stat_class, "st_maxwrite_sleep", "I" },
645	{ &mpool_stat_st_pages_fid, &mpool_stat_class, "st_pages", "I" },
646	{ &mpool_stat_st_map_fid, &mpool_stat_class, "st_map", "I" },
647	{ &mpool_stat_st_cache_hit_fid, &mpool_stat_class, "st_cache_hit", "I" },
648	{ &mpool_stat_st_cache_miss_fid, &mpool_stat_class, "st_cache_miss", "I" },
649	{ &mpool_stat_st_page_create_fid, &mpool_stat_class, "st_page_create", "I" },
650	{ &mpool_stat_st_page_in_fid, &mpool_stat_class, "st_page_in", "I" },
651	{ &mpool_stat_st_page_out_fid, &mpool_stat_class, "st_page_out", "I" },
652	{ &mpool_stat_st_ro_evict_fid, &mpool_stat_class, "st_ro_evict", "I" },
653	{ &mpool_stat_st_rw_evict_fid, &mpool_stat_class, "st_rw_evict", "I" },
654	{ &mpool_stat_st_page_trickle_fid, &mpool_stat_class, "st_page_trickle", "I" },
655	{ &mpool_stat_st_page_clean_fid, &mpool_stat_class, "st_page_clean", "I" },
656	{ &mpool_stat_st_page_dirty_fid, &mpool_stat_class, "st_page_dirty", "I" },
657	{ &mpool_stat_st_hash_buckets_fid, &mpool_stat_class, "st_hash_buckets", "I" },
658	{ &mpool_stat_st_hash_searches_fid, &mpool_stat_class, "st_hash_searches", "I" },
659	{ &mpool_stat_st_hash_longest_fid, &mpool_stat_class, "st_hash_longest", "I" },
660	{ &mpool_stat_st_hash_examined_fid, &mpool_stat_class, "st_hash_examined", "I" },
661	{ &mpool_stat_st_hash_nowait_fid, &mpool_stat_class, "st_hash_nowait", "I" },
662	{ &mpool_stat_st_hash_wait_fid, &mpool_stat_class, "st_hash_wait", "I" },
663	{ &mpool_stat_st_hash_max_nowait_fid, &mpool_stat_class, "st_hash_max_nowait", "I" },
664	{ &mpool_stat_st_hash_max_wait_fid, &mpool_stat_class, "st_hash_max_wait", "I" },
665	{ &mpool_stat_st_region_nowait_fid, &mpool_stat_class, "st_region_nowait", "I" },
666	{ &mpool_stat_st_region_wait_fid, &mpool_stat_class, "st_region_wait", "I" },
667	{ &mpool_stat_st_mvcc_frozen_fid, &mpool_stat_class, "st_mvcc_frozen", "I" },
668	{ &mpool_stat_st_mvcc_thawed_fid, &mpool_stat_class, "st_mvcc_thawed", "I" },
669	{ &mpool_stat_st_mvcc_freed_fid, &mpool_stat_class, "st_mvcc_freed", "I" },
670	{ &mpool_stat_st_alloc_fid, &mpool_stat_class, "st_alloc", "I" },
671	{ &mpool_stat_st_alloc_buckets_fid, &mpool_stat_class, "st_alloc_buckets", "I" },
672	{ &mpool_stat_st_alloc_max_buckets_fid, &mpool_stat_class, "st_alloc_max_buckets", "I" },
673	{ &mpool_stat_st_alloc_pages_fid, &mpool_stat_class, "st_alloc_pages", "I" },
674	{ &mpool_stat_st_alloc_max_pages_fid, &mpool_stat_class, "st_alloc_max_pages", "I" },
675	{ &mpool_stat_st_io_wait_fid, &mpool_stat_class, "st_io_wait", "I" },
676	{ &mpool_stat_st_regsize_fid, &mpool_stat_class, "st_regsize", "I" },
677	{ &mutex_stat_st_mutex_align_fid, &mutex_stat_class, "st_mutex_align", "I" },
678	{ &mutex_stat_st_mutex_tas_spins_fid, &mutex_stat_class, "st_mutex_tas_spins", "I" },
679	{ &mutex_stat_st_mutex_cnt_fid, &mutex_stat_class, "st_mutex_cnt", "I" },
680	{ &mutex_stat_st_mutex_free_fid, &mutex_stat_class, "st_mutex_free", "I" },
681	{ &mutex_stat_st_mutex_inuse_fid, &mutex_stat_class, "st_mutex_inuse", "I" },
682	{ &mutex_stat_st_mutex_inuse_max_fid, &mutex_stat_class, "st_mutex_inuse_max", "I" },
683	{ &mutex_stat_st_region_wait_fid, &mutex_stat_class, "st_region_wait", "I" },
684	{ &mutex_stat_st_region_nowait_fid, &mutex_stat_class, "st_region_nowait", "I" },
685	{ &mutex_stat_st_regsize_fid, &mutex_stat_class, "st_regsize", "I" },
686	{ &qam_stat_qs_magic_fid, &qam_stat_class, "qs_magic", "I" },
687	{ &qam_stat_qs_version_fid, &qam_stat_class, "qs_version", "I" },
688	{ &qam_stat_qs_metaflags_fid, &qam_stat_class, "qs_metaflags", "I" },
689	{ &qam_stat_qs_nkeys_fid, &qam_stat_class, "qs_nkeys", "I" },
690	{ &qam_stat_qs_ndata_fid, &qam_stat_class, "qs_ndata", "I" },
691	{ &qam_stat_qs_pagesize_fid, &qam_stat_class, "qs_pagesize", "I" },
692	{ &qam_stat_qs_extentsize_fid, &qam_stat_class, "qs_extentsize", "I" },
693	{ &qam_stat_qs_pages_fid, &qam_stat_class, "qs_pages", "I" },
694	{ &qam_stat_qs_re_len_fid, &qam_stat_class, "qs_re_len", "I" },
695	{ &qam_stat_qs_re_pad_fid, &qam_stat_class, "qs_re_pad", "I" },
696	{ &qam_stat_qs_pgfree_fid, &qam_stat_class, "qs_pgfree", "I" },
697	{ &qam_stat_qs_first_recno_fid, &qam_stat_class, "qs_first_recno", "I" },
698	{ &qam_stat_qs_cur_recno_fid, &qam_stat_class, "qs_cur_recno", "I" },
699	{ &rep_stat_st_log_queued_fid, &rep_stat_class, "st_log_queued", "I" },
700	{ &rep_stat_st_startup_complete_fid, &rep_stat_class, "st_startup_complete", "I" },
701	{ &rep_stat_st_status_fid, &rep_stat_class, "st_status", "I" },
702	{ &rep_stat_st_next_lsn_fid, &rep_stat_class, "st_next_lsn", "L" DB_PKG "LogSequenceNumber;" },
703	{ &rep_stat_st_waiting_lsn_fid, &rep_stat_class, "st_waiting_lsn", "L" DB_PKG "LogSequenceNumber;" },
704	{ &rep_stat_st_max_perm_lsn_fid, &rep_stat_class, "st_max_perm_lsn", "L" DB_PKG "LogSequenceNumber;" },
705	{ &rep_stat_st_next_pg_fid, &rep_stat_class, "st_next_pg", "I" },
706	{ &rep_stat_st_waiting_pg_fid, &rep_stat_class, "st_waiting_pg", "I" },
707	{ &rep_stat_st_dupmasters_fid, &rep_stat_class, "st_dupmasters", "I" },
708	{ &rep_stat_st_env_id_fid, &rep_stat_class, "st_env_id", "I" },
709	{ &rep_stat_st_env_priority_fid, &rep_stat_class, "st_env_priority", "I" },
710	{ &rep_stat_st_bulk_fills_fid, &rep_stat_class, "st_bulk_fills", "I" },
711	{ &rep_stat_st_bulk_overflows_fid, &rep_stat_class, "st_bulk_overflows", "I" },
712	{ &rep_stat_st_bulk_records_fid, &rep_stat_class, "st_bulk_records", "I" },
713	{ &rep_stat_st_bulk_transfers_fid, &rep_stat_class, "st_bulk_transfers", "I" },
714	{ &rep_stat_st_client_rerequests_fid, &rep_stat_class, "st_client_rerequests", "I" },
715	{ &rep_stat_st_client_svc_req_fid, &rep_stat_class, "st_client_svc_req", "I" },
716	{ &rep_stat_st_client_svc_miss_fid, &rep_stat_class, "st_client_svc_miss", "I" },
717	{ &rep_stat_st_gen_fid, &rep_stat_class, "st_gen", "I" },
718	{ &rep_stat_st_egen_fid, &rep_stat_class, "st_egen", "I" },
719	{ &rep_stat_st_log_duplicated_fid, &rep_stat_class, "st_log_duplicated", "I" },
720	{ &rep_stat_st_log_queued_max_fid, &rep_stat_class, "st_log_queued_max", "I" },
721	{ &rep_stat_st_log_queued_total_fid, &rep_stat_class, "st_log_queued_total", "I" },
722	{ &rep_stat_st_log_records_fid, &rep_stat_class, "st_log_records", "I" },
723	{ &rep_stat_st_log_requested_fid, &rep_stat_class, "st_log_requested", "I" },
724	{ &rep_stat_st_master_fid, &rep_stat_class, "st_master", "I" },
725	{ &rep_stat_st_master_changes_fid, &rep_stat_class, "st_master_changes", "I" },
726	{ &rep_stat_st_msgs_badgen_fid, &rep_stat_class, "st_msgs_badgen", "I" },
727	{ &rep_stat_st_msgs_processed_fid, &rep_stat_class, "st_msgs_processed", "I" },
728	{ &rep_stat_st_msgs_recover_fid, &rep_stat_class, "st_msgs_recover", "I" },
729	{ &rep_stat_st_msgs_send_failures_fid, &rep_stat_class, "st_msgs_send_failures", "I" },
730	{ &rep_stat_st_msgs_sent_fid, &rep_stat_class, "st_msgs_sent", "I" },
731	{ &rep_stat_st_newsites_fid, &rep_stat_class, "st_newsites", "I" },
732	{ &rep_stat_st_nsites_fid, &rep_stat_class, "st_nsites", "I" },
733	{ &rep_stat_st_nthrottles_fid, &rep_stat_class, "st_nthrottles", "I" },
734	{ &rep_stat_st_outdated_fid, &rep_stat_class, "st_outdated", "I" },
735	{ &rep_stat_st_pg_duplicated_fid, &rep_stat_class, "st_pg_duplicated", "I" },
736	{ &rep_stat_st_pg_records_fid, &rep_stat_class, "st_pg_records", "I" },
737	{ &rep_stat_st_pg_requested_fid, &rep_stat_class, "st_pg_requested", "I" },
738	{ &rep_stat_st_txns_applied_fid, &rep_stat_class, "st_txns_applied", "I" },
739	{ &rep_stat_st_startsync_delayed_fid, &rep_stat_class, "st_startsync_delayed", "I" },
740	{ &rep_stat_st_elections_fid, &rep_stat_class, "st_elections", "I" },
741	{ &rep_stat_st_elections_won_fid, &rep_stat_class, "st_elections_won", "I" },
742	{ &rep_stat_st_election_cur_winner_fid, &rep_stat_class, "st_election_cur_winner", "I" },
743	{ &rep_stat_st_election_gen_fid, &rep_stat_class, "st_election_gen", "I" },
744	{ &rep_stat_st_election_lsn_fid, &rep_stat_class, "st_election_lsn", "L" DB_PKG "LogSequenceNumber;" },
745	{ &rep_stat_st_election_nsites_fid, &rep_stat_class, "st_election_nsites", "I" },
746	{ &rep_stat_st_election_nvotes_fid, &rep_stat_class, "st_election_nvotes", "I" },
747	{ &rep_stat_st_election_priority_fid, &rep_stat_class, "st_election_priority", "I" },
748	{ &rep_stat_st_election_status_fid, &rep_stat_class, "st_election_status", "I" },
749	{ &rep_stat_st_election_tiebreaker_fid, &rep_stat_class, "st_election_tiebreaker", "I" },
750	{ &rep_stat_st_election_votes_fid, &rep_stat_class, "st_election_votes", "I" },
751	{ &rep_stat_st_election_sec_fid, &rep_stat_class, "st_election_sec", "I" },
752	{ &rep_stat_st_election_usec_fid, &rep_stat_class, "st_election_usec", "I" },
753	{ &rep_stat_st_max_lease_sec_fid, &rep_stat_class, "st_max_lease_sec", "I" },
754	{ &rep_stat_st_max_lease_usec_fid, &rep_stat_class, "st_max_lease_usec", "I" },
755	{ &repmgr_stat_st_perm_failed_fid, &repmgr_stat_class, "st_perm_failed", "I" },
756	{ &repmgr_stat_st_msgs_queued_fid, &repmgr_stat_class, "st_msgs_queued", "I" },
757	{ &repmgr_stat_st_msgs_dropped_fid, &repmgr_stat_class, "st_msgs_dropped", "I" },
758	{ &repmgr_stat_st_connection_drop_fid, &repmgr_stat_class, "st_connection_drop", "I" },
759	{ &repmgr_stat_st_connect_fail_fid, &repmgr_stat_class, "st_connect_fail", "I" },
760	{ &seq_stat_st_wait_fid, &seq_stat_class, "st_wait", "I" },
761	{ &seq_stat_st_nowait_fid, &seq_stat_class, "st_nowait", "I" },
762	{ &seq_stat_st_current_fid, &seq_stat_class, "st_current", "J" },
763	{ &seq_stat_st_value_fid, &seq_stat_class, "st_value", "J" },
764	{ &seq_stat_st_last_value_fid, &seq_stat_class, "st_last_value", "J" },
765	{ &seq_stat_st_min_fid, &seq_stat_class, "st_min", "J" },
766	{ &seq_stat_st_max_fid, &seq_stat_class, "st_max", "J" },
767	{ &seq_stat_st_cache_size_fid, &seq_stat_class, "st_cache_size", "I" },
768	{ &seq_stat_st_flags_fid, &seq_stat_class, "st_flags", "I" },
769	{ &txn_stat_st_nrestores_fid, &txn_stat_class, "st_nrestores", "I" },
770	{ &txn_stat_st_last_ckp_fid, &txn_stat_class, "st_last_ckp", "L" DB_PKG "LogSequenceNumber;" },
771	{ &txn_stat_st_time_ckp_fid, &txn_stat_class, "st_time_ckp", "J" },
772	{ &txn_stat_st_last_txnid_fid, &txn_stat_class, "st_last_txnid", "I" },
773	{ &txn_stat_st_maxtxns_fid, &txn_stat_class, "st_maxtxns", "I" },
774	{ &txn_stat_st_naborts_fid, &txn_stat_class, "st_naborts", "I" },
775	{ &txn_stat_st_nbegins_fid, &txn_stat_class, "st_nbegins", "I" },
776	{ &txn_stat_st_ncommits_fid, &txn_stat_class, "st_ncommits", "I" },
777	{ &txn_stat_st_nactive_fid, &txn_stat_class, "st_nactive", "I" },
778	{ &txn_stat_st_nsnapshot_fid, &txn_stat_class, "st_nsnapshot", "I" },
779	{ &txn_stat_st_maxnactive_fid, &txn_stat_class, "st_maxnactive", "I" },
780	{ &txn_stat_st_maxnsnapshot_fid, &txn_stat_class, "st_maxnsnapshot", "I" },
781	{ &txn_stat_st_txnarray_fid, &txn_stat_class, "st_txnarray", "[L" DB_PKG "TransactionStats$Active;" },
782	{ &txn_stat_st_region_wait_fid, &txn_stat_class, "st_region_wait", "I" },
783	{ &txn_stat_st_region_nowait_fid, &txn_stat_class, "st_region_nowait", "I" },
784	{ &txn_stat_st_regsize_fid, &txn_stat_class, "st_regsize", "I" },
785	{ &txn_active_txnid_fid, &txn_active_class, "txnid", "I" },
786	{ &txn_active_parentid_fid, &txn_active_class, "parentid", "I" },
787	{ &txn_active_pid_fid, &txn_active_class, "pid", "I" },
788	{ &txn_active_lsn_fid, &txn_active_class, "lsn", "L" DB_PKG "LogSequenceNumber;" },
789	{ &txn_active_read_lsn_fid, &txn_active_class, "read_lsn", "L" DB_PKG "LogSequenceNumber;" },
790	{ &txn_active_mvcc_ref_fid, &txn_active_class, "mvcc_ref", "I" },
791	{ &txn_active_status_fid, &txn_active_class, "status", "I" },
792	{ &txn_active_xa_status_fid, &txn_active_class, "xa_status", "I" },
793	{ &txn_active_xid_fid, &txn_active_class, "xid", "[B" },
794	{ &txn_active_name_fid, &txn_active_class, "name", "Ljava/lang/String;" },
795/* END-STAT-FIELDS */
796
797	{ &repmgr_siteinfo_status_fid, &repmgr_siteinfo_class, "status", "I" }
798};
799
800const struct {
801	jmethodID *mid;
802	jclass *cl;
803	const char *name;
804	const char *sig;
805} all_methods[] = {
806	{ &dbenv_construct, &dbenv_class, "<init>", "(JZ)V" },
807	{ &dbt_construct, &dbt_class, "<init>", "()V" },
808	{ &dblsn_construct, &dblsn_class, "<init>", "(II)V" },
809	{ &dbpreplist_construct, &dbpreplist_class, "<init>",
810	    "(L" DB_PKG "internal/DbTxn;[B)V" },
811	{ &dbtxn_construct, &dbtxn_class, "<init>", "(JZ)V" },
812
813	{ &bt_stat_construct, &bt_stat_class, "<init>", "()V" },
814	{ &get_err_msg_method, &dbenv_class, "get_err_msg",
815	    "(Ljava/lang/String;)Ljava/lang/String;" },
816	{ &h_stat_construct, &h_stat_class, "<init>", "()V" },
817	{ &lock_stat_construct, &lock_stat_class, "<init>", "()V" },
818	{ &log_stat_construct, &log_stat_class, "<init>", "()V" },
819	{ &mpool_stat_construct, &mpool_stat_class, "<init>", "()V" },
820	{ &mpool_fstat_construct, &mpool_fstat_class, "<init>", "()V" },
821	{ &mutex_stat_construct, &mutex_stat_class, "<init>", "()V" },
822	{ &qam_stat_construct, &qam_stat_class, "<init>", "()V" },
823	{ &rep_stat_construct, &rep_stat_class, "<init>", "()V" },
824	{ &repmgr_stat_construct, &repmgr_stat_class, "<init>", "()V" },
825	{ &seq_stat_construct, &seq_stat_class, "<init>", "()V" },
826	{ &txn_stat_construct, &txn_stat_class, "<init>", "()V" },
827	{ &txn_active_construct, &txn_active_class, "<init>", "()V" },
828	{ &rephost_construct, &rephost_class, "<init>", "(Ljava/lang/String;I)V" },
829        { &repmgr_siteinfo_construct, &repmgr_siteinfo_class, "<init>",
830	    "(L" DB_PKG "ReplicationHostAddress;I)V" },
831
832	{ &dbex_construct, &dbex_class, "<init>",
833	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
834	{ &deadex_construct, &deadex_class, "<init>",
835	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
836	{ &lockex_construct, &lockex_class, "<init>",
837	    "(Ljava/lang/String;IIL" DB_PKG "DatabaseEntry;L"
838	    DB_PKG "internal/DbLock;IL" DB_PKG "internal/DbEnv;)V" },
839	{ &memex_construct, &memex_class, "<init>",
840	    "(Ljava/lang/String;L" DB_PKG "DatabaseEntry;IL"
841	    DB_PKG "internal/DbEnv;)V" },
842	{ &memex_update_method, &memex_class, "updateDatabaseEntry",
843	    "(L" DB_PKG "DatabaseEntry;)V" },
844	{ &repdupmasterex_construct, &repdupmasterex_class, "<init>",
845	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
846	{ &rephandledeadex_construct, &rephandledeadex_class, "<init>",
847	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
848	{ &repholdelectionex_construct, &repholdelectionex_class, "<init>",
849	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
850	{ &repjoinfailex_construct, &repjoinfailex_class, "<init>",
851	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
852	{ &repleaseexpiredex_construct, &repleaseexpiredex_class, "<init>",
853	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
854	{ &repleasetimeoutex_construct, &repleasetimeoutex_class, "<init>",
855	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
856	{ &replockoutex_construct, &replockoutex_class, "<init>",
857	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
858	{ &repunavailex_construct, &repunavailex_class, "<init>",
859	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
860	{ &runrecex_construct, &runrecex_class, "<init>",
861	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
862	{ &versionex_construct, &versionex_class, "<init>",
863	    "(Ljava/lang/String;IL" DB_PKG "internal/DbEnv;)V" },
864	{ &filenotfoundex_construct, &filenotfoundex_class, "<init>",
865	    "(Ljava/lang/String;)V" },
866	{ &illegalargex_construct, &illegalargex_class, "<init>",
867	    "(Ljava/lang/String;)V" },
868	{ &outofmemerr_construct, &outofmemerr_class, "<init>",
869	    "(Ljava/lang/String;)V" },
870
871	{ &lock_construct, &lock_class, "<init>", "(JZ)V" },
872
873	{ &app_dispatch_method, &dbenv_class, "handle_app_dispatch",
874	    "(L" DB_PKG "DatabaseEntry;L" DB_PKG "LogSequenceNumber;I)I" },
875	{ &panic_event_notify_method, &dbenv_class, "handle_panic_event_notify",
876	    "()V" },
877	{ &rep_client_event_notify_method, &dbenv_class,
878	    "handle_rep_client_event_notify", "()V" },
879	{ &rep_elected_event_notify_method, &dbenv_class,
880	    "handle_rep_elected_event_notify" ,"()V" },
881	{ &rep_master_event_notify_method, &dbenv_class,
882	    "handle_rep_master_event_notify", "()V" },
883	{ &rep_new_master_event_notify_method, &dbenv_class,
884	    "handle_rep_new_master_event_notify", "(I)V" },
885	{ &rep_perm_failed_event_notify_method, &dbenv_class,
886	    "handle_rep_perm_failed_event_notify", "()V" },
887	{ &rep_startup_done_event_notify_method, &dbenv_class,
888	    "handle_rep_startup_done_event_notify", "()V" },
889	{ &write_failed_event_notify_method, &dbenv_class,
890	    "handle_write_failed_event_notify", "(I)V" },
891	{ &env_feedback_method, &dbenv_class, "handle_env_feedback", "(II)V" },
892	{ &errcall_method, &dbenv_class, "handle_error",
893	    "(Ljava/lang/String;)V" },
894	{ &msgcall_method, &dbenv_class, "handle_message",
895	    "(Ljava/lang/String;)V" },
896	{ &paniccall_method, &dbenv_class, "handle_panic",
897	    "(L" DB_PKG "DatabaseException;)V" },
898	{ &rep_transport_method, &dbenv_class, "handle_rep_transport",
899	    "(L" DB_PKG "DatabaseEntry;L" DB_PKG "DatabaseEntry;L"
900	    DB_PKG "LogSequenceNumber;II)I" },
901
902	{ &append_recno_method, &db_class, "handle_append_recno",
903	    "(L" DB_PKG "DatabaseEntry;I)V" },
904	{ &bt_compare_method, &db_class, "handle_bt_compare",
905	    "([B[B)I" },
906	{ &bt_prefix_method, &db_class, "handle_bt_prefix",
907	    "(L" DB_PKG "DatabaseEntry;L" DB_PKG "DatabaseEntry;)I" },
908	{ &db_feedback_method, &db_class, "handle_db_feedback", "(II)V" },
909	{ &dup_compare_method, &db_class, "handle_dup_compare",
910	    "([B[B)I" },
911	{ &foreignkey_nullify_method, &db_class, "handle_foreignkey_nullify",
912	    "(L" DB_PKG "DatabaseEntry;L" DB_PKG "DatabaseEntry;L" DB_PKG
913	    "DatabaseEntry;)Z" },
914	{ &h_compare_method, &db_class, "handle_h_compare",
915	    "([B[B)I" },
916	{ &h_hash_method, &db_class, "handle_h_hash", "([BI)I" },
917	{ &seckey_create_method, &db_class, "handle_seckey_create",
918	    "(L" DB_PKG "DatabaseEntry;L" DB_PKG "DatabaseEntry;)[L"
919	    DB_PKG "DatabaseEntry;" },
920
921	{ &outputstream_write_method, &outputstream_class, "write", "([BII)V" }
922};
923
924#define	NELEM(x) (sizeof (x) / sizeof (x[0]))
925
926SWIGEXPORT void JNICALL Java_com_sleepycat_db_internal_db_1javaJNI_initialize(
927    JNIEnv *jenv, jclass clazz)
928{
929	jclass cl;
930	unsigned int i, j;
931
932	COMPQUIET(clazz, NULL);
933
934	if ((*jenv)->GetJavaVM(jenv, &javavm) != 0) {
935		__db_errx(NULL, "Cannot get Java VM");
936		return;
937	}
938
939	for (i = 0; i < NELEM(all_classes); i++) {
940		cl = (*jenv)->FindClass(jenv, all_classes[i].name);
941		if (cl == NULL) {
942			fprintf(stderr,
943			    "Failed to load class %s - check CLASSPATH\n",
944			    all_classes[i].name);
945			return;
946		}
947
948		/*
949		 * Wrap classes in GlobalRefs so we keep the reference between
950		 * calls.
951		 */
952		*all_classes[i].cl = (jclass)(*jenv)->NewGlobalRef(jenv, cl);
953
954		if (*all_classes[i].cl == NULL) {
955			fprintf(stderr,
956			    "Failed to create a global reference for %s\n",
957			    all_classes[i].name);
958			return;
959		}
960	}
961
962	/* Get field IDs */
963	for (i = 0; i < NELEM(all_fields); i++) {
964		*all_fields[i].fid = (*jenv)->GetFieldID(jenv,
965		    *all_fields[i].cl, all_fields[i].name, all_fields[i].sig);
966
967		if (*all_fields[i].fid == NULL) {
968			fprintf(stderr,
969			    "Failed to look up field %s with sig %s\n",
970			    all_fields[i].name, all_fields[i].sig);
971			return;
972		}
973	}
974
975	/* Get method IDs */
976	for (i = 0; i < NELEM(all_methods); i++) {
977		*all_methods[i].mid = (*jenv)->GetMethodID(jenv,
978		    *all_methods[i].cl, all_methods[i].name,
979		    all_methods[i].sig);
980
981		if (*all_methods[i].mid == NULL) {
982			for (j = 0; j < NELEM(all_classes); j++)
983				if (all_methods[i].cl == all_classes[j].cl)
984					break;
985			fprintf(stderr,
986			    "Failed to look up method %s.%s with sig %s\n",
987			    all_classes[j].name, all_methods[i].name,
988			    all_methods[i].sig);
989			return;
990		}
991	}
992}
993
994static JNIEnv *__dbj_get_jnienv(void)
995{
996	/*
997	 * Note: Different versions of the JNI disagree on the signature for
998	 * AttachCurrentThreadAsDaemon.  The most recent documentation seems to
999	 * say that (JNIEnv **) is correct, but newer JNIs seem to use
1000	 * (void **), oddly enough.
1001	 */
1002#ifdef JNI_VERSION_1_2
1003	void *jenv = 0;
1004#else
1005	JNIEnv *jenv = 0;
1006#endif
1007
1008	/*
1009	 * This should always succeed, as we are called via some Java activity.
1010	 * I think therefore I am (a thread).
1011	 */
1012	if ((*javavm)->AttachCurrentThreadAsDaemon(javavm, &jenv, 0) != 0)
1013		return (0);
1014
1015	return ((JNIEnv *)jenv);
1016}
1017
1018static jobject __dbj_wrap_DB_LSN(JNIEnv *jenv, DB_LSN *lsn)
1019{
1020	return (*jenv)->NewObject(jenv, dblsn_class, dblsn_construct,
1021	    lsn->file, lsn->offset);
1022}
1023%}
1024