Example #1
0
/* putcat */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_putcat
(JNIEnv *env, jobject self, jbyteArray key, jbyteArray val){
  if(!key || !val){
    throwillarg(env);
    return false;
  }
  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 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 = tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz);
  if(icv) (*env)->ReleaseByteArrayElements(env, val, vbuf, JNI_ABORT);
  if(ick) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}
Example #2
0
 bool add(
    void const * pkey, size_t const ksize,
    void const * pval, size_t const vsize
    )
 {
    assert_data_store_open();
    return tchdbputcat(pdb_, pkey, ksize, pval, vsize);
 }
Example #3
0
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
        int omode, int dmode) {
    TCHDB *hdb = tchdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
    if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
    if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    bool err = false;
    int inum;
    double dnum;
    switch (dmode) {
        case -1:
            if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
        case 1:
            if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
        case 10:
            inum = tchdbaddint(hdb, kbuf, ksiz, tcatoi(vbuf));
            if (inum == INT_MIN) {
                printerr(hdb);
                err = true;
            } else {
                printf("%d\n", inum);
            }
            break;
        case 11:
            dnum = tchdbadddouble(hdb, kbuf, ksiz, tcatof(vbuf));
            if (isnan(dnum)) {
                printerr(hdb);
                err = true;
            } else {
                printf("%.6f\n", dnum);
            }
            break;
        default:
            if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
    }
    if (!tchdbclose(hdb)) {
        if (!err) printerr(hdb);
        err = true;
    }
    tchdbdel(hdb);
    return err ? 1 : 0;
}
Example #4
0
File: tchmgr.c Project: kadoma/fms
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
                   int omode, int dmode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  switch(dmode){
  case -1:
    if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  case 1:
    if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  default:
    if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}