2012-07-07 01:27:47 +10:00
|
|
|
/*-
|
2014-01-07 10:30:12 -05:00
|
|
|
* Public Domain 2008-2014 WiredTiger, Inc.
|
2012-07-07 01:27:47 +10:00
|
|
|
*
|
2014-01-07 10:30:12 -05:00
|
|
|
* This is free and unencumbered software released into the public domain.
|
|
|
|
|
*
|
|
|
|
|
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
|
* distribute this software, either in source code form or as a compiled
|
|
|
|
|
* binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
|
* means.
|
|
|
|
|
*
|
|
|
|
|
* In jurisdictions that recognize copyright laws, the author or authors
|
|
|
|
|
* of this software dedicate any and all copyright interest in the
|
|
|
|
|
* software to the public domain. We make this dedication for the benefit
|
|
|
|
|
* of the public at large and to the detriment of our heirs and
|
|
|
|
|
* successors. We intend this dedication to be an overt act of
|
|
|
|
|
* relinquishment in perpetuity of all present and future rights to this
|
|
|
|
|
* software under copyright law.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
2012-07-07 01:27:47 +10:00
|
|
|
*
|
|
|
|
|
* wiredtiger.i
|
|
|
|
|
* The SWIG interface file defining the wiredtiger Java API.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
%module wiredtiger
|
|
|
|
|
|
|
|
|
|
%include "enums.swg"
|
|
|
|
|
%include "typemaps.i"
|
|
|
|
|
|
|
|
|
|
%pragma(java) jniclasscode=%{
|
|
|
|
|
static {
|
|
|
|
|
try {
|
2012-07-09 16:19:51 +10:00
|
|
|
System.loadLibrary("wiredtiger_java");
|
2012-07-07 01:27:47 +10:00
|
|
|
} catch (UnsatisfiedLinkError e) {
|
|
|
|
|
System.err.println("Native code library failed to load. \n" + e);
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%{
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
#include "../src/include/wt_internal.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Closed handle checking:
|
|
|
|
|
*
|
|
|
|
|
* The typedef WT_CURSOR_NULLABLE used in wiredtiger.h is only made
|
|
|
|
|
* visible to the SWIG parser and is used to identify arguments of
|
|
|
|
|
* Cursor type that are permitted to be null. Likewise, typedefs
|
|
|
|
|
* WT_{CURSOR,SESSION,CONNECTION}_CLOSED identify 'close' calls that
|
|
|
|
|
* need explicit nulling of the swigCPtr. These typedefs permit
|
|
|
|
|
* special casing in typemaps for input args.
|
|
|
|
|
*
|
|
|
|
|
* We want SWIG to see these 'fake' typenames, but not the compiler.
|
|
|
|
|
*/
|
|
|
|
|
#define WT_CURSOR_NULLABLE WT_CURSOR
|
|
|
|
|
#define WT_CURSOR_CLOSED WT_CURSOR
|
|
|
|
|
#define WT_SESSION_CLOSED WT_SESSION
|
|
|
|
|
#define WT_CONNECTION_CLOSED WT_CONNECTION
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* For Connections, Sessions and Cursors created in Java, each of
|
|
|
|
|
* WT_CONNECTION_IMPL, WT_SESSION_IMPL and WT_CURSOR have a
|
|
|
|
|
* lang_private field that store a pointer to a JAVA_CALLBACK, alloced
|
|
|
|
|
* during the various open calls. {conn,session,cursor}CloseHandler()
|
|
|
|
|
* functions reach into the associated java object, set the swigCPtr
|
|
|
|
|
* to 0, and free the JAVA_CALLBACK. Typemaps matching Connection,
|
|
|
|
|
* Session, Cursor args use the NULL_CHECK macro, which checks if
|
|
|
|
|
* swigCPtr is 0.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
JNIEnv *jnienv; /* jni env that created the Session/Cursor */
|
|
|
|
|
jobject jobj; /* the java Session/Cursor object */
|
|
|
|
|
jfieldID fid; /* cached Cursor.swigCPtr field id in session */
|
|
|
|
|
} JAVA_CALLBACK;
|
2012-08-16 22:53:20 +10:00
|
|
|
|
2013-02-13 19:14:40 +11:00
|
|
|
static void throwWiredTigerException(JNIEnv *jenv, const char *msg) {
|
|
|
|
|
jclass excep = (*jenv)->FindClass(jenv, "com/wiredtiger/db/WiredTigerException");
|
2012-07-09 16:19:51 +10:00
|
|
|
if (excep)
|
|
|
|
|
(*jenv)->ThrowNew(jenv, excep, msg);
|
2012-07-07 01:27:47 +10:00
|
|
|
}
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
|
2012-07-07 01:27:47 +10:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
/* No finalizers */
|
|
|
|
|
%typemap(javafinalize) SWIGTYPE ""
|
|
|
|
|
|
|
|
|
|
/* Event handlers are not supported in Java. */
|
|
|
|
|
%typemap(in, numinputs=0) WT_EVENT_HANDLER * %{ $1 = NULL; %}
|
|
|
|
|
|
|
|
|
|
/* Allow silently passing the Java object and JNIEnv into our code. */
|
|
|
|
|
%typemap(in, numinputs=0) jobject *jthis %{ $1 = jarg1_; %}
|
|
|
|
|
%typemap(in, numinputs=0) JNIEnv * %{ $1 = jenv; %}
|
|
|
|
|
|
|
|
|
|
/* 64 bit typemaps. */
|
|
|
|
|
%typemap(jni) uint64_t "jlong"
|
|
|
|
|
%typemap(jtype) uint64_t "long"
|
|
|
|
|
%typemap(jstype) uint64_t "long"
|
|
|
|
|
|
|
|
|
|
%typemap(javain) uint64_t "$javainput"
|
|
|
|
|
%typemap(javaout) uint64_t {
|
2012-07-09 16:19:51 +10:00
|
|
|
return $jnicall;
|
2012-07-07 01:27:47 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return byte[] from cursor.get_value */
|
2013-03-26 12:42:57 +11:00
|
|
|
%typemap(jni) WT_ITEM, WT_ITEM * "jbyteArray"
|
|
|
|
|
%typemap(jtype) WT_ITEM, WT_ITEM * "byte[]"
|
|
|
|
|
%typemap(jstype) WT_ITEM, WT_ITEM * "byte[]"
|
2012-07-07 01:27:47 +10:00
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
%typemap(javain) WT_ITEM, WT_ITEM * "$javainput"
|
|
|
|
|
%typemap(javaout) WT_ITEM, WT_ITEM * {
|
2012-07-09 16:19:51 +10:00
|
|
|
return $jnicall;
|
2012-07-07 01:27:47 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%typemap(in) WT_ITEM * (WT_ITEM item) %{
|
2012-07-09 16:19:51 +10:00
|
|
|
$1 = &item;
|
|
|
|
|
$1->data = (*jenv)->GetByteArrayElements(jenv, $input, 0);
|
|
|
|
|
$1->size = (*jenv)->GetArrayLength(jenv, $input);
|
2012-07-07 01:27:47 +10:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%typemap(argout) WT_ITEM * %{
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
(*jenv)->ReleaseByteArrayElements(jenv, $input, (void *)$1->data, 0);
|
2012-07-07 01:27:47 +10:00
|
|
|
%}
|
|
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
%typemap(out) WT_ITEM %{
|
|
|
|
|
if ($1.data == NULL)
|
2012-07-09 16:19:51 +10:00
|
|
|
$result = NULL;
|
2013-03-26 12:42:57 +11:00
|
|
|
else if (($result = (*jenv)->NewByteArray(jenv, $1.size)) != NULL) {
|
2012-07-09 16:19:51 +10:00
|
|
|
(*jenv)->SetByteArrayRegion(jenv,
|
2013-03-26 12:42:57 +11:00
|
|
|
$result, 0, $1.size, $1.data);
|
2012-07-09 16:19:51 +10:00
|
|
|
}
|
2012-07-07 01:27:47 +10:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
/* Don't require empty config strings. */
|
|
|
|
|
%typemap(default) const char *config %{ $1 = NULL; %}
|
|
|
|
|
|
|
|
|
|
%typemap(out) int %{
|
2012-07-09 16:19:51 +10:00
|
|
|
if ($1 != 0 && $1 != WT_NOTFOUND) {
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror($1));
|
2012-07-09 16:19:51 +10:00
|
|
|
return $null;
|
|
|
|
|
}
|
|
|
|
|
$result = $1;
|
2012-07-07 01:27:47 +10:00
|
|
|
%}
|
|
|
|
|
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
%define NULL_CHECK(val, name)
|
|
|
|
|
if (!val) {
|
|
|
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException,
|
|
|
|
|
#name " is null");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
%enddef
|
|
|
|
|
|
|
|
|
|
%define WT_CLASS(type, class, name, closeHandler)
|
2012-07-07 01:27:47 +10:00
|
|
|
/*
|
|
|
|
|
* Extra 'self' elimination.
|
|
|
|
|
* The methods we're wrapping look like this:
|
|
|
|
|
* struct __wt_xxx {
|
2012-07-09 16:19:51 +10:00
|
|
|
* int method(WT_XXX *, ...otherargs...);
|
2012-07-07 01:27:47 +10:00
|
|
|
* };
|
|
|
|
|
* To SWIG, that is equivalent to:
|
2012-07-09 16:19:51 +10:00
|
|
|
* int method(struct __wt_xxx *self, WT_XXX *, ...otherargs...);
|
2012-07-07 01:27:47 +10:00
|
|
|
* and we use consecutive argument matching of typemaps to convert two args to
|
|
|
|
|
* one.
|
|
|
|
|
*/
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
%typemap(in, numinputs=0) type *name {
|
|
|
|
|
$1 = *(type **)&jarg1;
|
|
|
|
|
NULL_CHECK($1, $1_name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%typemap(in, numinputs=0) class ## _CLOSED *name {
|
|
|
|
|
$1 = *(type **)&jarg1;
|
|
|
|
|
NULL_CHECK($1, $1_name)
|
|
|
|
|
closeHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%typemap(in) class ## _NULLABLE * {
|
|
|
|
|
$1 = *(type **)&$input;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%typemap(in) type * {
|
|
|
|
|
$1 = *(type **)&$input;
|
|
|
|
|
NULL_CHECK($1, $1_name)
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-25 16:13:39 +11:00
|
|
|
%typemap(javaimports) type "
|
|
|
|
|
/**
|
|
|
|
|
* @copydoc class
|
|
|
|
|
* @ingroup wt_java
|
|
|
|
|
*/"
|
2012-07-07 01:27:47 +10:00
|
|
|
%enddef
|
|
|
|
|
|
2013-02-25 16:13:39 +11:00
|
|
|
%pragma(java) moduleimports=%{
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup wt_java WiredTiger Java API
|
|
|
|
|
*
|
|
|
|
|
* Java wrappers around the WiredTiger C API.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ingroup wt_java
|
|
|
|
|
*/
|
|
|
|
|
%}
|
|
|
|
|
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
WT_CLASS(struct __wt_connection, WT_CONNECTION, connection, connCloseHandler($1))
|
|
|
|
|
WT_CLASS(struct __wt_session, WT_SESSION, session, sessionCloseHandler($1))
|
|
|
|
|
WT_CLASS(struct __wt_cursor, WT_CURSOR, cursor, cursorCloseHandler($1))
|
2012-07-07 01:27:47 +10:00
|
|
|
|
2013-02-19 17:06:41 +11:00
|
|
|
%define COPYDOC(SIGNATURE_CLASS, CLASS, METHOD)
|
2013-02-25 16:13:39 +11:00
|
|
|
%javamethodmodifiers SIGNATURE_CLASS::METHOD "
|
|
|
|
|
/**
|
2013-02-19 17:06:41 +11:00
|
|
|
* @copydoc CLASS::METHOD
|
|
|
|
|
*/
|
|
|
|
|
public ";
|
|
|
|
|
%enddef
|
|
|
|
|
|
2013-02-19 18:40:27 +11:00
|
|
|
%include "java_doc.i"
|
2013-02-19 17:06:41 +11:00
|
|
|
|
2012-07-07 01:27:47 +10:00
|
|
|
/* WT_CURSOR customization. */
|
|
|
|
|
/* First, replace the varargs get / set methods with Java equivalents. */
|
|
|
|
|
%ignore __wt_cursor::get_key;
|
|
|
|
|
%ignore __wt_cursor::get_value;
|
|
|
|
|
%ignore __wt_cursor::set_key;
|
|
|
|
|
%ignore __wt_cursor::set_value;
|
|
|
|
|
%ignore __wt_cursor::insert;
|
|
|
|
|
%ignore __wt_cursor::remove;
|
|
|
|
|
%ignore __wt_cursor::search;
|
|
|
|
|
%ignore __wt_cursor::search_near;
|
|
|
|
|
%ignore __wt_cursor::update;
|
|
|
|
|
%javamethodmodifiers __wt_cursor::next "protected";
|
|
|
|
|
%rename (next_wrap) __wt_cursor::next;
|
|
|
|
|
%javamethodmodifiers __wt_cursor::prev "protected";
|
|
|
|
|
%rename (prev_wrap) __wt_cursor::prev;
|
2013-02-08 14:15:19 +11:00
|
|
|
%javamethodmodifiers __wt_cursor::key_format "protected";
|
|
|
|
|
%javamethodmodifiers __wt_cursor::value_format "protected";
|
2012-07-07 01:27:47 +10:00
|
|
|
|
2012-11-29 10:38:29 +11:00
|
|
|
%ignore __wt_cursor::compare(WT_CURSOR *, WT_CURSOR *, int *);
|
|
|
|
|
%rename (compare_wrap) __wt_cursor::compare;
|
2012-08-16 22:53:20 +10:00
|
|
|
|
2012-07-07 01:27:47 +10:00
|
|
|
/* SWIG magic to turn Java byte strings into data / size. */
|
|
|
|
|
%apply (char *STRING, int LENGTH) { (char *data, int size) };
|
|
|
|
|
|
|
|
|
|
/* Status from search_near */
|
|
|
|
|
%javaconst(1);
|
|
|
|
|
%inline %{
|
|
|
|
|
enum SearchStatus { FOUND, NOTFOUND, SMALLER, LARGER };
|
|
|
|
|
%}
|
|
|
|
|
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
%wrapper %{
|
|
|
|
|
/* Zero out SWIG's pointer to the C object,
|
|
|
|
|
* equivalent to 'jobj.swigCPtr = 0;' in java.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
javaClose(JAVA_CALLBACK *jcb, jfieldID *pfid)
|
|
|
|
|
{
|
|
|
|
|
jclass cls;
|
|
|
|
|
jfieldID fid;
|
|
|
|
|
JNIEnv *env;
|
|
|
|
|
|
|
|
|
|
env = jcb->jnienv;
|
|
|
|
|
|
|
|
|
|
if (pfid == NULL || *pfid == NULL) {
|
|
|
|
|
cls = (*env)->GetObjectClass(env, jcb->jobj);
|
2013-12-28 10:16:01 -05:00
|
|
|
fid = (*env)->GetFieldID(env, cls, "swigCPtr", "J");
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
if (pfid != NULL)
|
|
|
|
|
*pfid = fid;
|
2013-12-28 10:16:01 -05:00
|
|
|
} else {
|
|
|
|
|
fid = *pfid;
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
}
|
2013-12-28 10:16:01 -05:00
|
|
|
(*env)->SetLongField(env, jcb->jobj, fid, 0L);
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
(*env)->DeleteGlobalRef(env, jcb->jobj);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Connection specific close handler. */
|
|
|
|
|
static int
|
|
|
|
|
connCloseHandler(WT_CONNECTION *conn_arg)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
JAVA_CALLBACK *jcb;
|
|
|
|
|
WT_CONNECTION_IMPL *conn;
|
|
|
|
|
|
|
|
|
|
conn = (WT_CONNECTION_IMPL *)conn_arg;
|
|
|
|
|
jcb = (JAVA_CALLBACK *)conn->lang_private;
|
|
|
|
|
conn->lang_private = NULL;
|
|
|
|
|
ret = javaClose(jcb, NULL);
|
|
|
|
|
__wt_free(conn->default_session, jcb);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Session specific close handler. */
|
|
|
|
|
static int
|
|
|
|
|
sessionCloseHandler(WT_SESSION *session_arg)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
JAVA_CALLBACK *jcb;
|
|
|
|
|
WT_SESSION_IMPL *session;
|
|
|
|
|
|
|
|
|
|
session = (WT_SESSION_IMPL *)session_arg;
|
|
|
|
|
jcb = (JAVA_CALLBACK *)session->lang_private;
|
|
|
|
|
session->lang_private = NULL;
|
|
|
|
|
ret = javaClose(jcb, NULL);
|
|
|
|
|
__wt_free(session, jcb);
|
|
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Cursor specific close handler. */
|
|
|
|
|
static int
|
|
|
|
|
cursorCloseHandler(WT_CURSOR *cursor)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
JAVA_CALLBACK *jcb;
|
|
|
|
|
JAVA_CALLBACK *sess_jcb;
|
|
|
|
|
|
|
|
|
|
jcb = (JAVA_CALLBACK *)cursor->lang_private;
|
|
|
|
|
sess_jcb = (JAVA_CALLBACK *)
|
|
|
|
|
((WT_SESSION_IMPL *)cursor->session)->lang_private;
|
|
|
|
|
cursor->lang_private = NULL;
|
2013-12-28 10:16:01 -05:00
|
|
|
ret = javaClose(jcb, sess_jcb ? &sess_jcb->fid : NULL);
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
__wt_free((WT_SESSION_IMPL *)cursor->session, jcb);
|
|
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add event handler support. */
|
|
|
|
|
static int
|
|
|
|
|
javaCloseHandler(WT_EVENT_HANDLER *handler, WT_SESSION *session,
|
|
|
|
|
WT_CURSOR *cursor)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
WT_UNUSED(handler);
|
|
|
|
|
|
|
|
|
|
if (cursor != NULL)
|
|
|
|
|
ret = cursorCloseHandler(cursor);
|
|
|
|
|
else
|
|
|
|
|
ret = sessionCloseHandler(session);
|
|
|
|
|
return (ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WT_EVENT_HANDLER javaApiEventHandler = {NULL, NULL, NULL, javaCloseHandler};
|
|
|
|
|
%}
|
|
|
|
|
|
2012-07-07 01:27:47 +10:00
|
|
|
%extend __wt_cursor {
|
2013-02-08 14:15:19 +11:00
|
|
|
|
2012-07-09 16:19:51 +10:00
|
|
|
%javamethodmodifiers get_key_wrap "protected";
|
2013-03-26 12:42:57 +11:00
|
|
|
WT_ITEM get_key_wrap(JNIEnv *jenv) {
|
2012-07-09 16:19:51 +10:00
|
|
|
WT_ITEM k;
|
|
|
|
|
int ret;
|
2013-03-26 12:42:57 +11:00
|
|
|
k.data = NULL;
|
|
|
|
|
if ((ret = $self->get_key($self, &k)) != 0)
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror(ret));
|
2013-03-26 12:42:57 +11:00
|
|
|
return k;
|
2012-07-09 16:19:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%javamethodmodifiers get_value_wrap "protected";
|
2013-03-26 12:42:57 +11:00
|
|
|
WT_ITEM get_value_wrap(JNIEnv *jenv) {
|
2012-07-09 16:19:51 +10:00
|
|
|
WT_ITEM v;
|
|
|
|
|
int ret;
|
2013-03-26 12:42:57 +11:00
|
|
|
v.data = NULL;
|
|
|
|
|
if ((ret = $self->get_value($self, &v)) != 0)
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror(ret));
|
2013-03-26 12:42:57 +11:00
|
|
|
return v;
|
2012-07-09 16:19:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%javamethodmodifiers insert_wrap "protected";
|
|
|
|
|
int insert_wrap(WT_ITEM *k, WT_ITEM *v) {
|
|
|
|
|
$self->set_key($self, k);
|
|
|
|
|
$self->set_value($self, v);
|
|
|
|
|
return $self->insert($self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%javamethodmodifiers remove_wrap "protected";
|
|
|
|
|
int remove_wrap(WT_ITEM *k) {
|
|
|
|
|
$self->set_key($self, k);
|
|
|
|
|
return $self->remove($self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%javamethodmodifiers search_wrap "protected";
|
|
|
|
|
int search_wrap(WT_ITEM *k) {
|
|
|
|
|
$self->set_key($self, k);
|
|
|
|
|
return $self->search($self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%javamethodmodifiers search_near_wrap "protected";
|
|
|
|
|
enum SearchStatus search_near_wrap(JNIEnv *jenv, WT_ITEM *k) {
|
|
|
|
|
int cmp, ret;
|
|
|
|
|
|
|
|
|
|
$self->set_key($self, k);
|
|
|
|
|
ret = $self->search_near(self, &cmp);
|
|
|
|
|
if (ret != 0 && ret != WT_NOTFOUND)
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror(ret));
|
2012-07-09 16:19:51 +10:00
|
|
|
if (ret == 0)
|
|
|
|
|
return (cmp == 0 ? FOUND : cmp < 0 ? SMALLER : LARGER);
|
|
|
|
|
return (NOTFOUND);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%javamethodmodifiers update_wrap "protected";
|
|
|
|
|
int update_wrap(WT_ITEM *k, WT_ITEM *v) {
|
|
|
|
|
$self->set_key($self, k);
|
|
|
|
|
$self->set_value($self, v);
|
2012-07-17 14:49:07 +10:00
|
|
|
return $self->update($self);
|
2012-07-09 16:19:51 +10:00
|
|
|
}
|
2012-08-16 22:53:20 +10:00
|
|
|
|
2012-11-29 15:54:50 +11:00
|
|
|
int compare_wrap(JNIEnv *jenv, WT_CURSOR *other) {
|
2012-11-29 10:38:29 +11:00
|
|
|
int cmp, ret = $self->compare($self, other, &cmp);
|
2012-08-16 22:53:20 +10:00
|
|
|
if (ret != 0)
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror(ret));
|
2012-11-29 15:54:50 +11:00
|
|
|
return cmp;
|
2012-08-16 22:53:20 +10:00
|
|
|
}
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
|
|
|
|
|
%javamethodmodifiers java_init "protected";
|
|
|
|
|
int java_init(jobject jcursor) {
|
|
|
|
|
JAVA_CALLBACK *jcb = (JAVA_CALLBACK *)$self->lang_private;
|
|
|
|
|
jcb->jobj = JCALL1(NewGlobalRef, jcb->jnienv, jcursor);
|
|
|
|
|
JCALL1(DeleteLocalRef, jcb->jnienv, jcursor);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
2012-07-07 01:27:47 +10:00
|
|
|
}
|
|
|
|
|
|
2013-02-08 14:15:19 +11:00
|
|
|
/* Cache key/value formats in Cursor */
|
|
|
|
|
%typemap(javabody) struct __wt_cursor %{
|
|
|
|
|
private long swigCPtr;
|
|
|
|
|
protected boolean swigCMemOwn;
|
2013-02-13 19:14:40 +11:00
|
|
|
protected String keyFormat;
|
|
|
|
|
protected String valueFormat;
|
|
|
|
|
protected PackOutputStream keyPacker;
|
|
|
|
|
protected PackOutputStream valuePacker;
|
|
|
|
|
protected PackInputStream keyUnpacker;
|
|
|
|
|
protected PackInputStream valueUnpacker;
|
2013-02-08 14:15:19 +11:00
|
|
|
|
|
|
|
|
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
|
|
|
|
|
swigCMemOwn = cMemoryOwn;
|
|
|
|
|
swigCPtr = cPtr;
|
2013-02-13 19:14:40 +11:00
|
|
|
keyFormat = getKey_format();
|
|
|
|
|
valueFormat = getValue_format();
|
|
|
|
|
keyPacker = new PackOutputStream(keyFormat);
|
|
|
|
|
valuePacker = new PackOutputStream(valueFormat);
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
wiredtigerJNI.Cursor_java_init(swigCPtr, this, this);
|
2013-02-08 14:15:19 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static long getCPtr($javaclassname obj) {
|
|
|
|
|
return (obj == null) ? 0 : obj.swigCPtr;
|
|
|
|
|
}
|
|
|
|
|
%}
|
|
|
|
|
|
2012-07-07 01:27:47 +10:00
|
|
|
%typemap(javacode) struct __wt_cursor %{
|
2013-02-08 14:15:19 +11:00
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Retrieve the format string for this cursor's key.
|
|
|
|
|
*/
|
|
|
|
|
public String getKeyFormat() {
|
|
|
|
|
return keyFormat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the format string for this cursor's value.
|
|
|
|
|
*/
|
|
|
|
|
public String getValueFormat() {
|
|
|
|
|
return valueFormat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a byte to the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append.
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putKeyByte(byte value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
keyPacker.addByte(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a byte array to the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append.
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putKeyByteArray(byte[] value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
this.putKeyByteArray(value, 0, value.length);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a byte array to the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append.
|
|
|
|
|
* \param off The offset into value at which to start.
|
|
|
|
|
* \param len The length of the byte array.
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putKeyByteArray(byte[] value, int off, int len)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
keyPacker.addByteArray(value, off, len);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append an integer to the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putKeyInt(int value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
keyPacker.addInt(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a long to the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putKeyLong(long value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
keyPacker.addLong(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a short integer to the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putKeyShort(short value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
keyPacker.addShort(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a string to the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putKeyString(String value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
keyPacker.addString(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a byte to the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putValueByte(byte value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
valuePacker.addByte(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a byte array to the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putValueByteArray(byte[] value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
this.putValueByteArray(value, 0, value.length);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a byte array to the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \param off The offset into value at which to start.
|
|
|
|
|
* \param len The length of the byte array.
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putValueByteArray(byte[] value, int off, int len)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
valuePacker.addByteArray(value, off, len);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append an integer to the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putValueInt(int value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
valuePacker.addInt(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a long to the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putValueLong(long value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
valuePacker.addLong(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a short integer to the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putValueShort(short value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
valuePacker.addShort(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a string to the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param value The value to append
|
|
|
|
|
* \return This cursor object, so put calls can be chained.
|
|
|
|
|
*/
|
|
|
|
|
public Cursor putValueString(String value)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
valuePacker.addString(value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public byte getKeyByte()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return keyUnpacker.getByte();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte array from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param output The byte array where the returned value will be stored.
|
|
|
|
|
* The array should be large enough to store the entire
|
|
|
|
|
* data item, if not a truncated value will be returned.
|
|
|
|
|
*/
|
|
|
|
|
public void getKeyByteArray(byte[] output)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
this.getKeyByteArray(output, 0, output.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte array from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \param output The byte array where the returned value will be stored.
|
|
|
|
|
* \param off Offset into the destination buffer to start copying into.
|
|
|
|
|
* \param len The length should be large enough to store the entire
|
|
|
|
|
* data item, if not a truncated value will be returned.
|
|
|
|
|
*/
|
|
|
|
|
public void getKeyByteArray(byte[] output, int off, int len)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
keyUnpacker.getByteArray(output, off, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte array from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public byte[] getKeyByteArray()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return keyUnpacker.getByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve an integer from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public int getKeyInt()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return keyUnpacker.getInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a long from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public long getKeyLong()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return keyUnpacker.getLong();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a short integer from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public short getKeyShort()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return keyUnpacker.getShort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a string from the cursor's key.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public String getKeyString()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return keyUnpacker.getString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public byte getValueByte()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return valueUnpacker.getByte();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte array from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param output The byte array where the returned value will be stored.
|
|
|
|
|
* The array should be large enough to store the entire
|
|
|
|
|
* data item, if not a truncated value will be returned.
|
|
|
|
|
*/
|
|
|
|
|
public void getValueByteArray(byte[] output)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
this.getValueByteArray(output, 0, output.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte array from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \param output The byte array where the returned value will be stored.
|
|
|
|
|
* \param off Offset into the destination buffer to start copying into.
|
|
|
|
|
* \param len The length should be large enough to store the entire
|
|
|
|
|
* data item, if not a truncated value will be returned.
|
|
|
|
|
*/
|
|
|
|
|
public void getValueByteArray(byte[] output, int off, int len)
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
valueUnpacker.getByteArray(output, off, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a byte array from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public byte[] getValueByteArray()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return valueUnpacker.getByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve an integer from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public int getValueInt()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return valueUnpacker.getInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a long from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public long getValueLong()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return valueUnpacker.getLong();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a short integer from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public short getValueShort()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return valueUnpacker.getShort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a string from the cursor's value.
|
|
|
|
|
*
|
|
|
|
|
* \return The requested value.
|
|
|
|
|
*/
|
|
|
|
|
public String getValueString()
|
|
|
|
|
throws WiredTigerPackingException {
|
|
|
|
|
return valueUnpacker.getString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert the cursor's current key/value into the table.
|
|
|
|
|
*
|
|
|
|
|
* \return The status of the operation.
|
|
|
|
|
*/
|
2012-07-09 16:19:51 +10:00
|
|
|
public int insert() {
|
2013-03-26 12:42:57 +11:00
|
|
|
byte[] key = keyPacker.getValue();
|
|
|
|
|
byte[] value = valuePacker.getValue();
|
|
|
|
|
keyPacker.reset();
|
|
|
|
|
valuePacker.reset();
|
2012-07-09 16:19:51 +10:00
|
|
|
return insert_wrap(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Update the cursor's current key/value into the table.
|
|
|
|
|
*
|
|
|
|
|
* \return The status of the operation.
|
|
|
|
|
*/
|
2012-07-09 16:19:51 +10:00
|
|
|
public int update() {
|
2013-03-26 12:42:57 +11:00
|
|
|
byte[] key = keyPacker.getValue();
|
|
|
|
|
byte[] value = valuePacker.getValue();
|
|
|
|
|
keyPacker.reset();
|
|
|
|
|
valuePacker.reset();
|
2012-07-09 16:19:51 +10:00
|
|
|
return update_wrap(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Remove the cursor's current key/value into the table.
|
|
|
|
|
*
|
|
|
|
|
* \return The status of the operation.
|
|
|
|
|
*/
|
2012-07-09 16:19:51 +10:00
|
|
|
public int remove() {
|
2013-03-26 12:42:57 +11:00
|
|
|
byte[] key = keyPacker.getValue();
|
|
|
|
|
keyPacker.reset();
|
2012-07-09 16:19:51 +10:00
|
|
|
return remove_wrap(key);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Compare this cursor's position to another Cursor.
|
|
|
|
|
*
|
|
|
|
|
* \return The result of the comparison.
|
|
|
|
|
*/
|
2012-11-29 15:54:50 +11:00
|
|
|
public int compare(Cursor other) {
|
|
|
|
|
return compare_wrap(other);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Retrieve the next item in the table.
|
|
|
|
|
*
|
|
|
|
|
* \return The result of the comparison.
|
|
|
|
|
*/
|
2012-07-09 16:19:51 +10:00
|
|
|
public int next() {
|
|
|
|
|
int ret = next_wrap();
|
2013-03-26 12:42:57 +11:00
|
|
|
keyPacker.reset();
|
|
|
|
|
valuePacker.reset();
|
2013-02-13 19:14:40 +11:00
|
|
|
keyUnpacker = (ret == 0) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(keyFormat, get_key_wrap()) : null;
|
2013-02-13 19:14:40 +11:00
|
|
|
valueUnpacker = (ret == 0) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(valueFormat, get_value_wrap()) : null;
|
2012-07-09 16:19:51 +10:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Retrieve the previous item in the table.
|
|
|
|
|
*
|
|
|
|
|
* \return The result of the comparison.
|
|
|
|
|
*/
|
2012-07-09 16:19:51 +10:00
|
|
|
public int prev() {
|
|
|
|
|
int ret = prev_wrap();
|
2013-03-26 12:42:57 +11:00
|
|
|
keyPacker.reset();
|
|
|
|
|
valuePacker.reset();
|
2013-02-13 19:14:40 +11:00
|
|
|
keyUnpacker = (ret == 0) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(keyFormat, get_key_wrap()) : null;
|
2013-02-13 19:14:40 +11:00
|
|
|
valueUnpacker = (ret == 0) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(valueFormat, get_value_wrap()) : null;
|
2012-07-09 16:19:51 +10:00
|
|
|
return ret;
|
|
|
|
|
}
|
2013-02-19 18:00:50 +11:00
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Search for an item in the table.
|
|
|
|
|
*
|
|
|
|
|
* \return The result of the comparison.
|
|
|
|
|
*/
|
2012-07-09 16:19:51 +10:00
|
|
|
public int search() {
|
2013-02-13 19:14:40 +11:00
|
|
|
int ret = search_wrap(keyPacker.getValue());
|
2013-03-26 12:42:57 +11:00
|
|
|
keyPacker.reset();
|
|
|
|
|
valuePacker.reset();
|
2013-02-13 19:14:40 +11:00
|
|
|
keyUnpacker = (ret == 0) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(keyFormat, get_key_wrap()) : null;
|
2013-02-13 19:14:40 +11:00
|
|
|
valueUnpacker = (ret == 0) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(valueFormat, get_value_wrap()) : null;
|
2012-07-09 16:19:51 +10:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:42:57 +11:00
|
|
|
/**
|
|
|
|
|
* Search for an item in the table.
|
|
|
|
|
*
|
|
|
|
|
* \return The result of the comparison.
|
|
|
|
|
*/
|
2012-07-09 16:19:51 +10:00
|
|
|
public SearchStatus search_near() {
|
2013-02-13 19:14:40 +11:00
|
|
|
SearchStatus ret = search_near_wrap(keyPacker.getValue());
|
2013-03-26 12:42:57 +11:00
|
|
|
keyPacker.reset();
|
|
|
|
|
valuePacker.reset();
|
2013-02-13 19:14:40 +11:00
|
|
|
keyUnpacker = (ret != SearchStatus.NOTFOUND) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(keyFormat, get_key_wrap()) : null;
|
2013-02-13 19:14:40 +11:00
|
|
|
valueUnpacker = (ret != SearchStatus.NOTFOUND) ?
|
2013-03-26 12:42:57 +11:00
|
|
|
new PackInputStream(valueFormat, get_value_wrap()) : null;
|
2012-07-09 16:19:51 +10:00
|
|
|
return ret;
|
|
|
|
|
}
|
2012-07-07 01:27:47 +10:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
/* Remove / rename parts of the C API that we don't want in Java. */
|
|
|
|
|
%immutable __wt_cursor::session;
|
|
|
|
|
%immutable __wt_cursor::uri;
|
|
|
|
|
%immutable __wt_cursor::key_format;
|
|
|
|
|
%immutable __wt_cursor::value_format;
|
|
|
|
|
%immutable __wt_session::connection;
|
|
|
|
|
|
|
|
|
|
%ignore __wt_collator;
|
|
|
|
|
%ignore __wt_connection::add_collator;
|
|
|
|
|
%ignore __wt_compressor;
|
|
|
|
|
%ignore __wt_connection::add_compressor;
|
|
|
|
|
%ignore __wt_data_source;
|
|
|
|
|
%ignore __wt_connection::add_data_source;
|
|
|
|
|
%ignore __wt_event_handler;
|
|
|
|
|
%ignore __wt_extractor;
|
|
|
|
|
%ignore __wt_connection::add_extractor;
|
|
|
|
|
%ignore __wt_item;
|
|
|
|
|
%ignore __wt_session::msg_printf;
|
|
|
|
|
|
|
|
|
|
%ignore wiredtiger_struct_pack;
|
|
|
|
|
%ignore wiredtiger_struct_size;
|
|
|
|
|
%ignore wiredtiger_struct_unpack;
|
|
|
|
|
|
|
|
|
|
%ignore wiredtiger_version;
|
|
|
|
|
|
2013-04-18 15:39:19 +10:00
|
|
|
%ignore __wt_connection::get_extension_api;
|
2013-04-19 17:11:21 +10:00
|
|
|
%ignore wiredtiger_extension_init;
|
|
|
|
|
%ignore wiredtiger_extension_terminate;
|
2012-07-07 01:27:47 +10:00
|
|
|
|
|
|
|
|
%ignore wiredtiger_open;
|
2013-02-25 16:13:39 +11:00
|
|
|
%javamethodmodifiers wiredtiger_open_wrap "
|
|
|
|
|
/**
|
|
|
|
|
* @copydoc ::wiredtiger_open
|
|
|
|
|
*/
|
|
|
|
|
public ";
|
|
|
|
|
|
2012-07-07 01:27:47 +10:00
|
|
|
%rename(open) wiredtiger_open_wrap;
|
|
|
|
|
%ignore __wt_connection::open_session;
|
|
|
|
|
%rename(open_session) __wt_connection::open_session_wrap;
|
|
|
|
|
%ignore __wt_session::open_cursor;
|
2013-03-25 16:41:47 +11:00
|
|
|
%javamethodmodifiers __wt_session::open_cursor_wrap "
|
|
|
|
|
/**
|
|
|
|
|
* @copydoc WT_SESSION::open_cursor
|
|
|
|
|
*/
|
|
|
|
|
public ";
|
2012-07-07 01:27:47 +10:00
|
|
|
%rename(open_cursor) __wt_session::open_cursor_wrap;
|
|
|
|
|
|
|
|
|
|
%rename(Cursor) __wt_cursor;
|
|
|
|
|
%rename(Session) __wt_session;
|
|
|
|
|
%rename(Connection) __wt_connection;
|
|
|
|
|
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
%define TRACKED_CLASS(jclassname, ctypename, java_init_fcn, implclass)
|
|
|
|
|
%ignore jclassname::jclassname();
|
|
|
|
|
|
|
|
|
|
%typemap(javabody) struct ctypename %{
|
|
|
|
|
private long swigCPtr;
|
|
|
|
|
protected boolean swigCMemOwn;
|
|
|
|
|
|
|
|
|
|
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
|
|
|
|
|
swigCMemOwn = cMemoryOwn;
|
|
|
|
|
swigCPtr = cPtr;
|
|
|
|
|
java_init_fcn(swigCPtr, this, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static long getCPtr($javaclassname obj) {
|
|
|
|
|
return (obj == null) ? 0 : obj.swigCPtr;
|
|
|
|
|
}
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%extend ctypename {
|
|
|
|
|
%javamethodmodifiers java_init "protected";
|
|
|
|
|
int java_init(jobject jsess) {
|
|
|
|
|
implclass *session = (implclass *)$self;
|
|
|
|
|
JAVA_CALLBACK *jcb = (JAVA_CALLBACK *)session->lang_private;
|
|
|
|
|
jcb->jobj = JCALL1(NewGlobalRef, jcb->jnienv, jsess);
|
|
|
|
|
JCALL1(DeleteLocalRef, jcb->jnienv, jsess);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
%enddef
|
|
|
|
|
|
|
|
|
|
TRACKED_CLASS(Session, __wt_session, wiredtigerJNI.Session_java_init, WT_SESSION_IMPL)
|
|
|
|
|
TRACKED_CLASS(Connection, __wt_connection, wiredtigerJNI.Connection_java_init, WT_CONNECTION_IMPL)
|
|
|
|
|
/* Note: Cursor incorporates the elements of TRACKED_CLASS into its
|
|
|
|
|
* custom constructor and %extend clause.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-07-07 01:27:47 +10:00
|
|
|
%include "wiredtiger.h"
|
|
|
|
|
|
|
|
|
|
/* Return new connections, sessions and cursors. */
|
|
|
|
|
%inline {
|
|
|
|
|
WT_CONNECTION *wiredtiger_open_wrap(JNIEnv *jenv, const char *home, const char *config) {
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
extern WT_EVENT_HANDLER javaApiEventHandler;
|
2012-07-09 16:19:51 +10:00
|
|
|
WT_CONNECTION *conn = NULL;
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
WT_CONNECTION_IMPL *connimpl;
|
|
|
|
|
JAVA_CALLBACK *jcb;
|
2012-07-09 16:19:51 +10:00
|
|
|
int ret;
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
if ((ret = wiredtiger_open(home, &javaApiEventHandler, config, &conn)) != 0)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
connimpl = (WT_CONNECTION_IMPL *)conn;
|
|
|
|
|
if ((ret = __wt_calloc_def(connimpl->default_session, 1, &jcb)) != 0)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
jcb->jnienv = jenv;
|
|
|
|
|
connimpl->lang_private = jcb;
|
|
|
|
|
|
|
|
|
|
err: if (ret != 0)
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror(ret));
|
2012-07-09 16:19:51 +10:00
|
|
|
return conn;
|
2012-07-07 01:27:47 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%extend __wt_connection {
|
2012-07-09 16:19:51 +10:00
|
|
|
WT_SESSION *open_session_wrap(JNIEnv *jenv, const char *config) {
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
extern WT_EVENT_HANDLER javaApiEventHandler;
|
2012-07-09 16:19:51 +10:00
|
|
|
WT_SESSION *session = NULL;
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
WT_SESSION_IMPL *sessionimpl;
|
|
|
|
|
JAVA_CALLBACK *jcb;
|
2012-07-09 16:19:51 +10:00
|
|
|
int ret;
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
|
|
|
|
|
if ((ret = $self->open_session($self, &javaApiEventHandler, config, &session)) != 0)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
sessionimpl = (WT_SESSION_IMPL *)session;
|
|
|
|
|
if ((ret = __wt_calloc_def(sessionimpl, 1, &jcb)) != 0)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
jcb->jnienv = jenv;
|
|
|
|
|
sessionimpl->lang_private = jcb;
|
|
|
|
|
|
|
|
|
|
err: if (ret != 0)
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror(ret));
|
2012-07-09 16:19:51 +10:00
|
|
|
return session;
|
|
|
|
|
}
|
2012-07-07 01:27:47 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%extend __wt_session {
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
WT_CURSOR *open_cursor_wrap(JNIEnv *jenv, const char *uri, WT_CURSOR_NULLABLE *to_dup, const char *config) {
|
2012-07-09 16:19:51 +10:00
|
|
|
WT_CURSOR *cursor = NULL;
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
JAVA_CALLBACK *jcb;
|
2012-07-09 16:19:51 +10:00
|
|
|
int ret;
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
|
2012-07-09 16:19:51 +10:00
|
|
|
if ((ret = $self->open_cursor($self, uri, to_dup, config, &cursor)) != 0)
|
Null out closed handles in Java, and detect nulled handles on use. refs #485.
As reported in #485, when a conn/session is closed, any subordinate
open cursors and sessions have dangling handles that refer to freed
memory. But also, if a conn/session/cursor handle is closed, that
handle may still be referenced in Java though it references freed
memory.
This commit uses the event handler for close calls to capture the first
case, and makes explicit calls at the close site for the second case.
For each case, a close will set the Java side 'swigCPtr' for each associated
object being closed to 0.
For detection, typemaps effectively check an arg's swigCPtr to see
if the object has been previously closed. Special cases, like when
a NULL handle is permitted in the API, are accounted for.
Some details:
- WT_HANDLE_NULLABLE() and WT_HANDLE_CLOSED() mark points in the API
(wiredtiger.in) where handles may be used as null and where
handles are closed. This are not exposed to doxygen.
- lang_private fields have been added to WT_CONNECTION_IMPL,
WT_SESSION_IMPL and WT_CURSOR to keep a handle to the
associated java object, needed at the time of the close().
2013-11-18 13:29:15 -05:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
cursor->flags |= WT_CURSTD_RAW;
|
|
|
|
|
|
|
|
|
|
if ((ret = __wt_calloc_def((WT_SESSION_IMPL *)cursor->session,
|
|
|
|
|
1, &jcb)) != 0)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
jcb->jnienv = jenv;
|
|
|
|
|
cursor->lang_private = jcb;
|
|
|
|
|
|
|
|
|
|
err: if (ret != 0)
|
2013-02-13 19:14:40 +11:00
|
|
|
throwWiredTigerException(jenv, wiredtiger_strerror(ret));
|
2012-07-09 16:19:51 +10:00
|
|
|
return cursor;
|
|
|
|
|
}
|
2012-07-07 01:27:47 +10:00
|
|
|
}
|