Exemple #1
0
/* merge */
JNIEXPORT jboolean JNICALL
Java_estraier_Database_merge(JNIEnv *env, jobject obj, jstring name, jint options){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jboolean icname;
  const char *tname;
  int err;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0){
    throwillarg(env);
    return FALSE;
  }
  if(!name || !isinstanceof(env, name, CLSSTRING)){
    throwillarg(env);
    return FALSE;
  }
  if(!(tname = (*env)->GetStringUTFChars(env, name, &icname))){
    throwoutmem(env);
    return FALSE;
  }
  err = FALSE;
  if(!est_mtdb_merge((ESTMTDB *)(PTRNUM)coreptr, tname, options)){
    setecode(env, obj, est_mtdb_error((ESTMTDB *)(PTRNUM)coreptr));
    err = TRUE;
  }
  if(icname == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, name, tname);
  return err ? FALSE : TRUE;
}
Exemple #2
0
/* add_pseudo_index */
JNIEXPORT jboolean JNICALL
Java_estraier_Database_add_1pseudo_1index(JNIEnv *env, jobject obj, jstring path){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jboolean icpath;
  const char *tpath;
  int err;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0){
    throwillarg(env);
    return FALSE;
  }
  if(!path || !isinstanceof(env, path, CLSSTRING)){
    throwillarg(env);
    return FALSE;
  }
  if(!(tpath = (*env)->GetStringUTFChars(env, path, &icpath))){
    throwoutmem(env);
    return FALSE;
  }
  err = FALSE;
  if(!est_mtdb_add_pseudo_index((ESTMTDB *)(PTRNUM)coreptr, tpath)){
    setecode(env, obj, est_mtdb_error((ESTMTDB *)(PTRNUM)coreptr));
    err = TRUE;
  }
  if(icpath == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, path, tpath);
  return err ? FALSE : TRUE;
}
Exemple #3
0
/* get_doc */
JNIEXPORT jobject JNICALL
Java_estraier_Database_get_1doc(JNIEnv *env, jobject obj, jint id, jint options){
  jclass cls;
  jfieldID fid;
  jmethodID mid;
  jlong coreptr;
  ESTDOC *doc;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0 || id < 1){
    throwillarg(env);
    return NULL;
  }
  if(!(doc = est_mtdb_get_doc((ESTMTDB *)(PTRNUM)coreptr, id, options))){
    setecode(env, obj, est_mtdb_error((ESTMTDB *)(PTRNUM)coreptr));
    return NULL;
  }
  cls = (*env)->FindClass(env, CLSDOC);
  mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
  if(!(obj = (*env)->NewObject(env, cls, mid))){
    throwoutmem(env);
    return NULL;
  }
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  (*env)->SetLongField(env, obj, fid, (PTRNUM)doc);
  return obj;
}
Exemple #4
0
/* get_doc_attr */
JNIEXPORT jstring JNICALL
Java_estraier_Database_get_1doc_1attr(JNIEnv *env, jobject obj, jint id, jstring name){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jstring value;
  jboolean icname;
  const char *tname;
  char *tvalue;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0 || id < 1 || !name || !isinstanceof(env, name, CLSSTRING)){
    throwillarg(env);
    return NULL;
  }
  if(!(tname = (*env)->GetStringUTFChars(env, name, &icname))){
    throwoutmem(env);
    return NULL;
  }
  if(!(tvalue = est_mtdb_get_doc_attr((ESTMTDB *)(PTRNUM)coreptr, id, tname))){
    setecode(env, obj, est_mtdb_error((ESTMTDB *)(PTRNUM)coreptr));
    if(icname == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, name, tname);
    return NULL;
  }
  if(icname == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, name, tname);
  if(!(value = (*env)->NewStringUTF(env, tvalue))){
    throwoutmem(env);
    return NULL;
  }
  free(tvalue);
  return value;
}
/* fwmkeys */
JNIEXPORT jobject JNICALL Java_tokyocabinet_BDB_fwmkeys
(JNIEnv *env, jobject self, jbyteArray prefix, jint max){
  if(!prefix){
    throwillarg(env);
    return NULL;
  }
  TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr);
  jboolean icp;
  jbyte *pbuf = (*env)->GetByteArrayElements(env, prefix, &icp);
  if(!pbuf){
    throwoutmem(env);
    return NULL;
  }
  int psiz = (*env)->GetArrayLength(env, prefix);
  TCLIST *tkeys = tcbdbfwmkeys(bdb, pbuf, psiz, max);
  jclass clslist = (*env)->FindClass(env, CLSARRAYLIST);
  jmethodID midinit = (*env)->GetMethodID(env, clslist, "<init>", "()V");
  jobject keys = (*env)->NewObject(env, clslist, midinit);
  jmethodID midadd = (*env)->GetMethodID(env, clslist, "add", "(L" CLSOBJECT ";)Z");
  for(int i = 0; i < tclistnum(tkeys); i++){
    int ksiz;
    const char *kbuf = tclistval(tkeys, i, &ksiz);
    jbyteArray key = (*env)->NewByteArray(env, ksiz);
    (*env)->SetByteArrayRegion(env, key, 0, ksiz, (jbyte *)kbuf);
    (*env)->CallVoidMethod(env, keys, midadd, key);
    (*env)->DeleteLocalRef(env, key);
  }
  tclistdel(tkeys);
  (*env)->ReleaseByteArrayElements(env, prefix, pbuf, JNI_ABORT);
  return keys;
}
/* get */
JNIEXPORT jbyteArray JNICALL Java_tokyocabinet_BDB_get
(JNIEnv *env, jobject self, jbyteArray key){
  if(!key){
    throwillarg(env);
    return NULL;
  }
  TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return NULL;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  int vsiz;
  char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
  jbyteArray val;
  if(vbuf){
    val = (*env)->NewByteArray(env, vsiz);
    if(!val){
      throwoutmem(env);
      return NULL;
    }
    (*env)->SetByteArrayRegion(env, val, 0, vsiz, (jbyte *)vbuf);
    tcfree(vbuf);
  } else {
    val = NULL;
  }
  (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return val;
}
/* putdup */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_BDB_putdup
(JNIEnv *env, jobject self, jbyteArray key, jbyteArray val){
  if(!key || !val){
    throwillarg(env);
    return false;
  }
  TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return false;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  jboolean icv;
  jbyte *vbuf = (*env)->GetByteArrayElements(env, val, &icv);
  if(!vbuf){
    throwoutmem(env);
    return false;
  }
  int vsiz = (*env)->GetArrayLength(env, val);
  bool rv = tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz);
  (*env)->ReleaseByteArrayElements(env, val, vbuf, JNI_ABORT);
  (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}
Exemple #8
0
/* uri_to_id */
JNIEXPORT jint JNICALL
Java_estraier_Database_uri_1to_1id(JNIEnv *env, jobject obj, jstring uri){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jboolean icuri;
  const char *turi;
  int id;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0 || !uri || !isinstanceof(env, uri, CLSSTRING)){
    throwillarg(env);
    return -1;
  }
  if(!(turi = (*env)->GetStringUTFChars(env, uri, &icuri))){
    throwoutmem(env);
    return -1;
  }
  if((id = est_mtdb_uri_to_id((ESTMTDB *)(PTRNUM)coreptr, turi)) == -1){
    setecode(env, obj, est_mtdb_error((ESTMTDB *)(PTRNUM)coreptr));
    if(icuri == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, uri, turi);
    return -1;
  }
  if(icuri == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, uri, turi);
  return id;
}
Exemple #9
0
/* set_informer */
JNIEXPORT void JNICALL
Java_estraier_Database_set_1informer(JNIEnv *env, jobject obj, jobject informer){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jobject oldobj;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0){
    throwillarg(env);
    return;
  }
  fid = (*env)->GetFieldID(env, cls, "informer", "L" CLSDBINFO ";");
  if((oldobj = (*env)->GetObjectField(env, obj, fid)) != NULL)
    (*env)->DeleteGlobalRef(env, oldobj);
  (*env)->SetObjectField(env, obj, fid, NULL);
  if(!(informer = (*env)->NewGlobalRef(env, informer))){
    throwoutmem(env);
    return;
  }
  (*env)->SetObjectField(env, obj, fid, informer);
  infoenv = env;
  est_mtdb_set_informer((ESTMTDB *)(PTRNUM)coreptr, dbinform, informer);
}
Exemple #10
0
/* proc */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_TDBQRY_proc
(JNIEnv *env, jobject self, jobject qp){
  if(!qp){
    throwillarg(env);
    return false;
  }
  TDBQRY *qry = (TDBQRY *)(intptr_t)(*env)->GetLongField(env, self, tdbqry_fid_ptr);
  jclass clsqp = (*env)->GetObjectClass(env, qp);
  jclass clsmap = (*env)->FindClass(env, CLSHASHMAP);
  jclass clsset = (*env)->FindClass(env, CLSSET);
  jclass clsiter = (*env)->FindClass(env, CLSITERATOR);
  jclass clsentry = (*env)->FindClass(env, CLSMAPENTRY);
  jclass clsbyteary = (*env)->FindClass(env, "[B");
  jclass clsstring = (*env)->FindClass(env, "L" CLSSTRING ";");
  jmethodID midmapinit = (*env)->GetMethodID(env, clsmap, "<init>", "()V");
  jobject map = (*env)->NewObject(env, clsmap, midmapinit);
  TCPROCOP procop;
  procop.env = env;
  procop.obj = qp;
  procop.mid = (*env)->GetMethodID(env, clsqp, "proc", "([BL" CLSMAP ";)I");
  procop.map = map;
  procop.midmapclear = (*env)->GetMethodID(env, clsmap, "clear", "()V");
  procop.midmapput = (*env)->GetMethodID(env, clsmap, "put",
                                         "(L" CLSOBJECT ";L" CLSOBJECT ";)L" CLSOBJECT ";");
  procop.midmapentryset = (*env)->GetMethodID(env, clsmap, "entrySet", "()L" CLSSET ";");
  procop.midsetiterator = (*env)->GetMethodID(env, clsset, "iterator", "()L" CLSITERATOR ";");
  procop.miditerhasnext = (*env)->GetMethodID(env, clsiter, "hasNext", "()Z");
  procop.miditernext = (*env)->GetMethodID(env, clsiter, "next", "()L" CLSOBJECT ";");
  procop.midentrygk = (*env)->GetMethodID(env, clsentry, "getKey", "()L" CLSOBJECT ";");
  procop.midentrygv = (*env)->GetMethodID(env, clsentry, "getValue", "()L" CLSOBJECT ";");
  procop.midstringgb = (*env)->GetMethodID(env, clsstring, "getBytes", "()[B");
  procop.clsbyteary = clsbyteary;
  procop.clsstring = clsstring;
  return tctdbqryproc(qry, (TDBQRYPROC)tcprocrec, &procop);
}
Exemple #11
0
/* open */
JNIEXPORT jboolean JNICALL
Java_estraier_Database_open(JNIEnv *env, jobject obj, jstring name, jint omode){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jboolean icname;
  ESTMTDB *db;
  const char *tname;
  int err, ecode;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr != 0 || !name || !isinstanceof(env, name, CLSSTRING)){
    throwillarg(env);
    return FALSE;
  }
  if(!(tname = (*env)->GetStringUTFChars(env, name, &icname))){
    throwoutmem(env);
    return FALSE;
  }
  err = FALSE;
  if((db = est_mtdb_open(tname, omode, &ecode)) != NULL){
    (*env)->SetLongField(env, obj, fid, (PTRNUM)db);
  } else {
    setecode(env, obj, ecode);
    err = TRUE;
  }
  if(icname == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, name, tname);
  return err ? FALSE : TRUE;
}
Exemple #12
0
/* close */
JNIEXPORT jboolean JNICALL
Java_estraier_Database_close(JNIEnv *env, jobject obj){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  jobject infoobj;
  int err, ecode;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0){
    throwillarg(env);
    return FALSE;
  }
  err = FALSE;
  if(!est_mtdb_close((ESTMTDB *)(PTRNUM)coreptr, &ecode)){
    setecode(env, obj, ecode);
    err = TRUE;
  }
  (*env)->SetLongField(env, obj, fid, 0);
  fid = (*env)->GetFieldID(env, cls, "informer", "L" CLSDBINFO ";");
  if((infoobj = (*env)->GetObjectField(env, obj, fid)) != NULL)
    (*env)->DeleteGlobalRef(env, infoobj);
  (*env)->SetObjectField(env, obj, fid, NULL);
  return err ? FALSE : TRUE;
}
Exemple #13
0
/* putimpl */
JNIEXPORT jboolean JNICALL Java_tokyotyrant_TCRDB_putimpl
(JNIEnv *env, jobject self, jbyteArray pkey, jobjectArray cols, jint dmode){
  if(!pkey || !cols){
    throwillarg(env);
    return false;
  }
  TCRDB *tcrdb = (TCRDB *)(intptr_t)(*env)->GetLongField(env, self, tcrdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, pkey, &ick);
  if(!kbuf){
    throwoutmem(env);
    return false;
  }
  int ksiz = (*env)->GetArrayLength(env, pkey);
  jsize cnum = (*env)->GetArrayLength(env, cols);
  TCMAP *tcols = tcmapnew2(cnum + 1);
  cnum--;
  for(int i = 0; i < cnum; i += 2){
    jobject name = (*env)->GetObjectArrayElement(env, cols, i);
    jboolean icn;
    jbyte *nbuf = (*env)->GetByteArrayElements(env, name, &icn);
    if(!nbuf){
      throwoutmem(env);
      return false;
    }
    int nsiz = (*env)->GetArrayLength(env, name);
    jobject val = (*env)->GetObjectArrayElement(env, cols, i + 1);
    jboolean icv;
    jbyte *vbuf = (*env)->GetByteArrayElements(env, val, &icv);
    if(!vbuf){
      throwoutmem(env);
      return false;
    }
    int vsiz = (*env)->GetArrayLength(env, val);
    tcmapputkeep(tcols, nbuf, nsiz, vbuf, vsiz);
    if(icv) (*env)->ReleaseByteArrayElements(env, val, vbuf, JNI_ABORT);
    if(icn) (*env)->ReleaseByteArrayElements(env, name, nbuf, JNI_ABORT);
  }
  bool rv;
  switch(dmode){
  case 0:
    rv = tcrdbtblput(tcrdb, kbuf, ksiz, tcols);
    break;
  case 1:
    rv = tcrdbtblputkeep(tcrdb, kbuf, ksiz, tcols);
    break;
  case 2:
    rv = tcrdbtblputcat(tcrdb, kbuf, ksiz, tcols);
    break;
  default:
    rv = false;
    break;
  }
  tcmapdel(tcols);
  if(ick) (*env)->ReleaseByteArrayElements(env, pkey, kbuf, JNI_ABORT);
  return rv;
}
Exemple #14
0
/* setorder */
JNIEXPORT void JNICALL Java_tokyocabinet_TDBQRY_setorder
(JNIEnv *env, jobject self, jstring name, jint type){
  if(!name){
    throwillarg(env);
    return;
  }
  TDBQRY *qry = (TDBQRY *)(intptr_t)(*env)->GetLongField(env, self, tdbqry_fid_ptr);
  jboolean icn;
  const char *tname = (*env)->GetStringUTFChars(env, name, &icn);
  tctdbqrysetorder(qry, tname, type);
  if(icn) (*env)->ReleaseStringUTFChars(env, name, tname);
}
Exemple #15
0
/* set_wildmax */
JNIEXPORT void JNICALL
Java_estraier_Database_set_1wildmax(JNIEnv *env, jobject obj, jint num){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0){
    throwillarg(env);
    return;
  }
  est_mtdb_set_wildmax((ESTMTDB *)(PTRNUM)coreptr, num);
}
Exemple #16
0
/* size */
JNIEXPORT jdouble JNICALL
Java_estraier_Database_size(JNIEnv *env, jobject obj){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0){
    throwillarg(env);
    return -1;
  }
  return est_mtdb_size((ESTMTDB *)(PTRNUM)coreptr);
}
Exemple #17
0
/* set_max */
JNIEXPORT void JNICALL
Java_estraier_Condition_set_1max(JNIEnv *env, jobject obj, jint max){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(max < 0){
    throwillarg(env);
    return;
  }
  est_cond_set_max((ESTCOND *)(PTRNUM)coreptr, max);
}
Exemple #18
0
/* addcond */
JNIEXPORT void JNICALL Java_tokyocabinet_TDBQRY_addcond
(JNIEnv *env, jobject self, jstring name, jint op, jstring expr){
  if(!name || !expr){
    throwillarg(env);
    return;
  }
  TDBQRY *qry = (TDBQRY *)(intptr_t)(*env)->GetLongField(env, self, tdbqry_fid_ptr);
  jboolean icn;
  const char *tname = (*env)->GetStringUTFChars(env, name, &icn);
  jboolean ice;
  const char *texpr = (*env)->GetStringUTFChars(env, expr, &ice);
  tctdbqryaddcond(qry, tname, op, texpr);
  if(ice) (*env)->ReleaseStringUTFChars(env, expr, texpr);
  if(icn) (*env)->ReleaseStringUTFChars(env, name, tname);
}
Exemple #19
0
/* set_cache_size */
JNIEXPORT void JNICALL
Java_estraier_Database_set_1cache_1size(JNIEnv *env, jobject obj,
                                        jdouble size, jint anum, jint tnum, jint rnum){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0){
    throwillarg(env);
    return;
  }
  est_mtdb_set_cache_size((ESTMTDB *)(PTRNUM)coreptr, size, anum, tnum, rnum);
}
Exemple #20
0
/* getimpl */
JNIEXPORT jobjectArray JNICALL Java_tokyotyrant_TCRDB_getimpl
(JNIEnv *env, jobject self, jbyteArray pkey){
  if(!pkey){
    throwillarg(env);
    return 0;
  }
  TCRDB *tcrdb = (TCRDB *)(intptr_t)(*env)->GetLongField(env, self, tcrdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, pkey, &ick);
  if(!kbuf){
    throwoutmem(env);
    return NULL;
  }
  int ksiz = (*env)->GetArrayLength(env, pkey);
  jobjectArray ary = NULL;
  TCMAP *tcols = tcrdbtblget(tcrdb, kbuf, ksiz);
  if(tcols){
    int anum = tcmaprnum(tcols) * 2;
    ary = (*env)->NewObjectArray(env, anum, (*env)->GetObjectClass(env, pkey), NULL);
    anum = 0;
    tcmapiterinit(tcols);
    const char *nbuf;
    int nsiz;
    while((nbuf = tcmapiternext(tcols, &nsiz)) != NULL){
      int vsiz;
      const char *vbuf = tcmapiterval(nbuf, &vsiz);
      jbyteArray nary = (*env)->NewByteArray(env, nsiz);
      if(!nary){
        throwoutmem(env);
        return NULL;
      }
      jbyteArray vary = (*env)->NewByteArray(env, vsiz);
      if(!vary){
        throwoutmem(env);
        return NULL;
      }
      (*env)->SetByteArrayRegion(env, nary, 0, nsiz, (jbyte *)nbuf);
      (*env)->SetByteArrayRegion(env, vary, 0, vsiz, (jbyte *)vbuf);
      (*env)->SetObjectArrayElement(env, ary, anum++, nary);
      (*env)->SetObjectArrayElement(env, ary, anum++, vary);
      (*env)->DeleteLocalRef(env, vary);
      (*env)->DeleteLocalRef(env, nary);
    }
    tcmapdel(tcols);
  }
  if(ick) (*env)->ReleaseByteArrayElements(env, pkey, kbuf, JNI_ABORT);
  return ary;
}
Exemple #21
0
/* setindex */
JNIEXPORT jboolean JNICALL Java_tokyotyrant_TCRDB_setindex
(JNIEnv *env, jobject self, jstring name, jint type){
  if(!name){
    throwillarg(env);
    return false;
  }
  TCRDB *tcrdb = (TCRDB *)(intptr_t)(*env)->GetLongField(env, self, tcrdb_fid_ptr);
  jboolean icn;
  const char *tname = (*env)->GetStringUTFChars(env, name, &icn);
  if(!tname){
    throwoutmem(env);
    return false;
  }
  bool rv = tcrdbtblsetindex(tcrdb, tname, type);
  if(icn) (*env)->ReleaseStringUTFChars(env, name, tname);
  return rv;
}
Exemple #22
0
/* open */
JNIEXPORT jboolean JNICALL Java_tokyotyrant_TCRDB_open
(JNIEnv *env, jobject self, jstring host, jint port){
  if(!host){
    throwillarg(env);
    return false;
  }
  TCRDB *tcrdb = (TCRDB *)(intptr_t)(*env)->GetLongField(env, self, tcrdb_fid_ptr);
  jboolean icp;
  const char *thost = (*env)->GetStringUTFChars(env, host, &icp);
  if(!thost){
    throwoutmem(env);
    return false;
  }
  bool rv = tcrdbopen(tcrdb, thost, port);
  if(icp) (*env)->ReleaseStringUTFChars(env, host, thost);
  return rv;
}
Exemple #23
0
/* open */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_open
(JNIEnv *env, jobject self, jstring path, jint omode){
  if(!path){
    throwillarg(env);
    return false;
  }
  TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr);
  jboolean icp;
  const char *tpath = (*env)->GetStringUTFChars(env, path, &icp);
  if(!tpath){
    throwoutmem(env);
    return false;
  }
  bool rv = tchdbopen(hdb, tpath, omode);
  if(icp) (*env)->ReleaseStringUTFChars(env, path, tpath);
  return rv;
}
/* copy */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_BDB_copy
(JNIEnv *env, jobject self, jstring path){
  if(!path){
    throwillarg(env);
    return false;
  }
  TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr);
  jboolean icp;
  const char *tpath = (*env)->GetStringUTFChars(env, path, &icp);
  if(!tpath){
    throwoutmem(env);
    return false;
  }
  bool rv = tcbdbcopy(bdb, tpath);
  (*env)->ReleaseStringUTFChars(env, path, tpath);
  return rv;
}
Exemple #25
0
/* search */
JNIEXPORT jobject JNICALL
Java_estraier_Database_search(JNIEnv *env, jobject obj, jobject cond){
  jclass cls;
  jfieldID fid;
  jmethodID mid;
  jlong coreptr, condptr;
  jintArray resary;
  jint *resaryptr;
  jobject hintsobj, resobj;
  jboolean icresary;
  CBMAP *hints;
  int i, *res, rnum;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0 || !cond || !isinstanceof(env, cond, CLSCOND)){
    throwillarg(env);
    return NULL;
  }
  cls = (*env)->GetObjectClass(env, cond);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  condptr = (*env)->GetLongField(env, cond, fid);
  hints = cbmapopen();
  res = est_mtdb_search((ESTMTDB *)(PTRNUM)coreptr, (ESTCOND *)(PTRNUM)condptr, &rnum, hints);
  if(!(resary = (*env)->NewIntArray(env, rnum))){
    throwoutmem(env);
    return NULL;
  }
  resaryptr = (*env)->GetIntArrayElements(env, resary, &icresary);
  for(i = 0; i < rnum; i++){
    resaryptr[i] = res[i];
  }
  if(icresary == JNI_TRUE) (*env)->ReleaseIntArrayElements(env, resary, resaryptr, 0);
  cls = (*env)->FindClass(env, CLSRES);
  mid = (*env)->GetMethodID(env, cls, "<init>", "([IL" CLSMAP ";J)V");
  hintsobj = cbmaptoobj(env, hints);
  if(!(resobj = (*env)->NewObject(env, cls, mid, resary, hintsobj,
                                  (PTRNUM)est_cond_dup((ESTCOND *)(PTRNUM)condptr)))){
    throwoutmem(env);
    return NULL;
  }
  free(res);
  cbmapclose(hints);
  return resobj;
}
Exemple #26
0
/* vsiz */
JNIEXPORT jint JNICALL Java_tokyocabinet_HDB_vsiz
(JNIEnv *env, jobject self, jbyteArray key){
  if(!key){
    throwillarg(env);
    return 0;
  }
  TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return 0;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  int rv = tchdbvsiz(hdb, kbuf, ksiz);
  if(ick) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}
/* adddouble */
JNIEXPORT jdouble JNICALL Java_tokyocabinet_BDB_adddouble
(JNIEnv *env, jobject self, jbyteArray key, jdouble num){
  if(!key){
    throwillarg(env);
    return 0.0;
  }
  TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return 0.0;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  num = tcbdbadddouble(bdb, kbuf, ksiz, num);
  (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return num;
}
Exemple #28
0
/* out_doc */
JNIEXPORT jboolean JNICALL
Java_estraier_Database_out_1doc(JNIEnv *env, jobject obj, jint id, jint options){
  jclass cls;
  jfieldID fid;
  jlong coreptr;
  cls = (*env)->GetObjectClass(env, obj);
  fid = (*env)->GetFieldID(env, cls, "coreptr", "J");
  coreptr = (*env)->GetLongField(env, obj, fid);
  if(coreptr == 0 || id < 1){
    throwillarg(env);
    return FALSE;
  }
  if(!est_mtdb_out_doc((ESTMTDB *)(PTRNUM)coreptr, id, options)){
    setecode(env, obj, est_mtdb_error((ESTMTDB *)(PTRNUM)coreptr));
    return FALSE;
  }
  return TRUE;
}
/* jump */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_BDBCUR_jump
(JNIEnv *env, jobject self, jbyteArray key){
  if(!key){
    throwillarg(env);
    return false;
  }
  BDBCUR *cur = (BDBCUR *)(intptr_t)(*env)->GetLongField(env, self, bdbcur_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return false;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  bool rv = tcbdbcurjump(cur, kbuf, ksiz);
  (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}
/* put */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_BDBCUR_put
(JNIEnv *env, jobject self, jbyteArray val, jint cpmode){
  if(!val){
    throwillarg(env);
    return false;
  }
  BDBCUR *cur = (BDBCUR *)(intptr_t)(*env)->GetLongField(env, self, bdbcur_fid_ptr);
  jboolean icv;
  jbyte *vbuf = (*env)->GetByteArrayElements(env, val, &icv);
  if(!vbuf){
    throwoutmem(env);
    return false;
  }
  int vsiz = (*env)->GetArrayLength(env, val);
  bool rv = tcbdbcurput(cur, vbuf, vsiz, cpmode);
  (*env)->ReleaseByteArrayElements(env, val, vbuf, JNI_ABORT);
  return rv;
}