# class BDB::Txn

### Public Instance Methods

abort() click to toggle source

    static VALUE
    bdb_txn_abort(VALUE obj)
    {
        bdb_TXN *txnst;

        GetTxnDB(obj, txnst);
        bdb_txn_close_all(obj, Qfalse);
    #if HAVE_ST_DB_TXN_ABORT
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_abort)
            bdb_test_error(txnst->txn_cxx_abort(txnst->txn_cxx) );
        else
    #endif
            bdb_test_error(txnst->txnid->abort(txnst->txnid));
    #else
        bdb_test_error(txn_abort(txnst->txnid));
    #endif
        txnst->txnid = NULL;
        if (txnst->status == THROW) {
            txnst->status = ROLLBACK;
            rb_throw("__bdb__begin", Data_Wrap_Struct(bdb_cTxnCatch, 0, 0, txnst));
        }
        return Qtrue;
    }

assoc(*args) click to toggle source

    static VALUE
    bdb_txn_assoc(int argc, VALUE *argv, VALUE obj)
    {
        int i;
        VALUE ary, a;
        bdb_TXN *txnst;

        ary = rb_ary_new();
        GetTxnDB(obj, txnst);
        for (i = 0; i < argc; i++) {
            a = rb_funcall(argv[i], rb_intern("__txn_dup__"), 1, obj);
            bdb_ary_push(&txnst->db_assoc, a);
        bdb_ary_push(&txnst->db_assoc_objassoc_ary, (VALUE)create_assoc(a, txnst, BDB_OBJ_TX));
            rb_ary_push(ary, a);
        }
        switch (RARRAY_LEN(ary)) {
        case 0: return Qnil;
        case 1: return RARRAY_PTR(ary)[0];
        default: return ary;
        }
    }

associate(*args) click to toggle source

    static VALUE
    bdb_txn_assoc(int argc, VALUE *argv, VALUE obj)
    {
        int i;
        VALUE ary, a;
        bdb_TXN *txnst;

        ary = rb_ary_new();
        GetTxnDB(obj, txnst);
        for (i = 0; i < argc; i++) {
            a = rb_funcall(argv[i], rb_intern("__txn_dup__"), 1, obj);
            bdb_ary_push(&txnst->db_assoc, a);
        bdb_ary_push(&txnst->db_assoc_objassoc_ary, (VALUE)create_assoc(a, txnst, BDB_OBJ_TX));
            rb_ary_push(ary, a);
        }
        switch (RARRAY_LEN(ary)) {
        case 0: return Qnil;
        case 1: return RARRAY_PTR(ary)[0];
        default: return ary;
        }
    }

begin(*args) click to toggle source

    static VALUE
    bdb_env_begin(int argc, VALUE *argv, VALUE obj)
    {
        return bdb_env_rslbl_begin(Qfalse, argc, argv, obj);
    }

close(p1 = v1) click to toggle source

    static VALUE
    bdb_txn_commit(int argc, VALUE *argv, VALUE obj)
    {
        bdb_TXN *txnst;
        VALUE a;
        int flags;

        rb_secure(4);
        flags = 0;
        if (rb_scan_args(argc, argv, "01", &a) == 1) {
            flags = NUM2INT(a);
        }
        GetTxnDB(obj, txnst);
        bdb_txn_close_all(obj, Qtrue);
    #if HAVE_ST_DB_TXN_COMMIT
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_commit)
            bdb_test_error(txnst->txn_cxx_commit(txnst->txn_cxx, flags) );
        else
    #endif
            bdb_test_error(txnst->txnid->commit(txnst->txnid, flags));
    #else
    #if HAVE_TXN_COMMIT_2
        bdb_test_error(txn_commit(txnst->txnid, flags));
    #else
        bdb_test_error(txn_commit(txnst->txnid));
    #endif
    #endif
        txnst->txnid = NULL;
        if (txnst->status == THROW) {
            txnst->status = COMMIT;
            rb_throw("__bdb__begin", Data_Wrap_Struct(bdb_cTxnCatch, 0, 0, txnst));
        }
        return Qtrue;
    }

commit(p1 = v1) click to toggle source

    static VALUE
    bdb_txn_commit(int argc, VALUE *argv, VALUE obj)
    {
        bdb_TXN *txnst;
        VALUE a;
        int flags;

        rb_secure(4);
        flags = 0;
        if (rb_scan_args(argc, argv, "01", &a) == 1) {
            flags = NUM2INT(a);
        }
        GetTxnDB(obj, txnst);
        bdb_txn_close_all(obj, Qtrue);
    #if HAVE_ST_DB_TXN_COMMIT
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_commit)
            bdb_test_error(txnst->txn_cxx_commit(txnst->txn_cxx, flags) );
        else
    #endif
            bdb_test_error(txnst->txnid->commit(txnst->txnid, flags));
    #else
    #if HAVE_TXN_COMMIT_2
        bdb_test_error(txn_commit(txnst->txnid, flags));
    #else
        bdb_test_error(txn_commit(txnst->txnid));
    #endif
    #endif
        txnst->txnid = NULL;
        if (txnst->status == THROW) {
            txnst->status = COMMIT;
            rb_throw("__bdb__begin", Data_Wrap_Struct(bdb_cTxnCatch, 0, 0, txnst));
        }
        return Qtrue;
    }

dbremove(p1 = v1, p2 = v2, p3 = v3) click to toggle source

    static VALUE
    bdb_env_dbremove(int argc, VALUE *argv, VALUE obj)
    {
        VALUE a, b, c;
        char *file, *database;
        int flags;
        bdb_ENV *envst;
        bdb_TXN *txnst;
        DB_TXN *txnid;

        rb_secure(2);
        a = b = c = Qnil;
        file = database = NULL;
        flags = 0;
        rb_scan_args(argc, argv, "03", &a, &b, &c);
        if (!NIL_P(a)) {
            SafeStringValue(a);
            file = StringValuePtr(a);
        }
        if (!NIL_P(b)) {
            SafeStringValue(b);
            database = StringValuePtr(b);
        }
        if (!NIL_P(c)) {
            flags = NUM2INT(c);
        }
        txnid = NULL;
        if (rb_obj_is_kind_of(obj, bdb_cTxn)) {
            GetTxnDB(obj, txnst);
            txnid = txnst->txnid;
            GetEnvDB(txnst->env, envst);
        }
        else {
            GetEnvDB(obj, envst);
        }
    #if HAVE_CONST_DB_AUTO_COMMIT
        if (txnid == NULL && (envst->options & BDB_AUTO_COMMIT)) {
          flags |= DB_AUTO_COMMIT;
        }
    #endif
        bdb_test_error(envst->envp->dbremove(envst->envp, txnid,
                                             file, database, flags));
        return Qnil;
    }

dbrename(p1, p2, p3 = v3, p4 = v4) click to toggle source

    static VALUE
    bdb_env_dbrename(int argc, VALUE *argv, VALUE obj)
    {
        VALUE a, b, c, d;
        char *file, *database, *newname;
        int flags;
        bdb_ENV *envst;
        bdb_TXN *txnst;
        DB_TXN *txnid;

        rb_secure(2);
        a = b = c = Qnil;
        file = database = newname = NULL;
        flags = 0;
        if (rb_scan_args(argc, argv, "22", &a, &b, &c, &d) == 2) {
            c = b;
            b = d = Qnil;
        }
        if (!NIL_P(a)) {
            SafeStringValue(a);
            file = StringValuePtr(a);
        }
        if (!NIL_P(b)) {
            SafeStringValue(b);
            database = StringValuePtr(b);
        }
        if (!NIL_P(c)) {
            SafeStringValue(c);
            newname = StringValuePtr(c);
        }
        else {
            rb_raise(bdb_eFatal, "newname not specified");
        }
        if (!NIL_P(d)) {
            flags = NUM2INT(d);
        }
        txnid = NULL;
        if (rb_obj_is_kind_of(obj, bdb_cTxn)) {
            GetTxnDB(obj, txnst);
            txnid = txnst->txnid;
            GetEnvDB(txnst->env, envst);
        }
        else {
            GetEnvDB(obj, envst);
        }
    #if HAVE_CONST_DB_AUTO_COMMIT
        if (txnid == NULL && (envst->options & BDB_AUTO_COMMIT)) {
          flags |= DB_AUTO_COMMIT;
        }
    #endif
        bdb_test_error(envst->envp->dbrename(envst->envp, txnid,
                                             file, database, newname, flags));
        return Qnil;
    }

discard() click to toggle source

    static VALUE
    bdb_txn_discard(VALUE obj)
    {
        bdb_TXN *txnst;
        int flags;

        rb_secure(4);
        flags = 0;
        GetTxnDB(obj, txnst);
    #if HAVE_ST_DB_TXN_DISCARD
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_discard)
            bdb_test_error(txnst->txn_cxx_discard(txnst->txn_cxx, flags) );
        else
    #endif
            bdb_test_error(txnst->txnid->discard(txnst->txnid, flags));
    #else
        bdb_test_error(txn_discard(txnst->txnid, flags));
    #endif
        txnst->txnid = NULL;
        return Qtrue;
    }

id() click to toggle source

    static VALUE
    bdb_txn_id(VALUE obj)
    {
        bdb_TXN *txnst;
        int res;

        GetTxnDB(obj, txnst);
    #if HAVE_ST_DB_TXN_ID
        res = txnst->txnid->id(txnst->txnid);
    #else
        res = txn_id(txnst->txnid);
    #endif
        return INT2FIX(res);
    }

lock_timeout=(p1) click to toggle source

    static VALUE
    bdb_txn_set_lock_timeout(VALUE obj, VALUE a)
    {
        bdb_TXN *txnst;

        if (!NIL_P(a)) {
            GetTxnDB(obj, txnst);
            bdb_test_error(txnst->txnid->set_timeout(txnst->txnid, NUM2UINT(a), DB_SET_LOCK_TIMEOUT));
        }
        return obj;
    }

name() click to toggle source

    static VALUE
    bdb_txn_get_name(VALUE obj)
    {
        bdb_TXN *txnst;
        const char *name;

        GetTxnDB(obj, txnst);
        bdb_test_error(txnst->txnid->get_name(txnst->txnid, &name));
        return rb_tainted_str_new2(name);
    }

name=(p1) click to toggle source

    static VALUE
    bdb_txn_set_name(VALUE obj, VALUE a)
    {
        bdb_TXN *txnst;

        GetTxnDB(obj, txnst);
        bdb_test_error(txnst->txnid->set_name(txnst->txnid, StringValuePtr(a)));
        return a;
    }

set_lock_timeout(p1) click to toggle source

    static VALUE
    bdb_txn_set_lock_timeout(VALUE obj, VALUE a)
    {
        bdb_TXN *txnst;

        if (!NIL_P(a)) {
            GetTxnDB(obj, txnst);
            bdb_test_error(txnst->txnid->set_timeout(txnst->txnid, NUM2UINT(a), DB_SET_LOCK_TIMEOUT));
        }
        return obj;
    }

set_timeout(p1) click to toggle source

    static VALUE
    bdb_txn_set_timeout(VALUE obj, VALUE a)
    {
        if (!NIL_P(a)) {
            if (TYPE(a) == T_ARRAY) {
                if (RARRAY_LEN(a) >= 1 && !NIL_P(RARRAY_PTR(a)[0])) {
                    bdb_txn_set_txn_timeout(obj, RARRAY_PTR(a)[0]);
                }
                if (RARRAY_LEN(a) == 2 && !NIL_P(RARRAY_PTR(a)[1])) {
                    bdb_txn_set_lock_timeout(obj, RARRAY_PTR(a)[1]);
                }
            }
            else {
                bdb_txn_set_txn_timeout(obj, a);
            }
        }
        return obj;
    }

set_txn_timeout(p1) click to toggle source

    static VALUE
    bdb_txn_set_txn_timeout(VALUE obj, VALUE a)
    {
        bdb_TXN *txnst;

        if (!NIL_P(a)) {
            GetTxnDB(obj, txnst);
            bdb_test_error(txnst->txnid->set_timeout(txnst->txnid, NUM2UINT(a), DB_SET_TXN_TIMEOUT));
        }
        return obj;
    }

timeout=(p1) click to toggle source

    static VALUE
    bdb_txn_set_timeout(VALUE obj, VALUE a)
    {
        if (!NIL_P(a)) {
            if (TYPE(a) == T_ARRAY) {
                if (RARRAY_LEN(a) >= 1 && !NIL_P(RARRAY_PTR(a)[0])) {
                    bdb_txn_set_txn_timeout(obj, RARRAY_PTR(a)[0]);
                }
                if (RARRAY_LEN(a) == 2 && !NIL_P(RARRAY_PTR(a)[1])) {
                    bdb_txn_set_lock_timeout(obj, RARRAY_PTR(a)[1]);
                }
            }
            else {
                bdb_txn_set_txn_timeout(obj, a);
            }
        }
        return obj;
    }

transaction(*args) click to toggle source

    static VALUE
    bdb_env_begin(int argc, VALUE *argv, VALUE obj)
    {
        return bdb_env_rslbl_begin(Qfalse, argc, argv, obj);
    }

txn_abort() click to toggle source

    static VALUE
    bdb_txn_abort(VALUE obj)
    {
        bdb_TXN *txnst;

        GetTxnDB(obj, txnst);
        bdb_txn_close_all(obj, Qfalse);
    #if HAVE_ST_DB_TXN_ABORT
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_abort)
            bdb_test_error(txnst->txn_cxx_abort(txnst->txn_cxx) );
        else
    #endif
            bdb_test_error(txnst->txnid->abort(txnst->txnid));
    #else
        bdb_test_error(txn_abort(txnst->txnid));
    #endif
        txnst->txnid = NULL;
        if (txnst->status == THROW) {
            txnst->status = ROLLBACK;
            rb_throw("__bdb__begin", Data_Wrap_Struct(bdb_cTxnCatch, 0, 0, txnst));
        }
        return Qtrue;
    }

txn_assoc(*args) click to toggle source

    static VALUE
    bdb_txn_assoc(int argc, VALUE *argv, VALUE obj)
    {
        int i;
        VALUE ary, a;
        bdb_TXN *txnst;

        ary = rb_ary_new();
        GetTxnDB(obj, txnst);
        for (i = 0; i < argc; i++) {
            a = rb_funcall(argv[i], rb_intern("__txn_dup__"), 1, obj);
            bdb_ary_push(&txnst->db_assoc, a);
        bdb_ary_push(&txnst->db_assoc_objassoc_ary, (VALUE)create_assoc(a, txnst, BDB_OBJ_TX));
            rb_ary_push(ary, a);
        }
        switch (RARRAY_LEN(ary)) {
        case 0: return Qnil;
        case 1: return RARRAY_PTR(ary)[0];
        default: return ary;
        }
    }

txn_begin(*args) click to toggle source

    static VALUE
    bdb_env_begin(int argc, VALUE *argv, VALUE obj)
    {
        return bdb_env_rslbl_begin(Qfalse, argc, argv, obj);
    }

txn_close(p1 = v1) click to toggle source

    static VALUE
    bdb_txn_commit(int argc, VALUE *argv, VALUE obj)
    {
        bdb_TXN *txnst;
        VALUE a;
        int flags;

        rb_secure(4);
        flags = 0;
        if (rb_scan_args(argc, argv, "01", &a) == 1) {
            flags = NUM2INT(a);
        }
        GetTxnDB(obj, txnst);
        bdb_txn_close_all(obj, Qtrue);
    #if HAVE_ST_DB_TXN_COMMIT
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_commit)
            bdb_test_error(txnst->txn_cxx_commit(txnst->txn_cxx, flags) );
        else
    #endif
            bdb_test_error(txnst->txnid->commit(txnst->txnid, flags));
    #else
    #if HAVE_TXN_COMMIT_2
        bdb_test_error(txn_commit(txnst->txnid, flags));
    #else
        bdb_test_error(txn_commit(txnst->txnid));
    #endif
    #endif
        txnst->txnid = NULL;
        if (txnst->status == THROW) {
            txnst->status = COMMIT;
            rb_throw("__bdb__begin", Data_Wrap_Struct(bdb_cTxnCatch, 0, 0, txnst));
        }
        return Qtrue;
    }

txn_commit(p1 = v1) click to toggle source

    static VALUE
    bdb_txn_commit(int argc, VALUE *argv, VALUE obj)
    {
        bdb_TXN *txnst;
        VALUE a;
        int flags;

        rb_secure(4);
        flags = 0;
        if (rb_scan_args(argc, argv, "01", &a) == 1) {
            flags = NUM2INT(a);
        }
        GetTxnDB(obj, txnst);
        bdb_txn_close_all(obj, Qtrue);
    #if HAVE_ST_DB_TXN_COMMIT
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_commit)
            bdb_test_error(txnst->txn_cxx_commit(txnst->txn_cxx, flags) );
        else
    #endif
            bdb_test_error(txnst->txnid->commit(txnst->txnid, flags));
    #else
    #if HAVE_TXN_COMMIT_2
        bdb_test_error(txn_commit(txnst->txnid, flags));
    #else
        bdb_test_error(txn_commit(txnst->txnid));
    #endif
    #endif
        txnst->txnid = NULL;
        if (txnst->status == THROW) {
            txnst->status = COMMIT;
            rb_throw("__bdb__begin", Data_Wrap_Struct(bdb_cTxnCatch, 0, 0, txnst));
        }
        return Qtrue;
    }

txn_discard() click to toggle source

    static VALUE
    bdb_txn_discard(VALUE obj)
    {
        bdb_TXN *txnst;
        int flags;

        rb_secure(4);
        flags = 0;
        GetTxnDB(obj, txnst);
    #if HAVE_ST_DB_TXN_DISCARD
    #if HAVE_DBXML_INTERFACE
        if (txnst->txn_cxx_discard)
            bdb_test_error(txnst->txn_cxx_discard(txnst->txn_cxx, flags) );
        else
    #endif
            bdb_test_error(txnst->txnid->discard(txnst->txnid, flags));
    #else
        bdb_test_error(txn_discard(txnst->txnid, flags));
    #endif
        txnst->txnid = NULL;
        return Qtrue;
    }

txn_id() click to toggle source

    static VALUE
    bdb_txn_id(VALUE obj)
    {
        bdb_TXN *txnst;
        int res;

        GetTxnDB(obj, txnst);
    #if HAVE_ST_DB_TXN_ID
        res = txnst->txnid->id(txnst->txnid);
    #else
        res = txn_id(txnst->txnid);
    #endif
        return INT2FIX(res);
    }

txn_timeout=(p1) click to toggle source

    static VALUE
    bdb_txn_set_txn_timeout(VALUE obj, VALUE a)
    {
        bdb_TXN *txnst;

        if (!NIL_P(a)) {
            GetTxnDB(obj, txnst);
            bdb_test_error(txnst->txnid->set_timeout(txnst->txnid, NUM2UINT(a), DB_SET_TXN_TIMEOUT));
        }
        return obj;
    }