# class BDB::Lsn

### Public Instance Methods

<=>(p1) click to toggle source

    static VALUE
    bdb_lsn_log_compare(VALUE obj, VALUE a)
    {
        struct dblsnst *lsnst1, *lsnst2;
        bdb_ENV *envst1, *envst2;

        if (!rb_obj_is_kind_of(a, bdb_cLsn)) {
            rb_raise(bdb_eFatal, "invalid argument for <=>");
        }
        GetLsn(obj, lsnst1, envst1);
        GetLsn(a, lsnst2, envst2);
        return INT2NUM(log_compare(lsnst1->lsn, lsnst2->lsn));
    }

close() click to toggle source

    static VALUE
    bdb_log_cursor_close(VALUE obj)
    {
        struct dblsnst *lsnst;

        Data_Get_Struct(obj, struct dblsnst, lsnst);
        bdb_clean_env(lsnst->env, obj);

        return log_cursor_close(obj);
    }

compare(p1) click to toggle source

    static VALUE
    bdb_lsn_log_compare(VALUE obj, VALUE a)
    {
        struct dblsnst *lsnst1, *lsnst2;
        bdb_ENV *envst1, *envst2;

        if (!rb_obj_is_kind_of(a, bdb_cLsn)) {
            rb_raise(bdb_eFatal, "invalid argument for <=>");
        }
        GetLsn(obj, lsnst1, envst1);
        GetLsn(a, lsnst2, envst2);
        return INT2NUM(log_compare(lsnst1->lsn, lsnst2->lsn));
    }

cursor() click to toggle source

    static VALUE
    bdb_log_cursor(VALUE lsn)
    {
        bdb_ENV *envst;
        struct dblsnst *lsnst;

        Data_Get_Struct(lsn, struct dblsnst, lsnst);
        if (!lsnst->cursor) {
            GetEnvDB(lsnst->env, envst);
            bdb_test_error(envst->envp->log_cursor(envst->envp, &lsnst->cursor, 0));
            bdb_ary_push(&envst->db_ary, lsn);
        //bdb_ary_push(&envst->db_objassoc_ary, (VALUE)create_assoc(lsn, lsnst, BDB_OBJ_LOG));
        }
        return lsn;
    }

each() click to toggle source

    static VALUE
    bdb_log_each(VALUE lsn)
    {
        struct dblsnst *lsnst;

        Data_Get_Struct(lsn, struct dblsnst, lsnst);
        lsnst->flags = DB_NEXT;
        return rb_ensure(bdb_log_i_get, lsn, bdb_log_cursor_close, lsn);
    }

env() click to toggle source

    static VALUE
    bdb_lsn_env(VALUE obj)
    {
        struct dblsnst *lsnst;
        bdb_ENV *envst;
        GetLsn(obj, lsnst, envst);
        return lsnst->env;
    }

file() click to toggle source

    static VALUE
    bdb_lsn_log_file(VALUE obj)
    {
        struct dblsnst *lsnst;
        bdb_ENV *envst;
        char name[2048];

        GetLsn(obj, lsnst, envst);
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        bdb_test_error(log_file(envst->envp->lg_info, lsnst->lsn, name, 2048));
    #elif HAVE_ST_DB_ENV_LOG_FILE
        bdb_test_error(envst->envp->log_file(envst->envp, lsnst->lsn, name, 2048));
    #else
        bdb_test_error(log_file(envst->envp, lsnst->lsn, name, 2048));
    #endif
        return rb_tainted_str_new2(name);
    }

flush() click to toggle source

    static VALUE
    bdb_lsn_log_flush(VALUE obj)
    {
        struct dblsnst *lsnst;
        bdb_ENV *envst;

        GetLsn(obj, lsnst, envst);
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        bdb_test_error(log_flush(envst->envp->lg_info, lsnst->lsn));
    #elif HAVE_ST_DB_ENV_LOG_FLUSH
        bdb_test_error(envst->envp->log_flush(envst->envp, lsnst->lsn));
    #else
        bdb_test_error(log_flush(envst->envp, lsnst->lsn));
    #endif
        return obj;
    }

get(p1 = v1) click to toggle source

    static VALUE
    bdb_lsn_log_get(int argc, VALUE *argv, VALUE obj)
    {
        struct dblsnst *lsnst;
        DBT data;
        VALUE res, a;
        int ret, flags;
        bdb_ENV *envst;
    #if HAVE_ST_DB_ENV_LOG_CURSOR
        DB_LOGC *cursor;
    #endif

        flags = DB_SET;
        if (rb_scan_args(argc, argv, "01", &a) == 1) {
            flags = NUM2INT(a);
        }
        GetLsn(obj, lsnst, envst);
    #if HAVE_ST_DB_ENV_LOG_CURSOR
        bdb_test_error(envst->envp->log_cursor(envst->envp, &cursor, 0));
    #endif
        MEMZERO(&data, DBT, 1);
        data.flags |= DB_DBT_MALLOC;
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        ret = bdb_test_error(log_get(envst->envp->lg_info, lsnst->lsn, &data, flags));
    #elif HAVE_ST_DB_ENV_LOG_CURSOR
        ret = cursor->get(cursor, lsnst->lsn, &data, flags);
        cursor->close(cursor, 0);
        ret = bdb_test_error(ret);
    #else
        ret = bdb_test_error(log_get(envst->envp, lsnst->lsn, &data, flags));
    #endif
        if (ret == DB_NOTFOUND) {
            return Qnil;
        }
        res = rb_tainted_str_new(data.data, data.size);
        free(data.data);
        return res;
    }

log_close() click to toggle source

    static VALUE
    bdb_log_cursor_close(VALUE obj)
    {
        struct dblsnst *lsnst;

        Data_Get_Struct(obj, struct dblsnst, lsnst);
        bdb_clean_env(lsnst->env, obj);

        return log_cursor_close(obj);
    }

log_compare(p1) click to toggle source

    static VALUE
    bdb_lsn_log_compare(VALUE obj, VALUE a)
    {
        struct dblsnst *lsnst1, *lsnst2;
        bdb_ENV *envst1, *envst2;

        if (!rb_obj_is_kind_of(a, bdb_cLsn)) {
            rb_raise(bdb_eFatal, "invalid argument for <=>");
        }
        GetLsn(obj, lsnst1, envst1);
        GetLsn(a, lsnst2, envst2);
        return INT2NUM(log_compare(lsnst1->lsn, lsnst2->lsn));
    }

log_cursor() click to toggle source

    static VALUE
    bdb_log_cursor(VALUE lsn)
    {
        bdb_ENV *envst;
        struct dblsnst *lsnst;

        Data_Get_Struct(lsn, struct dblsnst, lsnst);
        if (!lsnst->cursor) {
            GetEnvDB(lsnst->env, envst);
            bdb_test_error(envst->envp->log_cursor(envst->envp, &lsnst->cursor, 0));
            bdb_ary_push(&envst->db_ary, lsn);
        //bdb_ary_push(&envst->db_objassoc_ary, (VALUE)create_assoc(lsn, lsnst, BDB_OBJ_LOG));
        }
        return lsn;
    }

log_each() click to toggle source

    static VALUE
    bdb_log_each(VALUE lsn)
    {
        struct dblsnst *lsnst;

        Data_Get_Struct(lsn, struct dblsnst, lsnst);
        lsnst->flags = DB_NEXT;
        return rb_ensure(bdb_log_i_get, lsn, bdb_log_cursor_close, lsn);
    }

log_file() click to toggle source

    static VALUE
    bdb_lsn_log_file(VALUE obj)
    {
        struct dblsnst *lsnst;
        bdb_ENV *envst;
        char name[2048];

        GetLsn(obj, lsnst, envst);
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        bdb_test_error(log_file(envst->envp->lg_info, lsnst->lsn, name, 2048));
    #elif HAVE_ST_DB_ENV_LOG_FILE
        bdb_test_error(envst->envp->log_file(envst->envp, lsnst->lsn, name, 2048));
    #else
        bdb_test_error(log_file(envst->envp, lsnst->lsn, name, 2048));
    #endif
        return rb_tainted_str_new2(name);
    }

log_flush() click to toggle source

    static VALUE
    bdb_lsn_log_flush(VALUE obj)
    {
        struct dblsnst *lsnst;
        bdb_ENV *envst;

        GetLsn(obj, lsnst, envst);
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        bdb_test_error(log_flush(envst->envp->lg_info, lsnst->lsn));
    #elif HAVE_ST_DB_ENV_LOG_FLUSH
        bdb_test_error(envst->envp->log_flush(envst->envp, lsnst->lsn));
    #else
        bdb_test_error(log_flush(envst->envp, lsnst->lsn));
    #endif
        return obj;
    }

log_get(p1 = v1) click to toggle source

    static VALUE
    bdb_lsn_log_get(int argc, VALUE *argv, VALUE obj)
    {
        struct dblsnst *lsnst;
        DBT data;
        VALUE res, a;
        int ret, flags;
        bdb_ENV *envst;
    #if HAVE_ST_DB_ENV_LOG_CURSOR
        DB_LOGC *cursor;
    #endif

        flags = DB_SET;
        if (rb_scan_args(argc, argv, "01", &a) == 1) {
            flags = NUM2INT(a);
        }
        GetLsn(obj, lsnst, envst);
    #if HAVE_ST_DB_ENV_LOG_CURSOR
        bdb_test_error(envst->envp->log_cursor(envst->envp, &cursor, 0));
    #endif
        MEMZERO(&data, DBT, 1);
        data.flags |= DB_DBT_MALLOC;
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        ret = bdb_test_error(log_get(envst->envp->lg_info, lsnst->lsn, &data, flags));
    #elif HAVE_ST_DB_ENV_LOG_CURSOR
        ret = cursor->get(cursor, lsnst->lsn, &data, flags);
        cursor->close(cursor, 0);
        ret = bdb_test_error(ret);
    #else
        ret = bdb_test_error(log_get(envst->envp, lsnst->lsn, &data, flags));
    #endif
        if (ret == DB_NOTFOUND) {
            return Qnil;
        }
        res = rb_tainted_str_new(data.data, data.size);
        free(data.data);
        return res;
    }

log_reverse_each() click to toggle source

    static VALUE
    bdb_log_hcae(VALUE lsn)
    {
        struct dblsnst *lsnst;

        Data_Get_Struct(lsn, struct dblsnst, lsnst);
        lsnst->flags = DB_PREV;
        return rb_ensure(bdb_log_i_get, lsn, bdb_log_cursor_close, lsn);
     }

    #endif

    static VALUE
    bdb_env_log_archive(int argc, VALUE *argv, VALUE obj)
    {
        char **list, **file;
        bdb_ENV *envst;
        int flag;
        VALUE res;

        GetEnvDB(obj, envst);
        flag = 0;
        list = NULL;
        if (rb_scan_args(argc, argv, "01", &res)) {
            flag = NUM2INT(res);
        }
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        bdb_test_error(log_archive(envst->envp->lg_info, &list, flag, NULL));
    #elif HAVE_ST_DB_ENV_LOG_ARCHIVE
        bdb_test_error(envst->envp->log_archive(envst->envp, &list, flag));
    #else
    #if HAVE_DB_LOG_ARCHIVE_4
        bdb_test_error(log_archive(envst->envp, &list, flag, NULL));
    #else
        bdb_test_error(log_archive(envst->envp, &list, flag));
    #endif
    #endif
        res = rb_ary_new();
        for (file = list; file != NULL && *file != NULL; file++) {
            rb_ary_push(res, rb_tainted_str_new2(*file));
        }
        if (list != NULL) free(list);
        return res;
    }

reverse_each() click to toggle source

    static VALUE
    bdb_log_hcae(VALUE lsn)
    {
        struct dblsnst *lsnst;

        Data_Get_Struct(lsn, struct dblsnst, lsnst);
        lsnst->flags = DB_PREV;
        return rb_ensure(bdb_log_i_get, lsn, bdb_log_cursor_close, lsn);
     }

    #endif

    static VALUE
    bdb_env_log_archive(int argc, VALUE *argv, VALUE obj)
    {
        char **list, **file;
        bdb_ENV *envst;
        int flag;
        VALUE res;

        GetEnvDB(obj, envst);
        flag = 0;
        list = NULL;
        if (rb_scan_args(argc, argv, "01", &res)) {
            flag = NUM2INT(res);
        }
    #if HAVE_ST_DB_ENV_LG_INFO
        if (!envst->envp->lg_info) {
            rb_raise(bdb_eFatal, "log region not open");
        }
        bdb_test_error(log_archive(envst->envp->lg_info, &list, flag, NULL));
    #elif HAVE_ST_DB_ENV_LOG_ARCHIVE
        bdb_test_error(envst->envp->log_archive(envst->envp, &list, flag));
    #else
    #if HAVE_DB_LOG_ARCHIVE_4
        bdb_test_error(log_archive(envst->envp, &list, flag, NULL));
    #else
        bdb_test_error(log_archive(envst->envp, &list, flag));
    #endif
    #endif
        res = rb_ary_new();
        for (file = list; file != NULL && *file != NULL; file++) {
            rb_ary_push(res, rb_tainted_str_new2(*file));
        }
        if (list != NULL) free(list);
        return res;
    }