1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997, 1998
* Sleepycat Software. All rights reserved.
*/
#include "config.h"
#ifndef lint
static const char sccsid[] = "@(#)java_Dbt.cpp 10.5 (Sleepycat) 9/10/98";
#endif /* not lint */
#include <jni.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "db.h"
#include "java_util.h"
#include "com_sleepycat_db_Dbt.h"
JAVADB_RW_ACCESS(Dbt, jint, size, DBT, size)
JAVADB_RW_ACCESS(Dbt, jint, ulen, DBT, ulen)
JAVADB_RW_ACCESS(Dbt, jint, dlen, DBT, dlen)
JAVADB_RW_ACCESS(Dbt, jint, doff, DBT, doff)
JAVADB_RW_ACCESS(Dbt, jint, flags, DBT, flags)
JNIEXPORT void JNICALL Java_com_sleepycat_db_Dbt_init
(JNIEnv *jnienv, jobject jthis)
{
DBT_info *dbt = NEW(DBT_info);
set_private_info(jnienv, name_DBT, jthis, dbt);
}
JNIEXPORT void JNICALL Java_com_sleepycat_db_Dbt_internal_1set_1data
(JNIEnv *jnienv, jobject jthis, jbyteArray array)
{
DBT_info *db_this = get_DBT(jnienv, jthis);
if (verify_non_null(jnienv, db_this)) {
// If we previously allocated an array for java,
// must release reference.
db_this->release(jnienv);
// Make the array a global ref, it won't be GC'd till we release it.
if (array)
array = (jbyteArray)jnienv->NewGlobalRef(array);
db_this->array_ = array;
}
}
JNIEXPORT jbyteArray JNICALL Java_com_sleepycat_db_Dbt_get_1data
(JNIEnv *jnienv, jobject jthis)
{
DBT_info *db_this = get_DBT(jnienv, jthis);
if (verify_non_null(jnienv, db_this)) {
return db_this->array_;
}
return 0;
}
JNIEXPORT void JNICALL Java_com_sleepycat_db_Dbt_set_1offset
(JNIEnv *jnienv, jobject jthis, jint offset)
{
DBT_info *db_this = get_DBT(jnienv, jthis);
if (verify_non_null(jnienv, db_this)) {
db_this->offset_ = offset;
}
}
JNIEXPORT jint JNICALL Java_com_sleepycat_db_Dbt_get_1offset
(JNIEnv *jnienv, jobject jthis)
{
DBT_info *db_this = get_DBT(jnienv, jthis);
if (verify_non_null(jnienv, db_this)) {
return db_this->offset_;
}
return 0;
}
JNIEXPORT void JNICALL Java_com_sleepycat_db_Dbt_set_1recno_1key_1data(JNIEnv *jnienv, jobject jthis, jint value)
{
LockedDBT dbt_this(jnienv, jthis, inOp);
if (dbt_this.has_error())
return;
if (!dbt_this.dbt->data ||
dbt_this.java_array_len_ < sizeof(db_recno_t)) {
char buf[200];
sprintf(buf, "set_recno_key_data error: %p %p %d %d",
dbt_this.dbt, dbt_this.dbt->data,
dbt_this.dbt->ulen, sizeof(db_recno_t));
report_exception(jnienv, buf, 0);
}
else {
*(db_recno_t*)(dbt_this.dbt->data) = value;
}
}
JNIEXPORT jint JNICALL Java_com_sleepycat_db_Dbt_get_1recno_1key_1data(JNIEnv *jnienv, jobject jthis)
{
// Although this is kind of like "retrieve", we don't support
// DB_DBT_MALLOC for this operation, so we tell LockedDBT constructor
// that is not a retrieve.
//
LockedDBT dbt_this(jnienv, jthis, inOp);
if (dbt_this.has_error())
return 0;
if (!dbt_this.dbt->data ||
dbt_this.java_array_len_ < sizeof(db_recno_t)) {
char buf[200];
sprintf(buf, "get_recno_key_data error: %p %p %d %d",
dbt_this.dbt, dbt_this.dbt->data,
dbt_this.dbt->ulen, sizeof(db_recno_t));
report_exception(jnienv, buf, 0);
return 0;
}
else {
return *(db_recno_t*)(dbt_this.dbt->data);
}
}
JNIEXPORT void JNICALL Java_com_sleepycat_db_Dbt_finalize
(JNIEnv *jnienv, jobject jthis)
{
DBT_info *dbt = get_DBT(jnienv, jthis);
if (dbt) {
// Free any data related to DBT here
dbt->release(jnienv);
DELETE(dbt);
}
}
|