extern "C" int __db_close_int(long id, u_int32_t flags) { Db *dbp; int ret; ct_entry *ctp; ret = 0; ctp = get_tableent(id); if (ctp == NULL) return (DB_NOSERVER_ID); DB_ASSERT(ctp->ct_type == CT_DB); if (__dbsrv_verbose && ctp->ct_refcount != 1) printf("Deref'ing dbp id %ld, refcount %d\n", id, ctp->ct_refcount); if (--ctp->ct_refcount != 0) return (ret); dbp = ctp->ct_dbp; if (__dbsrv_verbose) printf("Closing dbp id %ld\n", id); ret = dbp->close(flags); __dbdel_ctp(ctp); return (ret); }
extern "C" int __dbenv_close_int(long id, u_int32_t flags, int force) { DbEnv *dbenv; int ret; ct_entry *ctp; ret = 0; ctp = get_tableent(id); if (ctp == NULL) return (DB_NOSERVER_ID); DB_ASSERT(ctp->ct_type == CT_ENV); if (__dbsrv_verbose && ctp->ct_refcount != 1) printf("Deref'ing env id %ld, refcount %d\n", id, ctp->ct_refcount); /* * If we are timing out, we need to force the close, no matter * what the refcount. */ if (--ctp->ct_refcount != 0 && !force) return (ret); dbenv = ctp->ct_envp; if (__dbsrv_verbose) printf("Closing env id %ld\n", id); ret = dbenv->close(flags); __dbdel_ctp(ctp); return (ret); }
int dbji_call_dup_compare(DB_JAVAINFO *dbji, DB *db, jobject jdb, const DBT *dbt1, const DBT *dbt2) { JNIEnv *jnienv; jobject jdbt1, jdbt2; DBT_JAVAINFO *dbtji1, *dbtji2; COMPQUIET(db, NULL); jnienv = dbji_get_jnienv(dbji); if (jnienv == NULL) { fprintf(stderr, "Cannot attach to current thread!\n"); return (0); } /* XXX * We should have a pool of Dbt objects used for this purpose * instead of creating new ones each time. Because of * multithreading, we may need an arbitrary number (more than two). * We might also have a byte arrays that grow as needed, * so we don't need to allocate those either. */ jdbt1 = create_default_object(jnienv, name_DBT); jdbt2 = create_default_object(jnienv, name_DBT); dbtji1 = get_DBT_JAVAINFO(jnienv, jdbt1); memcpy(&dbtji1->dbt, dbt1, sizeof(DBT)); dbtji1->create_array_ = 1; dbtji2 = get_DBT_JAVAINFO(jnienv, jdbt2); memcpy(&dbtji2->dbt, dbt2, sizeof(DBT)); dbtji2->create_array_ = 1; DB_ASSERT(dbji->dup_compare_method_id_ != NULL); return (*jnienv)->CallIntMethod(jnienv, dbji->dup_compare_, dbji->dup_compare_method_id_, jdb, jdbt1, jdbt2); }
static void DbEnv_feedback_callback(DB_ENV *dbenv, int opcode, int percent) { DB_ENV_JAVAINFO *dbinfo; DB_ASSERT(dbenv != NULL); dbinfo = (DB_ENV_JAVAINFO *)dbenv->cj_internal; dbjie_call_feedback(dbinfo, dbenv, dbinfo->jenvref_, opcode, percent); }
static void Db_feedback_callback(DB *db, int opcode, int percent) { DB_JAVAINFO *dbinfo; DB_ASSERT(db != NULL); dbinfo = (DB_JAVAINFO *)db->cj_internal; dbji_call_feedback(dbinfo, db, dbinfo->jdbref_, opcode, percent); }
static int DbEnv_tx_recover_callback(DB_ENV *dbenv, DBT *dbt, DB_LSN *lsn, db_recops recops) { DB_ENV_JAVAINFO *dbinfo; DB_ASSERT(dbenv != NULL); dbinfo = (DB_ENV_JAVAINFO *)dbenv->cj_internal; return dbjie_call_tx_recover(dbinfo, dbenv, dbinfo->jenvref_, dbt, lsn, recops); }
void dbji_call_feedback(DB_JAVAINFO *dbji, DB *db, jobject jdb, int opcode, int percent) { JNIEnv *jnienv; COMPQUIET(db, NULL); jnienv = dbji_get_jnienv(dbji); if (jnienv == NULL) { fprintf(stderr, "Cannot attach to current thread!\n"); return; } DB_ASSERT(dbji->feedback_method_id_ != NULL); (*jnienv)->CallVoidMethod(jnienv, dbji->feedback_, dbji->feedback_method_id_, jdb, (jint)opcode, (jint)percent); }
int dbji_call_h_hash(DB_JAVAINFO *dbji, DB *db, jobject jdb, const void *data, int len) { JNIEnv *jnienv; jbyteArray jarray; COMPQUIET(db, NULL); jnienv = dbji_get_jnienv(dbji); if (jnienv == NULL) { fprintf(stderr, "Cannot attach to current thread!\n"); return (0); } DB_ASSERT(dbji->h_hash_method_id_ != NULL); jarray = (*jnienv)->NewByteArray(jnienv, len); (*jnienv)->SetByteArrayRegion(jnienv, jarray, 0, len, (void *)data); return (*jnienv)->CallIntMethod(jnienv, dbji->h_hash_, dbji->h_hash_method_id_, jdb, jarray, len); }
extern int dbji_call_append_recno(DB_JAVAINFO *dbji, DB *db, jobject jdb, DBT *dbt, jint recno) { JNIEnv *jnienv; jobject jdbt; DBT_JAVAINFO *dbtji; jbyteArray arr; unsigned int arraylen; unsigned char *data; COMPQUIET(db, NULL); jnienv = dbji_get_jnienv(dbji); if (jnienv == NULL) { fprintf(stderr, "Cannot attach to current thread!\n"); return (0); } /* XXX * We should have a pool of Dbt objects used for this purpose * instead of creating new ones each time. Because of * multithreading, we may need an arbitrary number (more than two). * We might also have a byte arrays that grow as needed, * so we don't need to allocate those either. * * Note, we do not set the 'create_array_' flag as on other * callbacks as we are creating the array here. */ jdbt = create_default_object(jnienv, name_DBT); dbtji = get_DBT_JAVAINFO(jnienv, jdbt); memcpy(&dbtji->dbt, dbt, sizeof(DBT)); dbtji->dbt.data = NULL; arr = (*jnienv)->NewByteArray(jnienv, dbt->size); (*jnienv)->SetByteArrayRegion(jnienv, arr, 0, dbt->size, (jbyte *)dbt->data); dbtji->array_ = (jbyteArray)NEW_GLOBAL_REF(jnienv, arr); DB_ASSERT(dbji->append_recno_method_id_ != NULL); (*jnienv)->CallVoidMethod(jnienv, dbji->append_recno_, dbji->append_recno_method_id_, jdb, jdbt, recno); /* The underlying C API requires that an errno be returned * on error. Java users know nothing of errnos, so we * allow them to throw exceptions instead. We leave the * exception in place and return DB_JAVA_CALLBACK to the C API * that called us. Eventually the DB->get will fail and * when java prepares to throw an exception in * report_exception(), this will be spotted as a special case, * and the original exception will be preserved. * * Note: we have sometimes noticed strange behavior with * exceptions under Linux 1.1.7 JVM. (i.e. multiple calls * to ExceptionOccurred() may report different results). * Currently we don't know of any problems related to this * in our code, but if it pops up in the future, users are * encouranged to get a more recent JVM. */ if ((*jnienv)->ExceptionOccurred(jnienv) != NULL) return (DB_JAVA_CALLBACK); if (dbtji->array_ == NULL) { report_exception(jnienv, "Dbt.data is null", 0, 0); return (EFAULT); } arraylen = (*jnienv)->GetArrayLength(jnienv, dbtji->array_); if (dbtji->offset_ < 0 ) { report_exception(jnienv, "Dbt.offset illegal", 0, 0); return (EFAULT); } if (dbt->ulen + dbtji->offset_ > arraylen) { report_exception(jnienv, "Dbt.ulen + Dbt.offset greater than array length", 0, 0); return (EFAULT); } data = (*jnienv)->GetByteArrayElements(jnienv, dbtji->array_, (jboolean *)0); dbt->data = data + dbtji->offset_; return (0); }