Example #1
0
/* putkeep */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_putkeep
(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 = tchdbputkeep(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
/* 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 #3
0
static int
_tc_store (mu_dbm_file_t db,
	   struct mu_dbm_datum const *key,
	   struct mu_dbm_datum const *contents,
	   int replace)
{
  TCHDB *hdb = db->db_descr;
  bool result;

  if (replace)
    result = tchdbput (hdb, key->mu_dptr, key->mu_dsize,
		       contents->mu_dptr, contents->mu_dsize);
  else
    result = tchdbputkeep (hdb, key->mu_dptr, key->mu_dsize,
			   contents->mu_dptr, contents->mu_dsize);
  if (result)
    return 0;
  db->db_errno.n = tchdbecode (hdb);
  if (db->db_errno.n == TCEKEEP)
    return MU_ERR_EXISTS;
  return MU_ERR_FAILURE;
}
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;
}