Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
TestDB Class Reference

List of all members.

Public Member Functions

 TestDB (void)
 ~TestDB (void)
int put (void)
void list (void)

Private Attributes

int counter_
DbEnv * env_
Db * db_

Detailed Description

Definition at line 12 of file test.cpp.


Constructor & Destructor Documentation

TestDB::TestDB ( void  )

Definition at line 25 of file test.cpp.

{
    counter_ = 0;
    env_ = new DbEnv(0); // Exception will occure
    env_->open("db", DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_THREAD, 0644);
    db_ = new Db(env_, 0);
    db_->open(NULL, "test", NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT | DB_THREAD, 0644);
}
TestDB::~TestDB ( void  )

Definition at line 34 of file test.cpp.

{
    std::cout << "Close DB" << std::endl;
    if (db_ != NULL) {
        db_->close(0);
        delete db_;
        db_ = NULL;
    }
    if (env_ != NULL) {
        env_->close(0);
        delete env_;
        env_ = NULL;
    }
}

Member Function Documentation

void TestDB::list ( void  )

Definition at line 74 of file test.cpp.

{
    Dbc *cursor = NULL;
    DbTxn *txn = NULL;
    env_->txn_begin(NULL, &txn, 0);
    printf("list: %p\n", txn);
    try {
        db_->cursor(txn, &cursor, 0);
        Dbt key, value;
        key.set_flags(0);
        value.set_flags(0);
        int ret;
        std::cout << "Start loop" << std::endl;
        for (;;) {
            ret = cursor->get(&key, &value, DB_NEXT);
            if (ret == DB_NOTFOUND) {
                break;
            }
            int k = *(int *)key.get_data();
            char *v = (char *)value.get_data();
            std::cout << k << " -> " << v << std::endl;  
            // free(key.get_data());
            // free(value.get_data());
            // sleep(1);
        }
        std::cout << "Endloop" << std::endl;
        cursor->close();
        txn->commit(0);
    } catch (DbException &e) {
        std::cerr << "Error in transaction: " << e.what() << std::endl;
        if (cursor != NULL) {
            cursor->close();
        }
        txn->abort();
    }
}

Here is the caller graph for this function:

int TestDB::put ( void  )

Definition at line 49 of file test.cpp.

{
    char foo[] = "foo";
    Dbt key(&counter_, sizeof(counter_));
    Dbt data(foo, sizeof(foo));
    DbTxn *txn = NULL;
    try {
        unsigned long int id = (unsigned long int)(void*)Glib::Thread::self();
        int ret = env_->txn_begin(NULL, &txn, 0);
        printf("(%d) put(%d): %p\n", id, ret, txn);
    } catch (std::exception &e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return counter_;
    }
    try {
        db_->put(txn, &key, &data, 0);
        txn->commit(0);
    } catch (DbException &e) {
        std::cerr << "Error in transaction: " << e.what() << std::endl;
        txn->abort();
    }
    txn = NULL;
    return (counter_++);
}

Here is the caller graph for this function:


Member Data Documentation

int TestDB::counter_ [private]

Definition at line 15 of file test.cpp.

Db* TestDB::db_ [private]

Definition at line 17 of file test.cpp.

DbEnv* TestDB::env_ [private]

Definition at line 16 of file test.cpp.


The documentation for this class was generated from the following file: