2007-12-17 22:00:54 +00:00
|
|
|
#include <db.h>
|
|
|
|
#include <string.h>
|
2007-12-19 23:01:41 +00:00
|
|
|
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
|
2007-12-17 22:00:54 +00:00
|
|
|
|
|
|
|
class Dbt;
|
2007-12-18 16:22:21 +00:00
|
|
|
class DbEnv;
|
|
|
|
class DbTxn;
|
|
|
|
class Dbc;
|
2007-12-17 22:00:54 +00:00
|
|
|
|
2007-12-18 01:44:22 +00:00
|
|
|
// DBT and Dbt objects are the same pointers. So watch out if you use Dbt to make other classes (e.g., with subclassing).
|
2007-12-17 22:00:54 +00:00
|
|
|
class Dbt : private DBT
|
|
|
|
{
|
2007-12-18 18:34:44 +00:00
|
|
|
friend class Dbc;
|
2007-12-17 22:00:54 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
void * get_data(void) const { return data; }
|
|
|
|
void set_data(void *p) { data = p; }
|
|
|
|
|
|
|
|
u_int32_t get_size(void) const { return size; }
|
2007-12-20 18:28:08 +00:00
|
|
|
void set_size(u_int32_t p) { size = p; }
|
2007-12-17 22:00:54 +00:00
|
|
|
|
2007-12-18 18:34:44 +00:00
|
|
|
u_int32_t get_flags() const { return flags; }
|
2007-12-20 18:28:08 +00:00
|
|
|
void set_flags(u_int32_t f) { flags = f; }
|
2007-12-18 18:34:44 +00:00
|
|
|
|
2007-12-20 18:38:29 +00:00
|
|
|
u_int32_t get_ulen() const { return ulen; }
|
|
|
|
void set_ulen(u_int32_t p) { ulen = p; }
|
|
|
|
|
2007-12-17 22:00:54 +00:00
|
|
|
DBT *get_DBT(void) { return (DBT*)this; }
|
|
|
|
|
2007-12-18 16:22:21 +00:00
|
|
|
Dbt(void */*data*/, u_int32_t /*size*/);
|
2007-12-17 22:00:54 +00:00
|
|
|
Dbt(void);
|
|
|
|
~Dbt();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Nothing here.
|
2007-12-18 01:31:34 +00:00
|
|
|
};
|
2007-12-17 22:00:54 +00:00
|
|
|
|
2007-12-20 19:00:35 +00:00
|
|
|
extern "C" {
|
|
|
|
typedef int (*bt_compare_fcn_type)(DB *db, const DBT *dbt1, const DBT *dbt2);
|
|
|
|
};
|
|
|
|
|
2007-12-18 01:31:34 +00:00
|
|
|
class Db {
|
|
|
|
public:
|
|
|
|
/* Functions to make C++ work, defined in the BDB C++ API documents */
|
|
|
|
Db(DbEnv *dbenv, u_int32_t flags);
|
|
|
|
~Db();
|
|
|
|
|
2007-12-18 16:22:21 +00:00
|
|
|
DB *get_DB(void) {
|
2007-12-18 01:31:34 +00:00
|
|
|
return the_db;
|
|
|
|
}
|
2007-12-18 16:22:21 +00:00
|
|
|
const DB *get_const_DB() const {
|
2007-12-18 01:31:34 +00:00
|
|
|
return the_db;
|
|
|
|
}
|
2007-12-18 16:22:21 +00:00
|
|
|
static Db *get_Db(DB *db) {
|
|
|
|
return (Db*)db->api_internal;
|
2007-12-18 01:31:34 +00:00
|
|
|
}
|
2007-12-18 16:22:21 +00:00
|
|
|
static const Db *get_const_Db(const DB *db) {
|
|
|
|
return (Db*)db->api_internal;
|
2007-12-18 01:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* C++ analogues of the C functions. */
|
|
|
|
int close(u_int32_t /*flags*/);
|
|
|
|
int cursor(DbTxn */*txnid*/, Dbc **/*cursorp*/, u_int32_t /*flags*/);
|
|
|
|
int del(DbTxn */*txnid*/, Dbt */*key*/, u_int32_t /*flags*/);
|
|
|
|
int get(DbTxn */*txnid*/, Dbt */*key*/, Dbt */*data*/, u_int32_t /*flags*/);
|
|
|
|
int open(DbTxn */*txnid*/, const char */*name*/, const char */*subname*/, DBTYPE, u_int32_t, int);
|
|
|
|
int put(DbTxn *, Dbt *, Dbt *, u_int32_t);
|
|
|
|
int get_flags(u_int32_t *);
|
|
|
|
int set_flags(u_int32_t);
|
2007-12-18 19:37:59 +00:00
|
|
|
int set_pagesize(u_int32_t);
|
2007-12-20 19:00:35 +00:00
|
|
|
int remove(const char *file, const char *database, u_int32_t flags);
|
|
|
|
int set_bt_compare(bt_compare_fcn_type bt_compare_fcn);
|
2007-12-18 01:31:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DB *the_db;
|
2007-12-18 16:22:21 +00:00
|
|
|
DbEnv *the_Env;
|
|
|
|
int is_private_env;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DbEnv {
|
|
|
|
friend class Db;
|
|
|
|
public:
|
|
|
|
DbEnv(u_int32_t flags);
|
|
|
|
|
|
|
|
DB_ENV *get_DB_ENV(void) {
|
2007-12-18 16:34:48 +00:00
|
|
|
if (this==0) return 0;
|
2007-12-18 16:22:21 +00:00
|
|
|
return the_env;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* C++ analogues of the C functions. */
|
|
|
|
int close(u_int32_t);
|
2007-12-18 19:37:59 +00:00
|
|
|
int open(const char *, u_int32_t, int);
|
|
|
|
int set_cachesize(u_int32_t, u_int32_t, int);
|
2007-12-19 16:57:11 +00:00
|
|
|
#if DB_VERSION_MAJOR<4 || (DB_VERSION_MAJOR==4 && DB_VERSION_MINOR<=4)
|
|
|
|
// set_lk_max is only defined for versions up to 4.4
|
2007-12-18 19:37:59 +00:00
|
|
|
int set_lk_max(u_int32_t);
|
2007-12-19 16:57:11 +00:00
|
|
|
#endif
|
2007-12-18 19:37:59 +00:00
|
|
|
int txn_begin(DbTxn *, DbTxn **, u_int32_t);
|
2007-12-20 19:43:42 +00:00
|
|
|
int set_data_dir(const char *dir);
|
|
|
|
void set_errpfx(const char *errpfx);
|
2007-12-18 16:22:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DB_ENV *the_env;
|
|
|
|
|
|
|
|
DbEnv(DB_ENV *, u_int32_t flags);
|
|
|
|
};
|
|
|
|
|
2007-12-18 01:31:34 +00:00
|
|
|
|
2007-12-18 16:22:21 +00:00
|
|
|
class DbTxn {
|
|
|
|
public:
|
2007-12-18 19:37:59 +00:00
|
|
|
int commit (u_int32_t /*flags*/);
|
|
|
|
|
2007-12-18 16:22:21 +00:00
|
|
|
DB_TXN *get_DB_TXN()
|
|
|
|
{
|
2007-12-18 16:34:48 +00:00
|
|
|
if (this==0) return 0;
|
2007-12-18 16:22:21 +00:00
|
|
|
return the_txn;
|
|
|
|
}
|
2007-12-18 19:37:59 +00:00
|
|
|
|
|
|
|
DbTxn(DB_TXN*);
|
2007-12-18 16:22:21 +00:00
|
|
|
private:
|
|
|
|
DB_TXN *the_txn;
|
2007-12-18 01:31:34 +00:00
|
|
|
};
|
2007-12-18 16:22:21 +00:00
|
|
|
|
2007-12-18 18:34:44 +00:00
|
|
|
class Dbc : protected DBC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int close(void);
|
|
|
|
int get(Dbt*, Dbt *, u_int32_t);
|
|
|
|
|
|
|
|
};
|
|
|
|
|