java_DbTxn.c 1.75 KB
Newer Older
unknown's avatar
unknown committed
1 2 3
/*-
 * See the file LICENSE for redistribution information.
 *
unknown's avatar
unknown committed
4
 * Copyright (c) 1997-2002
unknown's avatar
unknown committed
5 6 7 8 9
 *	Sleepycat Software.  All rights reserved.
 */
#include "db_config.h"

#ifndef lint
unknown's avatar
unknown committed
10
static const char revid[] = "$Id: java_DbTxn.c,v 11.16 2002/08/06 05:19:05 bostic Exp $";
unknown's avatar
unknown committed
11 12 13 14 15 16 17
#endif /* not lint */

#include <jni.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

unknown's avatar
unknown committed
18
#include "db_int.h"
unknown's avatar
unknown committed
19 20 21
#include "java_util.h"
#include "com_sleepycat_db_DbTxn.h"

unknown's avatar
unknown committed
22 23 24 25 26 27
JAVADB_METHOD(DbTxn_abort, (JAVADB_ARGS), DB_TXN,
    abort, (c_this))
JAVADB_METHOD(DbTxn_commit, (JAVADB_ARGS, jint flags), DB_TXN,
    commit, (c_this, flags))
JAVADB_METHOD(DbTxn_discard, (JAVADB_ARGS, jint flags), DB_TXN,
    discard, (c_this, flags))
unknown's avatar
unknown committed
28 29 30 31 32 33 34 35 36

JNIEXPORT jint JNICALL Java_com_sleepycat_db_DbTxn_id
  (JNIEnv *jnienv, jobject jthis)
{
	int retval = 0;
	DB_TXN *dbtxn = get_DB_TXN(jnienv, jthis);
	if (!verify_non_null(jnienv, dbtxn))
		return (-1);

unknown's avatar
unknown committed
37 38
	/* No error to check for from DB_TXN->id */
	retval = dbtxn->id(dbtxn);
unknown's avatar
unknown committed
39 40 41 42
	return (retval);
}

JNIEXPORT void JNICALL Java_com_sleepycat_db_DbTxn_prepare
unknown's avatar
unknown committed
43
  (JNIEnv *jnienv, jobject jthis, jbyteArray gid)
unknown's avatar
unknown committed
44 45
{
	int err;
unknown's avatar
unknown committed
46 47 48 49
	DB_TXN *dbtxn;
	jbyte *c_array;

	dbtxn = get_DB_TXN(jnienv, jthis);
unknown's avatar
unknown committed
50 51 52
	if (!verify_non_null(jnienv, dbtxn))
		return;

unknown's avatar
unknown committed
53 54 55 56 57 58 59 60 61
	if (gid == NULL ||
	    (*jnienv)->GetArrayLength(jnienv, gid) < DB_XIDDATASIZE) {
		report_exception(jnienv, "DbTxn.prepare gid array "
				 "must be >= 128 bytes", EINVAL, 0);
		return;
	}
	c_array = (*jnienv)->GetByteArrayElements(jnienv, gid, NULL);
	err = dbtxn->prepare(dbtxn, (u_int8_t *)c_array);
	(*jnienv)->ReleaseByteArrayElements(jnienv, gid, c_array, 0);
unknown's avatar
unknown committed
62 63 64
	verify_return(jnienv, err, 0);
}

unknown's avatar
unknown committed
65 66 67
JAVADB_METHOD(DbTxn_set_1timeout,
    (JAVADB_ARGS, jlong timeout, jint flags), DB_TXN,
    set_timeout, (c_this, (u_int32_t)timeout, flags))