summaryrefslogtreecommitdiff
path: root/db/cxx
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-12-15 21:42:09 +0000
committerjbj <devnull@localhost>2003-12-15 21:42:09 +0000
commit8960e3895f7af91126465368dff8fbb36ab4e853 (patch)
tree3c515e39dde0e88edeb806ea87d08524ba25c761 /db/cxx
parent752cac72e220dcad4e6fce39508e714e59e3e0a1 (diff)
downloadlibrpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.tar.gz
librpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.tar.bz2
librpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.zip
- upgrade to db-4.2.52.
CVS patchset: 6972 CVS date: 2003/12/15 21:42:09
Diffstat (limited to 'db/cxx')
-rw-r--r--db/cxx/cxx_db.cpp102
-rw-r--r--db/cxx/cxx_dbc.cpp28
-rw-r--r--db/cxx/cxx_dbt.cpp4
-rw-r--r--db/cxx/cxx_env.cpp164
-rw-r--r--db/cxx/cxx_except.cpp272
-rw-r--r--db/cxx/cxx_lock.cpp86
-rw-r--r--db/cxx/cxx_logc.cpp13
-rw-r--r--db/cxx/cxx_mpool.cpp229
-rw-r--r--db/cxx/cxx_multi.cpp67
-rw-r--r--db/cxx/cxx_txn.cpp145
10 files changed, 671 insertions, 439 deletions
diff --git a/db/cxx/cxx_db.cpp b/db/cxx/cxx_db.cpp
index d6d15a0bf..de6c983f2 100644
--- a/db/cxx/cxx_db.cpp
+++ b/db/cxx/cxx_db.cpp
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997-2002
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "Id: cxx_db.cpp,v 11.71 2002/08/26 22:13:36 mjc Exp ";
+static const char revid[] = "$Id: cxx_db.cpp,v 11.77 2003/04/18 08:36:29 mjc Exp $";
#endif /* not lint */
#include <errno.h>
@@ -39,7 +39,7 @@ int Db::_name _argspec \
\
ret = db->_name _arglist; \
if (!_retok(ret)) \
- DB_ERROR("Db::" # _name, ret, error_policy()); \
+ DB_ERROR(env_, "Db::" # _name, ret, error_policy()); \
return (ret); \
}
@@ -50,14 +50,14 @@ int Db::_name _argspec \
DB *db = unwrap(this); \
\
if (!db) { \
- DB_ERROR("Db::" # _name, EINVAL, error_policy()); \
+ DB_ERROR(env_, "Db::" # _name, EINVAL, error_policy()); \
return (EINVAL); \
} \
if (_cleanup) \
cleanup(); \
ret = db->_name _arglist; \
if (!_retok(ret)) \
- DB_ERROR("Db::" # _name, ret, error_policy()); \
+ DB_ERROR(env_, "Db::" # _name, ret, error_policy()); \
return (ret); \
}
@@ -92,6 +92,7 @@ void Db::_name _argspec \
Db::Db(DbEnv *env, u_int32_t flags)
: imp_(0)
, env_(env)
+, mpf_(0)
, construct_error_(0)
, flags_(0)
, construct_flags_(flags)
@@ -107,7 +108,7 @@ Db::Db(DbEnv *env, u_int32_t flags)
flags_ |= DB_CXX_PRIVATE_ENV;
if ((construct_error_ = initialize()) != 0)
- DB_ERROR("Db::Db", construct_error_, error_policy());
+ DB_ERROR(env_, "Db::Db", construct_error_, error_policy());
}
// If the DB handle is still open, we close it. This is to make stack
@@ -159,6 +160,10 @@ int Db::initialize()
if ((flags_ & DB_CXX_PRIVATE_ENV) != 0)
env_ = new DbEnv(db->dbenv, cxx_flags);
+ // Create a DbMpoolFile from the DB_MPOOLFILE* in the DB handle.
+ mpf_ = new DbMpoolFile();
+ mpf_->imp_ = wrap(db->mpf);
+
return (0);
}
@@ -173,7 +178,6 @@ void Db::cleanup()
if (db != NULL) {
// extra safety
- db->api_internal = 0;
imp_ = 0;
// we must dispose of the DbEnv object if
@@ -187,6 +191,8 @@ void Db::cleanup()
delete env_;
env_ = 0;
}
+
+ delete mpf_;
}
}
@@ -231,7 +237,7 @@ int Db::close(u_int32_t flags)
// the DB* structures.
//
if ((ret = db->close(db, flags)) != 0)
- DB_ERROR("Db::close", ret, error_policy());
+ DB_ERROR(env_, "Db::close", ret, error_policy());
return (ret);
}
@@ -259,9 +265,7 @@ void Db::errx(const char *format, ...)
DB_REAL_ERR(db->dbenv, 0, 0, 1, format);
}
-DB_METHOD(fd, (int *fdp),
- (db, fdp),
- DB_RETOK_STD)
+DB_METHOD(fd, (int *fdp), (db, fdp), DB_RETOK_STD)
int Db::get(DbTxn *txnid, Dbt *key, Dbt *value, u_int32_t flags)
{
@@ -272,9 +276,9 @@ int Db::get(DbTxn *txnid, Dbt *key, Dbt *value, u_int32_t flags)
if (!DB_RETOK_DBGET(ret)) {
if (ret == ENOMEM && DB_OVERFLOWED_DBT(value))
- DB_ERROR_DBT("Db::get", value, error_policy());
+ DB_ERROR_DBT(env_, "Db::get", value, error_policy());
else
- DB_ERROR("Db::get", ret, error_policy());
+ DB_ERROR(env_, "Db::get", ret, error_policy());
}
return (ret);
@@ -286,6 +290,25 @@ int Db::get_byteswapped(int *isswapped)
return (db->get_byteswapped(db, isswapped));
}
+DbEnv *Db::get_env()
+{
+ DB *db = (DB *)unwrapConst(this);
+ DB_ENV *dbenv;
+ (void)db->get_env(db, &dbenv);
+ return (dbenv != NULL ? DbEnv::get_DbEnv(dbenv) : NULL);
+}
+
+DbMpoolFile *Db::get_mpf()
+{
+ return (mpf_);
+}
+
+DB_METHOD(get_dbname, (const char **filenamep, const char **dbnamep),
+ (db, filenamep, dbnamep), DB_RETOK_STD)
+
+DB_METHOD(get_open_flags, (u_int32_t *flagsp),
+ (db, flagsp), DB_RETOK_STD)
+
int Db::get_type(DBTYPE *dbtype)
{
DB *db = (DB *)unwrapConst(this);
@@ -320,7 +343,7 @@ int Db::open(DbTxn *txnid, const char *file, const char *database,
mode);
if (!DB_RETOK_STD(ret))
- DB_ERROR("Db::open", ret, error_policy());
+ DB_ERROR(env_, "Db::open", ret, error_policy());
return (ret);
}
@@ -335,9 +358,9 @@ int Db::pget(DbTxn *txnid, Dbt *key, Dbt *pkey, Dbt *value, u_int32_t flags)
/* The logic here is identical to Db::get - reuse the macro. */
if (!DB_RETOK_DBGET(ret)) {
if (ret == ENOMEM && DB_OVERFLOWED_DBT(value))
- DB_ERROR_DBT("Db::pget", value, error_policy());
+ DB_ERROR_DBT(env_, "Db::pget", value, error_policy());
else
- DB_ERROR("Db::pget", ret, error_policy());
+ DB_ERROR(env_, "Db::pget", ret, error_policy());
}
return (ret);
@@ -412,7 +435,7 @@ extern "C" _rettype _db_##_name##_intercept_c _cargspec \
Db *cxxthis; \
\
DB_ASSERT(cthis != NULL); \
- cxxthis = (Db *)cthis->api_internal; \
+ cxxthis = Db::get_Db(cthis); \
DB_ASSERT(cxxthis != NULL); \
DB_ASSERT(cxxthis->_name##_callback_ != 0); \
\
@@ -523,12 +546,19 @@ int Db::verify(const char *name, const char *subdb,
if (!db)
ret = EINVAL;
- else
+ else {
+ // after a DB->verify (no matter if success or failure),
+ // the underlying DB object must not be accessed,
+ // so we clean up in advance.
+ //
+ cleanup();
+
ret = __db_verify_internal(db, name, subdb, ostr,
_verify_callback_c, flags);
+ }
if (!DB_RETOK_STD(ret))
- DB_ERROR("Db::verify", ret, error_policy());
+ DB_ERROR(env_, "Db::verify", ret, error_policy());
return (ret);
}
@@ -537,36 +567,62 @@ DB_METHOD(set_bt_compare, (bt_compare_fcn_type func),
(db, func), DB_RETOK_STD)
DB_METHOD(set_bt_maxkey, (u_int32_t bt_maxkey),
(db, bt_maxkey), DB_RETOK_STD)
+DB_METHOD(get_bt_minkey, (u_int32_t *bt_minkeyp),
+ (db, bt_minkeyp), DB_RETOK_STD)
DB_METHOD(set_bt_minkey, (u_int32_t bt_minkey),
(db, bt_minkey), DB_RETOK_STD)
DB_METHOD(set_bt_prefix, (bt_prefix_fcn_type func),
(db, func), DB_RETOK_STD)
DB_METHOD(set_dup_compare, (dup_compare_fcn_type func),
(db, func), DB_RETOK_STD)
-DB_METHOD(set_encrypt, (const char *passwd, int flags),
+DB_METHOD(get_encrypt_flags, (u_int32_t *flagsp),
+ (db, flagsp), DB_RETOK_STD)
+DB_METHOD(set_encrypt, (const char *passwd, u_int32_t flags),
(db, passwd, flags), DB_RETOK_STD)
+DB_METHOD_VOID(get_errfile, (FILE **errfilep), (db, errfilep))
DB_METHOD_VOID(set_errfile, (FILE *errfile), (db, errfile))
+DB_METHOD_VOID(get_errpfx, (const char **errpfx), (db, errpfx))
DB_METHOD_VOID(set_errpfx, (const char *errpfx), (db, errpfx))
+DB_METHOD(get_flags, (u_int32_t *flagsp), (db, flagsp),
+ DB_RETOK_STD)
DB_METHOD(set_flags, (u_int32_t flags), (db, flags),
DB_RETOK_STD)
+DB_METHOD(get_h_ffactor, (u_int32_t *h_ffactorp),
+ (db, h_ffactorp), DB_RETOK_STD)
DB_METHOD(set_h_ffactor, (u_int32_t h_ffactor),
(db, h_ffactor), DB_RETOK_STD)
DB_METHOD(set_h_hash, (h_hash_fcn_type func),
(db, func), DB_RETOK_STD)
+DB_METHOD(get_h_nelem, (u_int32_t *h_nelemp),
+ (db, h_nelemp), DB_RETOK_STD)
DB_METHOD(set_h_nelem, (u_int32_t h_nelem),
(db, h_nelem), DB_RETOK_STD)
+DB_METHOD(get_lorder, (int *db_lorderp), (db, db_lorderp),
+ DB_RETOK_STD)
DB_METHOD(set_lorder, (int db_lorder), (db, db_lorder),
DB_RETOK_STD)
+DB_METHOD(get_pagesize, (u_int32_t *db_pagesizep),
+ (db, db_pagesizep), DB_RETOK_STD)
DB_METHOD(set_pagesize, (u_int32_t db_pagesize),
(db, db_pagesize), DB_RETOK_STD)
+DB_METHOD(get_re_delim, (int *re_delimp),
+ (db, re_delimp), DB_RETOK_STD)
DB_METHOD(set_re_delim, (int re_delim),
(db, re_delim), DB_RETOK_STD)
+DB_METHOD(get_re_len, (u_int32_t *re_lenp),
+ (db, re_lenp), DB_RETOK_STD)
DB_METHOD(set_re_len, (u_int32_t re_len),
(db, re_len), DB_RETOK_STD)
+DB_METHOD(get_re_pad, (int *re_padp),
+ (db, re_padp), DB_RETOK_STD)
DB_METHOD(set_re_pad, (int re_pad),
(db, re_pad), DB_RETOK_STD)
-DB_METHOD(set_re_source, (char *re_source),
+DB_METHOD(get_re_source, (const char **re_source),
+ (db, re_source), DB_RETOK_STD)
+DB_METHOD(set_re_source, (const char *re_source),
(db, re_source), DB_RETOK_STD)
+DB_METHOD(get_q_extentsize, (u_int32_t *extentsizep),
+ (db, extentsizep), DB_RETOK_STD)
DB_METHOD(set_q_extentsize, (u_int32_t extentsize),
(db, extentsize), DB_RETOK_STD)
@@ -589,10 +645,10 @@ void Db::set_app_private(void *value)
unwrap(this)->app_private = value;
}
+DB_METHOD(get_cachesize, (u_int32_t *gbytesp, u_int32_t *bytesp, int *ncachep),
+ (db, gbytesp, bytesp, ncachep), DB_RETOK_STD)
DB_METHOD(set_cachesize, (u_int32_t gbytes, u_int32_t bytes, int ncache),
(db, gbytes, bytes, ncache), DB_RETOK_STD)
-DB_METHOD(set_cache_priority, (DB_CACHE_PRIORITY priority),
- (db, priority), DB_RETOK_STD)
int Db::set_paniccall(void (*callback)(DbEnv *, int))
{
diff --git a/db/cxx/cxx_dbc.cpp b/db/cxx/cxx_dbc.cpp
index 67ba544b3..9350c97e6 100644
--- a/db/cxx/cxx_dbc.cpp
+++ b/db/cxx/cxx_dbc.cpp
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997-2002
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "Id: cxx_dbc.cpp,v 11.55 2002/07/03 21:03:52 bostic Exp ";
+static const char revid[] = "$Id: cxx_dbc.cpp,v 11.58 2003/04/24 15:36:27 bostic Exp $";
#endif /* not lint */
#include <errno.h>
@@ -39,7 +39,8 @@ int Dbc::_name _argspec \
\
ret = dbc->c_##_name _arglist; \
if (!_retok(ret)) \
- DB_ERROR("Dbc::" # _name, ret, ON_ERROR_UNKNOWN); \
+ DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv), \
+ "Dbc::" # _name, ret, ON_ERROR_UNKNOWN); \
return (ret); \
}
@@ -67,7 +68,8 @@ int Dbc::dup(Dbc** cursorp, u_int32_t _flags)
// The following cast implies that Dbc can be no larger than DBC
*cursorp = (Dbc*)new_cursor;
else
- DB_ERROR("Dbc::dup", ret, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv),
+ "Dbc::dup", ret, ON_ERROR_UNKNOWN);
return (ret);
}
@@ -81,11 +83,14 @@ int Dbc::get(Dbt* key, Dbt *data, u_int32_t _flags)
if (!DB_RETOK_DBCGET(ret)) {
if (ret == ENOMEM && DB_OVERFLOWED_DBT(key))
- DB_ERROR_DBT("Dbc::get", key, ON_ERROR_UNKNOWN);
+ DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
+ "Dbc::get", key, ON_ERROR_UNKNOWN);
else if (ret == ENOMEM && DB_OVERFLOWED_DBT(data))
- DB_ERROR_DBT("Dbc::get", data, ON_ERROR_UNKNOWN);
+ DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
+ "Dbc::get", data, ON_ERROR_UNKNOWN);
else
- DB_ERROR("Dbc::get", ret, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv),
+ "Dbc::get", ret, ON_ERROR_UNKNOWN);
}
return (ret);
@@ -101,11 +106,14 @@ int Dbc::pget(Dbt* key, Dbt *pkey, Dbt *data, u_int32_t _flags)
/* Logic is the same as for Dbc::get - reusing macro. */
if (!DB_RETOK_DBCGET(ret)) {
if (ret == ENOMEM && DB_OVERFLOWED_DBT(key))
- DB_ERROR_DBT("Dbc::pget", key, ON_ERROR_UNKNOWN);
+ DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
+ "Dbc::pget", key, ON_ERROR_UNKNOWN);
else if (ret == ENOMEM && DB_OVERFLOWED_DBT(data))
- DB_ERROR_DBT("Dbc::pget", data, ON_ERROR_UNKNOWN);
+ DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
+ "Dbc::pget", data, ON_ERROR_UNKNOWN);
else
- DB_ERROR("Dbc::pget", ret, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv),
+ "Dbc::pget", ret, ON_ERROR_UNKNOWN);
}
return (ret);
diff --git a/db/cxx/cxx_dbt.cpp b/db/cxx/cxx_dbt.cpp
index e50e7e572..ab35f2f81 100644
--- a/db/cxx/cxx_dbt.cpp
+++ b/db/cxx/cxx_dbt.cpp
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997-2002
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "Id: cxx_dbt.cpp,v 11.53 2002/03/27 04:31:14 bostic Exp ";
+static const char revid[] = "$Id: cxx_dbt.cpp,v 11.54 2003/01/08 04:10:27 bostic Exp $";
#endif /* not lint */
#include <errno.h>
diff --git a/db/cxx/cxx_env.cpp b/db/cxx/cxx_env.cpp
index 63f665a2a..7917c06c1 100644
--- a/db/cxx/cxx_env.cpp
+++ b/db/cxx/cxx_env.cpp
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997-2002
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "Id: cxx_env.cpp,v 11.88 2002/08/26 22:13:36 mjc Exp ";
+static const char revid[] = "$Id: cxx_env.cpp,v 11.96 2003/06/30 19:17:48 mjc Exp $";
#endif /* not lint */
#include <errno.h>
@@ -45,7 +45,7 @@ int DbEnv::_name _argspec \
#define DBENV_METHOD(_name, _argspec, _arglist) \
DBENV_METHOD_ERR(_name, _argspec, _arglist, \
- DB_ERROR("DbEnv::" # _name, ret, error_policy()))
+ DB_ERROR(this, "DbEnv::" # _name, ret, error_policy()))
#define DBENV_METHOD_QUIET(_name, _argspec, _arglist) \
int DbEnv::_name _argspec \
@@ -115,26 +115,29 @@ int _app_dispatch_intercept_c(DB_ENV *env, DBT *dbt,
extern "C"
int _rep_send_intercept_c(DB_ENV *env, const DBT *cntrl,
- const DBT *data, int id, u_int32_t flags)
+ const DBT *data, const DB_LSN *lsn, int id,
+ u_int32_t flags)
{
return (DbEnv::_rep_send_intercept(env,
- cntrl, data, id, flags));
+ cntrl, data, lsn, id, flags));
}
void DbEnv::_feedback_intercept(DB_ENV *env, int opcode, int pct)
{
if (env == 0) {
- DB_ERROR("DbEnv::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
return;
}
DbEnv *cxxenv = (DbEnv *)env->api1_internal;
if (cxxenv == 0) {
- DB_ERROR("DbEnv::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
return;
}
if (cxxenv->feedback_callback_ == 0) {
- DB_ERROR("DbEnv::feedback_callback", EINVAL,
- cxxenv->error_policy());
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::feedback_callback", EINVAL, cxxenv->error_policy());
return;
}
(*cxxenv->feedback_callback_)(cxxenv, opcode, pct);
@@ -143,16 +146,17 @@ void DbEnv::_feedback_intercept(DB_ENV *env, int opcode, int pct)
void DbEnv::_paniccall_intercept(DB_ENV *env, int errval)
{
if (env == 0) {
- DB_ERROR("DbEnv::paniccall_callback", EINVAL,
- ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::paniccall_callback", EINVAL, ON_ERROR_UNKNOWN);
}
DbEnv *cxxenv = (DbEnv *)env->api1_internal;
if (cxxenv == 0) {
- DB_ERROR("DbEnv::paniccall_callback", EINVAL,
- ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::paniccall_callback", EINVAL, ON_ERROR_UNKNOWN);
}
if (cxxenv->paniccall_callback_ == 0) {
- DB_ERROR("DbEnv::paniccall_callback", EINVAL,
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::paniccall_callback", EINVAL,
cxxenv->error_policy());
}
(*cxxenv->paniccall_callback_)(cxxenv, errval);
@@ -162,19 +166,20 @@ int DbEnv::_app_dispatch_intercept(DB_ENV *env, DBT *dbt,
DB_LSN *lsn, db_recops op)
{
if (env == 0) {
- DB_ERROR("DbEnv::app_dispatch_callback",
- EINVAL, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::app_dispatch_callback", EINVAL, ON_ERROR_UNKNOWN);
return (EINVAL);
}
DbEnv *cxxenv = (DbEnv *)env->api1_internal;
if (cxxenv == 0) {
- DB_ERROR("DbEnv::app_dispatch_callback",
- EINVAL, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::app_dispatch_callback", EINVAL, ON_ERROR_UNKNOWN);
return (EINVAL);
}
if (cxxenv->app_dispatch_callback_ == 0) {
- DB_ERROR("DbEnv::app_dispatch_callback",
- EINVAL, cxxenv->error_policy());
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::app_dispatch_callback", EINVAL,
+ cxxenv->error_policy());
return (EINVAL);
}
Dbt *cxxdbt = (Dbt *)dbt;
@@ -183,22 +188,24 @@ int DbEnv::_app_dispatch_intercept(DB_ENV *env, DBT *dbt,
}
int DbEnv::_rep_send_intercept(DB_ENV *env, const DBT *cntrl,
- const DBT *data, int id, u_int32_t flags)
+ const DBT *data, const DB_LSN *lsn, int id, u_int32_t flags)
{
-
if (env == 0) {
- DB_ERROR("DbEnv::rep_send_callback", EINVAL, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::rep_send_callback", EINVAL, ON_ERROR_UNKNOWN);
return (EINVAL);
}
DbEnv *cxxenv = (DbEnv *)env->api1_internal;
if (cxxenv == 0) {
- DB_ERROR("DbEnv::rep_send_callback", EINVAL, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(env),
+ "DbEnv::rep_send_callback", EINVAL, ON_ERROR_UNKNOWN);
return (EINVAL);
}
const Dbt *cxxcntrl = (const Dbt *)cntrl;
+ const DbLsn *cxxlsn = (const DbLsn *)lsn;
Dbt *cxxdata = (Dbt *)data;
return ((*cxxenv->rep_send_callback_)(cxxenv,
- cxxcntrl, cxxdata, id, flags));
+ cxxcntrl, cxxdata, cxxlsn, id, flags));
}
// A truism for the DbEnv object is that there is a valid
@@ -225,7 +232,8 @@ DbEnv::DbEnv(u_int32_t flags)
, rep_send_callback_(0)
{
if ((construct_error_ = initialize(0)) != 0)
- DB_ERROR("DbEnv::DbEnv", construct_error_, error_policy());
+ DB_ERROR(this, "DbEnv::DbEnv", construct_error_,
+ error_policy());
}
DbEnv::DbEnv(DB_ENV *env, u_int32_t flags)
@@ -240,7 +248,8 @@ DbEnv::DbEnv(DB_ENV *env, u_int32_t flags)
, rep_send_callback_(0)
{
if ((construct_error_ = initialize(env)) != 0)
- DB_ERROR("DbEnv::DbEnv", construct_error_, error_policy());
+ DB_ERROR(this, "DbEnv::DbEnv", construct_error_,
+ error_policy());
}
// If the DB_ENV handle is still open, we close it. This is to make stack
@@ -287,7 +296,7 @@ int DbEnv::close(u_int32_t flags)
// the DB* structures.
//
if ((ret = env->close(env, flags)) != 0)
- DB_ERROR("DbEnv::close", ret, error_policy());
+ DB_ERROR(this, "DbEnv::close", ret, error_policy());
return (ret);
}
@@ -334,6 +343,10 @@ void *DbEnv::get_app_private() const
return unwrapConst(this)->app_private;
}
+DBENV_METHOD(get_home, (const char **homep), (dbenv, homep))
+DBENV_METHOD(get_open_flags, (u_int32_t *flagsp), (dbenv, flagsp))
+DBENV_METHOD(get_data_dirs, (const char ***dirspp), (dbenv, dirspp))
+
// used internally during constructor
// to associate an existing DB_ENV with this DbEnv,
// or create a new one.
@@ -362,7 +375,7 @@ DBENV_METHOD_ERR(lock_get,
(u_int32_t locker, u_int32_t flags, const Dbt *obj,
db_lockmode_t lock_mode, DbLock *lock),
(dbenv, locker, flags, obj, lock_mode, &lock->lock_),
- DbEnv::runtime_error_lock_get("DbEnv::lock_get", ret,
+ DbEnv::runtime_error_lock_get(this, "DbEnv::lock_get", ret,
DB_LOCK_GET, lock_mode, obj, *lock,
-1, error_policy()))
DBENV_METHOD(lock_id, (u_int32_t *idp), (dbenv, idp))
@@ -374,7 +387,7 @@ DBENV_METHOD_ERR(lock_vec,
(u_int32_t locker, u_int32_t flags, DB_LOCKREQ list[],
int nlist, DB_LOCKREQ **elist_returned),
(dbenv, locker, flags, list, nlist, elist_returned),
- DbEnv::runtime_error_lock_get("DbEnv::lock_vec", ret,
+ DbEnv::runtime_error_lock_get(this, "DbEnv::lock_vec", ret,
(*elist_returned)->op, (*elist_returned)->mode,
Dbt::get_Dbt((*elist_returned)->obj), DbLock((*elist_returned)->lock),
(*elist_returned) - list, error_policy()))
@@ -413,7 +426,7 @@ int DbEnv::memp_fcreate(DbMpoolFile **dbmfp, u_int32_t flags)
*dbmfp = new DbMpoolFile();
(*dbmfp)->imp_ = wrap(mpf);
} else
- DB_ERROR("DbMpoolFile::f_create", ret, ON_ERROR_UNKNOWN);
+ DB_ERROR(this, "DbMpoolFile::f_create", ret, ON_ERROR_UNKNOWN);
return (ret);
}
@@ -445,7 +458,7 @@ int DbEnv::open(const char *db_home, u_int32_t flags, int mode)
ret = env->open(env, db_home, flags, mode);
if (!DB_RETOK_STD(ret))
- DB_ERROR("DbEnv::open", ret, error_policy());
+ DB_ERROR(this, "DbEnv::open", ret, error_policy());
return (ret);
}
@@ -462,7 +475,7 @@ int DbEnv::remove(const char *db_home, u_int32_t flags)
cleanup();
if ((ret = env->remove(env, db_home, flags)) != 0)
- DB_ERROR("DbEnv::remove", ret, error_policy());
+ DB_ERROR(this, "DbEnv::remove", ret, error_policy());
return (ret);
}
@@ -473,7 +486,8 @@ int DbEnv::remove(const char *db_home, u_int32_t flags)
// ON_ERROR_RETURN do nothing here, the caller will return an error
// ON_ERROR_UNKNOWN defer the policy to policy saved in DbEnv::DbEnv
//
-void DbEnv::runtime_error(const char *caller, int error, int error_policy)
+void DbEnv::runtime_error(DbEnv *env,
+ const char *caller, int error, int error_policy)
{
if (error_policy == ON_ERROR_UNKNOWN)
error_policy = last_known_error_policy;
@@ -484,18 +498,28 @@ void DbEnv::runtime_error(const char *caller, int error, int error_policy)
case DB_LOCK_DEADLOCK:
{
DbDeadlockException dl_except(caller);
+ dl_except.set_env(env);
throw dl_except;
}
break;
case DB_RUNRECOVERY:
{
DbRunRecoveryException rr_except(caller);
+ rr_except.set_env(env);
throw rr_except;
}
break;
+ case DB_LOCK_NOTGRANTED:
+ {
+ DbLockNotGrantedException lng_except(caller);
+ lng_except.set_env(env);
+ throw lng_except;
+ }
+ break;
default:
{
DbException except(caller, error);
+ except.set_env(env);
throw except;
}
break;
@@ -505,7 +529,8 @@ void DbEnv::runtime_error(const char *caller, int error, int error_policy)
// Like DbEnv::runtime_error, but issue a DbMemoryException
// based on the fact that this Dbt is not large enough.
-void DbEnv::runtime_error_dbt(const char *caller, Dbt *dbt, int error_policy)
+void DbEnv::runtime_error_dbt(DbEnv *env,
+ const char *caller, Dbt *dbt, int error_policy)
{
if (error_policy == ON_ERROR_UNKNOWN)
error_policy = last_known_error_policy;
@@ -513,6 +538,7 @@ void DbEnv::runtime_error_dbt(const char *caller, Dbt *dbt, int error_policy)
// Creating and throwing the object in two separate
// statements seems to be necessary for HP compilers.
DbMemoryException except(caller, dbt);
+ except.set_env(env);
throw except;
}
}
@@ -520,12 +546,13 @@ void DbEnv::runtime_error_dbt(const char *caller, Dbt *dbt, int error_policy)
// Like DbEnv::runtime_error, but issue a DbLockNotGrantedException,
// or a regular runtime error.
// call regular runtime_error if it
-void DbEnv::runtime_error_lock_get(const char *caller, int error,
+void DbEnv::runtime_error_lock_get(DbEnv *env,
+ const char *caller, int error,
db_lockop_t op, db_lockmode_t mode, const Dbt *obj,
DbLock lock, int index, int error_policy)
{
if (error != DB_LOCK_NOTGRANTED) {
- runtime_error(caller, error, error_policy);
+ runtime_error(env, caller, error, error_policy);
return;
}
@@ -536,6 +563,7 @@ void DbEnv::runtime_error_lock_get(const char *caller, int error,
// statements seems to be necessary for HP compilers.
DbLockNotGrantedException except(caller, op, mode,
obj, lock, index);
+ except.set_env(env);
throw except;
}
}
@@ -562,26 +590,47 @@ void DbEnv::_stream_error_function(const char *prefix, char *message)
// set methods
+DBENV_METHOD_VOID(get_errfile, (FILE **errfilep), (dbenv, errfilep))
DBENV_METHOD_VOID(set_errfile, (FILE *errfile), (dbenv, errfile))
+DBENV_METHOD_VOID(get_errpfx, (const char **errpfxp), (dbenv, errpfxp))
DBENV_METHOD_VOID(set_errpfx, (const char *errpfx), (dbenv, errpfx))
// We keep these alphabetical by field name,
// for comparison with Java's list.
//
DBENV_METHOD(set_data_dir, (const char *dir), (dbenv, dir))
-DBENV_METHOD(set_encrypt, (const char *passwd, int flags),
+DBENV_METHOD(get_encrypt_flags, (u_int32_t *flagsp),
+ (dbenv, flagsp))
+DBENV_METHOD(set_encrypt, (const char *passwd, u_int32_t flags),
(dbenv, passwd, flags))
+DBENV_METHOD(get_lg_bsize, (u_int32_t *bsizep), (dbenv, bsizep))
DBENV_METHOD(set_lg_bsize, (u_int32_t bsize), (dbenv, bsize))
+DBENV_METHOD(get_lg_dir, (const char **dirp), (dbenv, dirp))
DBENV_METHOD(set_lg_dir, (const char *dir), (dbenv, dir))
+DBENV_METHOD(get_lg_max, (u_int32_t *maxp), (dbenv, maxp))
DBENV_METHOD(set_lg_max, (u_int32_t max), (dbenv, max))
+DBENV_METHOD(get_lg_regionmax, (u_int32_t *regionmaxp), (dbenv, regionmaxp))
DBENV_METHOD(set_lg_regionmax, (u_int32_t regionmax), (dbenv, regionmax))
+DBENV_METHOD(get_lk_conflicts, (const u_int8_t **lk_conflictsp, int *lk_maxp),
+ (dbenv, lk_conflictsp, lk_maxp))
+DBENV_METHOD(set_lk_conflicts, (u_int8_t *lk_conflicts, int lk_max),
+ (dbenv, lk_conflicts, lk_max))
+DBENV_METHOD(get_lk_detect, (u_int32_t *detectp), (dbenv, detectp))
DBENV_METHOD(set_lk_detect, (u_int32_t detect), (dbenv, detect))
DBENV_METHOD(set_lk_max, (u_int32_t max), (dbenv, max))
+DBENV_METHOD(get_lk_max_lockers, (u_int32_t *max_lockersp),
+ (dbenv, max_lockersp))
DBENV_METHOD(set_lk_max_lockers, (u_int32_t max_lockers), (dbenv, max_lockers))
+DBENV_METHOD(get_lk_max_locks, (u_int32_t *max_locksp), (dbenv, max_locksp))
DBENV_METHOD(set_lk_max_locks, (u_int32_t max_locks), (dbenv, max_locks))
+DBENV_METHOD(get_lk_max_objects, (u_int32_t *max_objectsp),
+ (dbenv, max_objectsp))
DBENV_METHOD(set_lk_max_objects, (u_int32_t max_objects), (dbenv, max_objects))
+DBENV_METHOD(get_mp_mmapsize, (size_t *mmapsizep), (dbenv, mmapsizep))
DBENV_METHOD(set_mp_mmapsize, (size_t mmapsize), (dbenv, mmapsize))
+DBENV_METHOD(get_tmp_dir, (const char **tmp_dirp), (dbenv, tmp_dirp))
DBENV_METHOD(set_tmp_dir, (const char *tmp_dir), (dbenv, tmp_dir))
+DBENV_METHOD(get_tx_max, (u_int32_t *tx_maxp), (dbenv, tx_maxp))
DBENV_METHOD(set_tx_max, (u_int32_t tx_max), (dbenv, tx_max))
DBENV_METHOD_QUIET(set_alloc,
@@ -594,6 +643,9 @@ void DbEnv::set_app_private(void *value)
unwrap(this)->app_private = value;
}
+DBENV_METHOD(get_cachesize,
+ (u_int32_t *gbytesp, u_int32_t *bytesp, int *ncachep),
+ (dbenv, gbytesp, bytesp, ncachep))
DBENV_METHOD(set_cachesize,
(u_int32_t gbytes, u_int32_t bytes, int ncache),
(dbenv, gbytes, bytes, ncache))
@@ -641,9 +693,8 @@ int DbEnv::set_feedback(void (*arg)(DbEnv *, int, int))
return ((*(dbenv->set_feedback))(dbenv, _feedback_intercept_c));
}
+DBENV_METHOD(get_flags, (u_int32_t *flagsp), (dbenv, flagsp))
DBENV_METHOD(set_flags, (u_int32_t flags, int onoff), (dbenv, flags, onoff))
-DBENV_METHOD(set_lk_conflicts, (u_int8_t *lk_conflicts, int lk_max),
- (dbenv, lk_conflicts, lk_max))
int DbEnv::set_paniccall(void (*arg)(DbEnv *, int))
{
@@ -657,8 +708,10 @@ int DbEnv::set_paniccall(void (*arg)(DbEnv *, int))
DBENV_METHOD(set_rpc_server,
(void *cl, char *host, long tsec, long ssec, u_int32_t flags),
(dbenv, cl, host, tsec, ssec, flags))
+DBENV_METHOD(get_shm_key, (long *shm_keyp), (dbenv, shm_keyp))
DBENV_METHOD(set_shm_key, (long shm_key), (dbenv, shm_key))
// Note: this changes from last_known_error_policy to error_policy()
+DBENV_METHOD(get_tas_spins, (u_int32_t *argp), (dbenv, argp))
DBENV_METHOD(set_tas_spins, (u_int32_t arg), (dbenv, arg))
int DbEnv::set_app_dispatch
@@ -670,12 +723,15 @@ int DbEnv::set_app_dispatch
app_dispatch_callback_ = arg;
if ((ret = (*(dbenv->set_app_dispatch))(dbenv,
_app_dispatch_intercept_c)) != 0)
- DB_ERROR("DbEnv::set_app_dispatch", ret, error_policy());
+ DB_ERROR(this, "DbEnv::set_app_dispatch", ret, error_policy());
return (ret);
}
+DBENV_METHOD(get_tx_timestamp, (time_t *timestamp), (dbenv, timestamp))
DBENV_METHOD(set_tx_timestamp, (time_t *timestamp), (dbenv, timestamp))
+DBENV_METHOD(get_verbose, (u_int32_t which, int *onoffp),
+ (dbenv, which, onoffp))
DBENV_METHOD(set_verbose, (u_int32_t which, int onoff), (dbenv, which, onoff))
int DbEnv::txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags)
@@ -688,7 +744,7 @@ int DbEnv::txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags)
if (DB_RETOK_STD(ret))
*tid = new DbTxn(txn);
else
- DB_ERROR("DbEnv::txn_begin", ret, error_policy());
+ DB_ERROR(this, "DbEnv::txn_begin", ret, error_policy());
return (ret);
}
@@ -716,14 +772,14 @@ int DbEnv::txn_recover(DbPreplist *preplist, long count,
&c_preplist);
if (ret != 0) {
- DB_ERROR("DbEnv::txn_recover", ret, error_policy());
+ DB_ERROR(this, "DbEnv::txn_recover", ret, error_policy());
return (ret);
}
if ((ret =
dbenv->txn_recover(dbenv, c_preplist, count, retp, flags)) != 0) {
__os_free(dbenv, c_preplist);
- DB_ERROR("DbEnv::txn_recover", ret, error_policy());
+ DB_ERROR(this, "DbEnv::txn_recover", ret, error_policy());
return (ret);
}
@@ -742,8 +798,9 @@ int DbEnv::txn_recover(DbPreplist *preplist, long count,
DBENV_METHOD(txn_stat, (DB_TXN_STAT **statp, u_int32_t flags),
(dbenv, statp, flags))
-int DbEnv::set_rep_transport(u_int32_t myid,
- int (*f_send)(DbEnv *, const Dbt *, const Dbt *, int, u_int32_t))
+int DbEnv::set_rep_transport(int myid,
+ int (*f_send)(DbEnv *, const Dbt *, const Dbt *, const DbLsn *, int,
+ u_int32_t))
{
DB_ENV *dbenv = unwrap(this);
int ret;
@@ -751,7 +808,7 @@ int DbEnv::set_rep_transport(u_int32_t myid,
rep_send_callback_ = f_send;
if ((ret = dbenv->set_rep_transport(dbenv,
myid, _rep_send_intercept_c)) != 0)
- DB_ERROR("DbEnv::set_rep_transport", ret, error_policy());
+ DB_ERROR(this, "DbEnv::set_rep_transport", ret, error_policy());
return (ret);
}
@@ -760,14 +817,16 @@ DBENV_METHOD(rep_elect,
(int nsites, int pri, u_int32_t timeout, int *idp),
(dbenv, nsites, pri, timeout, idp))
-int DbEnv::rep_process_message(Dbt *control, Dbt *rec, int *idp)
+int DbEnv::rep_process_message(Dbt *control,
+ Dbt *rec, int *idp, DbLsn *ret_lsnp)
{
DB_ENV *dbenv = unwrap(this);
int ret;
- ret = dbenv->rep_process_message(dbenv, control, rec, idp);
+ ret = dbenv->rep_process_message(dbenv, control, rec, idp, ret_lsnp);
if (!DB_RETOK_REPPMSG(ret))
- DB_ERROR("DbEnv::rep_process_message", ret, error_policy());
+ DB_ERROR(this, "DbEnv::rep_process_message", ret,
+ error_policy());
return (ret);
}
@@ -779,9 +838,14 @@ DBENV_METHOD(rep_start,
DBENV_METHOD(rep_stat, (DB_REP_STAT **statp, u_int32_t flags),
(dbenv, statp, flags))
+DBENV_METHOD(get_rep_limit, (u_int32_t *gbytesp, u_int32_t *bytesp),
+ (dbenv, gbytesp, bytesp))
DBENV_METHOD(set_rep_limit, (u_int32_t gbytes, u_int32_t bytes),
(dbenv, gbytes, bytes))
+DBENV_METHOD(get_timeout,
+ (db_timeout_t *timeoutp, u_int32_t flags),
+ (dbenv, timeoutp, flags))
DBENV_METHOD(set_timeout,
(db_timeout_t timeout, u_int32_t flags),
(dbenv, timeout, flags))
diff --git a/db/cxx/cxx_except.cpp b/db/cxx/cxx_except.cpp
index a62e21a76..2710af30b 100644
--- a/db/cxx/cxx_except.cpp
+++ b/db/cxx/cxx_except.cpp
@@ -1,20 +1,21 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: cxx_except.cpp,v 11.7 2000/09/21 15:05:45 dda Exp $";
+static const char revid[] = "$Id: cxx_except.cpp,v 11.21 2003/05/19 15:38:51 mjc Exp $";
#endif /* not lint */
#include <string.h>
+#include <errno.h>
#include "db_cxx.h"
-#include "cxx_int.h"
+#include "dbinc/cxx_int.h"
// tmpString is used to create strings on the stack
//
@@ -25,30 +26,7 @@ public:
const char *str2 = 0,
const char *str3 = 0,
const char *str4 = 0,
- const char *str5 = 0)
- {
- int len = strlen(str1);
- if (str2)
- len += strlen(str2);
- if (str3)
- len += strlen(str3);
- if (str4)
- len += strlen(str4);
- if (str5)
- len += strlen(str5);
-
- s_ = new char[len+1];
-
- strcpy(s_, str1);
- if (str2)
- strcat(s_, str2);
- if (str3)
- strcat(s_, str3);
- if (str4)
- strcat(s_, str4);
- if (str5)
- strcat(s_, str5);
- }
+ const char *str5 = 0);
~tmpString() { delete [] s_; }
operator const char *() { return (s_); }
@@ -56,6 +34,35 @@ private:
char *s_;
};
+tmpString::tmpString(const char *str1,
+ const char *str2,
+ const char *str3,
+ const char *str4,
+ const char *str5)
+{
+ size_t len = strlen(str1);
+ if (str2)
+ len += strlen(str2);
+ if (str3)
+ len += strlen(str3);
+ if (str4)
+ len += strlen(str4);
+ if (str5)
+ len += strlen(str5);
+
+ s_ = new char[len+1];
+
+ strcpy(s_, str1);
+ if (str2)
+ strcat(s_, str2);
+ if (str3)
+ strcat(s_, str3);
+ if (str4)
+ strcat(s_, str4);
+ if (str5)
+ strcat(s_, str5);
+}
+
// Note: would not be needed if we can inherit from exception
// It does not appear to be possible to inherit from exception
// with the current Microsoft library (VC5.0).
@@ -81,30 +88,36 @@ DbException::~DbException()
DbException::DbException(int err)
: err_(err)
+, env_(0)
{
what_ = dupString(db_strerror(err));
}
DbException::DbException(const char *description)
: err_(0)
+, env_(0)
{
what_ = dupString(tmpString(description));
}
DbException::DbException(const char *prefix, int err)
: err_(err)
+, env_(0)
{
what_ = dupString(tmpString(prefix, ": ", db_strerror(err)));
}
DbException::DbException(const char *prefix1, const char *prefix2, int err)
: err_(err)
+, env_(0)
{
- what_ = dupString(tmpString(prefix1, ": ", prefix2, ": ", db_strerror(err)));
+ what_ = dupString(tmpString(prefix1, ": ", prefix2, ": ",
+ db_strerror(err)));
}
DbException::DbException(const DbException &that)
: err_(that.err_)
+, env_(0)
{
what_ = dupString(that.what_);
}
@@ -130,3 +143,206 @@ const char *DbException::what() const
{
return (what_);
}
+
+DbEnv *DbException::get_env() const
+{
+ return env_;
+}
+
+void DbException::set_env(DbEnv *env)
+{
+ env_= env;
+}
+
+////////////////////////////////////////////////////////////////////////
+// //
+// DbMemoryException //
+// //
+////////////////////////////////////////////////////////////////////////
+
+static const char *memory_err_desc = "Dbt not large enough for available data";
+DbMemoryException::~DbMemoryException()
+{
+}
+
+DbMemoryException::DbMemoryException(Dbt *dbt)
+: DbException(memory_err_desc, ENOMEM)
+, dbt_(dbt)
+{
+}
+
+DbMemoryException::DbMemoryException(const char *description)
+: DbException(description, ENOMEM)
+, dbt_(0)
+{
+}
+
+DbMemoryException::DbMemoryException(const char *prefix, Dbt *dbt)
+: DbException(prefix, memory_err_desc, ENOMEM)
+, dbt_(dbt)
+{
+}
+
+DbMemoryException::DbMemoryException(const char *prefix1, const char *prefix2,
+ Dbt *dbt)
+: DbException(prefix1, prefix2, ENOMEM)
+, dbt_(dbt)
+{
+}
+
+DbMemoryException::DbMemoryException(const DbMemoryException &that)
+: DbException(that)
+, dbt_(that.dbt_)
+{
+}
+
+DbMemoryException
+&DbMemoryException::operator =(const DbMemoryException &that)
+{
+ if (this != &that) {
+ DbException::operator=(that);
+ dbt_ = that.dbt_;
+ }
+ return (*this);
+}
+
+Dbt *DbMemoryException::get_dbt() const
+{
+ return (dbt_);
+}
+
+////////////////////////////////////////////////////////////////////////
+// //
+// DbDeadlockException //
+// //
+////////////////////////////////////////////////////////////////////////
+
+DbDeadlockException::~DbDeadlockException()
+{
+}
+
+DbDeadlockException::DbDeadlockException(const char *description)
+: DbException(description, DB_LOCK_DEADLOCK)
+{
+}
+
+DbDeadlockException::DbDeadlockException(const DbDeadlockException &that)
+: DbException(that)
+{
+}
+
+DbDeadlockException
+&DbDeadlockException::operator =(const DbDeadlockException &that)
+{
+ if (this != &that)
+ DbException::operator=(that);
+ return (*this);
+}
+
+////////////////////////////////////////////////////////////////////////
+// //
+// DbLockNotGrantedException //
+// //
+////////////////////////////////////////////////////////////////////////
+
+DbLockNotGrantedException::~DbLockNotGrantedException()
+{
+ delete lock_;
+}
+
+DbLockNotGrantedException::DbLockNotGrantedException(const char *prefix,
+ db_lockop_t op, db_lockmode_t mode, const Dbt *obj, const DbLock lock,
+ int index)
+: DbException(prefix, DbEnv::strerror(DB_LOCK_NOTGRANTED),
+ DB_LOCK_NOTGRANTED)
+, op_(op)
+, mode_(mode)
+, obj_(obj)
+, index_(index)
+{
+ lock_ = new DbLock(lock);
+}
+
+DbLockNotGrantedException::DbLockNotGrantedException(const char *description)
+: DbException(description, DB_LOCK_NOTGRANTED)
+{
+}
+
+DbLockNotGrantedException::DbLockNotGrantedException
+ (const DbLockNotGrantedException &that)
+: DbException(that)
+{
+ op_ = that.op_;
+ mode_ = that.mode_;
+ obj_ = that.obj_;
+ lock_ = new DbLock(*that.lock_);
+ index_ = that.index_;
+}
+
+DbLockNotGrantedException
+&DbLockNotGrantedException::operator =(const DbLockNotGrantedException &that)
+{
+ if (this != &that) {
+ DbException::operator=(that);
+ op_ = that.op_;
+ mode_ = that.mode_;
+ obj_ = that.obj_;
+ lock_ = new DbLock(*that.lock_);
+ index_ = that.index_;
+ }
+ return (*this);
+}
+
+db_lockop_t DbLockNotGrantedException::get_op() const
+{
+ return op_;
+}
+
+db_lockmode_t DbLockNotGrantedException::get_mode() const
+{
+ return mode_;
+}
+
+const Dbt* DbLockNotGrantedException::get_obj() const
+{
+ return obj_;
+}
+
+DbLock* DbLockNotGrantedException::get_lock() const
+{
+ return lock_;
+}
+
+int DbLockNotGrantedException::get_index() const
+{
+ return index_;
+}
+
+////////////////////////////////////////////////////////////////////////
+// //
+// DbRunRecoveryException //
+// //
+////////////////////////////////////////////////////////////////////////
+
+DbRunRecoveryException::~DbRunRecoveryException()
+{
+}
+
+DbRunRecoveryException::DbRunRecoveryException(const char *description)
+: DbException(description, DB_RUNRECOVERY)
+{
+}
+
+DbRunRecoveryException::DbRunRecoveryException
+ (const DbRunRecoveryException &that)
+: DbException(that)
+{
+}
+
+DbRunRecoveryException
+&DbRunRecoveryException::operator =(const DbRunRecoveryException &that)
+{
+ if (this != &that)
+ DbException::operator=(that);
+ return (*this);
+}
diff --git a/db/cxx/cxx_lock.cpp b/db/cxx/cxx_lock.cpp
index e8ce2aa9d..602c7409b 100644
--- a/db/cxx/cxx_lock.cpp
+++ b/db/cxx/cxx_lock.cpp
@@ -1,86 +1,21 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: cxx_lock.cpp,v 11.9 2000/09/21 15:05:45 dda Exp $";
+static const char revid[] = "$Id: cxx_lock.cpp,v 11.18 2003/01/08 04:10:36 bostic Exp $";
#endif /* not lint */
#include <errno.h>
#include <string.h>
#include "db_cxx.h"
-#include "cxx_int.h"
-
-int DbEnv::lock_detect(u_int32_t flags, u_int32_t atype, int *aborted)
-{
- DB_ENV *env = unwrap(this);
- int err;
-
- if ((err = ::lock_detect(env, flags, atype, aborted)) != 0) {
- DB_ERROR("DbEnv::lock_detect", err, error_policy());
- return (err);
- }
- return (err);
-}
-
-int DbEnv::lock_get(u_int32_t locker, u_int32_t flags, const Dbt *obj,
- db_lockmode_t lock_mode, DbLock *lock)
-{
- DB_ENV *env = unwrap(this);
- int err;
-
- if ((err = ::lock_get(env, locker, flags, obj,
- lock_mode, &lock->lock_)) != 0) {
- DB_ERROR("DbEnv::lock_get", err, error_policy());
- return (err);
- }
- return (err);
-}
-
-int DbEnv::lock_id(u_int32_t *idp)
-{
- DB_ENV *env = unwrap(this);
- int err;
-
- if ((err = ::lock_id(env, idp)) != 0) {
- DB_ERROR("DbEnv::lock_id", err, error_policy());
- }
- return (err);
-}
-
-int DbEnv::lock_stat(DB_LOCK_STAT **statp,
- db_malloc_fcn_type db_malloc_fcn)
-{
- DB_ENV *env = unwrap(this);
- int err;
-
- if ((err = ::lock_stat(env, statp, db_malloc_fcn)) != 0) {
- DB_ERROR("DbEnv::lock_stat", err, error_policy());
- return (err);
- }
- return (0);
-}
-
-int DbEnv::lock_vec(u_int32_t locker, u_int32_t flags,
- DB_LOCKREQ list[],
- int nlist, DB_LOCKREQ **elist_returned)
-{
- DB_ENV *env = unwrap(this);
- int err;
-
- if ((err = ::lock_vec(env, locker, flags, list,
- nlist, elist_returned)) != 0) {
- DB_ERROR("DbEnv::lock_vec", err, error_policy());
- return (err);
- }
- return (err);
-}
+#include "dbinc/cxx_int.h"
////////////////////////////////////////////////////////////////////////
// //
@@ -108,18 +43,3 @@ DbLock &DbLock::operator = (const DbLock &that)
lock_ = that.lock_;
return (*this);
}
-
-int DbLock::put(DbEnv *env)
-{
- DB_ENV *envp = unwrap(env);
-
- if (!env) {
- return (EINVAL); // handle never assigned
- }
-
- int err;
- if ((err = lock_put(envp, &lock_)) != 0) {
- DB_ERROR("DbLock::put", err, env->error_policy());
- }
- return (err);
-}
diff --git a/db/cxx/cxx_logc.cpp b/db/cxx/cxx_logc.cpp
index 8bb70c1dc..0a7fdaca1 100644
--- a/db/cxx/cxx_logc.cpp
+++ b/db/cxx/cxx_logc.cpp
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997-2002
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "Id: cxx_logc.cpp,v 11.8 2002/07/03 21:03:53 bostic Exp ";
+static const char revid[] = "$Id: cxx_logc.cpp,v 11.11 2003/03/27 20:05:04 merrells Exp $";
#endif /* not lint */
#include <errno.h>
@@ -37,11 +37,12 @@ int DbLogc::close(u_int32_t _flags)
{
DB_LOGC *logc = this;
int ret;
+ DbEnv *dbenv2 = DbEnv::get_DbEnv(logc->dbenv);
ret = logc->close(logc, _flags);
if (!DB_RETOK_STD(ret))
- DB_ERROR("DbLogc::close", ret, ON_ERROR_UNKNOWN);
+ DB_ERROR(dbenv2, "DbLogc::close", ret, ON_ERROR_UNKNOWN);
return (ret);
}
@@ -56,9 +57,11 @@ int DbLogc::get(DbLsn *lsn, Dbt *data, u_int32_t _flags)
if (!DB_RETOK_LGGET(ret)) {
if (ret == ENOMEM && DB_OVERFLOWED_DBT(data))
- DB_ERROR_DBT("DbLogc::get", data, ON_ERROR_UNKNOWN);
+ DB_ERROR_DBT(DbEnv::get_DbEnv(logc->dbenv),
+ "DbLogc::get", data, ON_ERROR_UNKNOWN);
else
- DB_ERROR("DbLogc::get", ret, ON_ERROR_UNKNOWN);
+ DB_ERROR(DbEnv::get_DbEnv(logc->dbenv),
+ "DbLogc::get", ret, ON_ERROR_UNKNOWN);
}
return (ret);
diff --git a/db/cxx/cxx_mpool.cpp b/db/cxx/cxx_mpool.cpp
index 22f4735e3..6ef491e0f 100644
--- a/db/cxx/cxx_mpool.cpp
+++ b/db/cxx/cxx_mpool.cpp
@@ -1,20 +1,52 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: cxx_mpool.cpp,v 11.11 2000/09/21 15:05:45 dda Exp $";
+static const char revid[] = "$Id: cxx_mpool.cpp,v 11.27 2003/06/30 17:19:41 bostic Exp $";
#endif /* not lint */
#include <errno.h>
#include "db_cxx.h"
-#include "cxx_int.h"
+#include "dbinc/cxx_int.h"
+
+#include "db_int.h"
+
+// Helper macros for simple methods that pass through to the
+// underlying C method. It may return an error or raise an exception.
+// Note this macro expects that input _argspec is an argument
+// list element (e.g., "char *arg") and that _arglist is the arguments
+// that should be passed through to the C method (e.g., "(mpf, arg)")
+//
+#define DB_MPOOLFILE_METHOD(_name, _argspec, _arglist, _retok) \
+int DbMpoolFile::_name _argspec \
+{ \
+ int ret; \
+ DB_MPOOLFILE *mpf = unwrap(this); \
+ \
+ if (mpf == NULL) \
+ ret = EINVAL; \
+ else \
+ ret = mpf->_name _arglist; \
+ if (!_retok(ret)) \
+ DB_ERROR(DbEnv::get_DbEnv(mpf->dbenv), \
+ "DbMpoolFile::"#_name, ret, ON_ERROR_UNKNOWN); \
+ return (ret); \
+}
+
+#define DB_MPOOLFILE_METHOD_VOID(_name, _argspec, _arglist) \
+void DbMpoolFile::_name _argspec \
+{ \
+ DB_MPOOLFILE *mpf = unwrap(this); \
+ \
+ mpf->_name _arglist; \
+}
////////////////////////////////////////////////////////////////////////
// //
@@ -31,150 +63,69 @@ DbMpoolFile::~DbMpoolFile()
{
}
-int DbMpoolFile::open(DbEnv *envp, const char *file,
- u_int32_t flags, int mode, size_t pagesize,
- DB_MPOOL_FINFO *finfop, DbMpoolFile **result)
-{
- int err;
-
- DB_MPOOLFILE *mpf;
- DB_ENV *env = unwrap(envp);
-
- if ((err = ::memp_fopen(env, file, flags, mode, pagesize,
- finfop, &mpf)) != 0) {
- DB_ERROR("DbMpoolFile::open", err, envp->error_policy());
- return (err);
- }
- *result = new DbMpoolFile();
- (*result)->imp_ = wrap(mpf);
- return (0);
-}
-
-int DbMpoolFile::close()
+int DbMpoolFile::close(u_int32_t flags)
{
DB_MPOOLFILE *mpf = unwrap(this);
- int err = 0;
- if (!mpf) {
- err = EINVAL;
- }
- else if ((err = ::memp_fclose(mpf)) != 0) {
- DB_ERROR("DbMpoolFile::close", err, ON_ERROR_UNKNOWN);
- return (err);
- }
+ int ret;
+ DbEnv *dbenv = DbEnv::get_DbEnv(mpf->dbenv);
+
+ if (mpf == NULL)
+ ret = EINVAL;
+ else
+ ret = mpf->close(mpf, flags);
+
imp_ = 0; // extra safety
// This may seem weird, but is legal as long as we don't access
// any data before returning.
- //
delete this;
- return (0);
-}
-
-int DbMpoolFile::get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep)
-{
- DB_MPOOLFILE *mpf = unwrap(this);
- int err = 0;
- if (!mpf) {
- err = EINVAL;
- }
- else if ((err = ::memp_fget(mpf, pgnoaddr, flags, pagep)) != 0) {
- DB_ERROR("DbMpoolFile::get", err, ON_ERROR_UNKNOWN);
- }
- return (err);
-}
-
-int DbMpoolFile::put(void *pgaddr, u_int32_t flags)
-{
- DB_MPOOLFILE *mpf = unwrap(this);
- int err = 0;
- if (!mpf) {
- err = EINVAL;
- }
- else if ((err = ::memp_fput(mpf, pgaddr, flags)) != 0) {
- DB_ERROR("DbMpoolFile::put", err, ON_ERROR_UNKNOWN);
- }
- return (err);
-}
-
-int DbMpoolFile::set(void *pgaddr, u_int32_t flags)
-{
- DB_MPOOLFILE *mpf = unwrap(this);
- int err = 0;
- if (!mpf) {
- err = EINVAL;
- }
- else if ((err = ::memp_fset(mpf, pgaddr, flags)) != 0) {
- DB_ERROR("DbMpoolFile::set", err, ON_ERROR_UNKNOWN);
- }
- return (err);
-}
-
-int DbMpoolFile::sync()
-{
- DB_MPOOLFILE *mpf = unwrap(this);
- int err = 0;
- if (!mpf) {
- err = EINVAL;
- }
- else if ((err = ::memp_fsync(mpf)) != 0 && err != DB_INCOMPLETE) {
- DB_ERROR("DbMpoolFile::sync", err, ON_ERROR_UNKNOWN);
- }
- return (err);
-}
-////////////////////////////////////////////////////////////////////////
-// //
-// DbMpool //
-// //
-////////////////////////////////////////////////////////////////////////
+ if (!DB_RETOK_STD(ret))
+ DB_ERROR(dbenv, "DbMpoolFile::close", ret, ON_ERROR_UNKNOWN);
-int DbEnv::memp_register(int ftype,
- pgin_fcn_type pgin_fcn,
- pgout_fcn_type pgout_fcn)
-{
- DB_ENV *env = unwrap(this);
- int err = 0;
-
- if ((err = ::memp_register(env, ftype, pgin_fcn, pgout_fcn)) != 0) {
- DB_ERROR("DbEnv::memp_register", err, error_policy());
- return (err);
- }
- return (err);
+ return (ret);
}
-int DbEnv::memp_stat(DB_MPOOL_STAT **gsp, DB_MPOOL_FSTAT ***fsp,
- db_malloc_fcn_type db_malloc_fcn)
-{
- DB_ENV *env = unwrap(this);
- int err = 0;
-
- if ((err = ::memp_stat(env, gsp, fsp, db_malloc_fcn)) != 0) {
- DB_ERROR("DbEnv::memp_stat", err, error_policy());
- return (err);
- }
- return (err);
-}
-
-int DbEnv::memp_sync(DbLsn *sn)
-{
- DB_ENV *env = unwrap(this);
- int err = 0;
-
- if ((err = ::memp_sync(env, sn)) != 0 && err != DB_INCOMPLETE) {
- DB_ERROR("DbEnv::memp_sync", err, error_policy());
- return (err);
- }
- return (err);
-}
-
-int DbEnv::memp_trickle(int pct, int *nwrotep)
-{
- DB_ENV *env = unwrap(this);
- int err = 0;
-
- if ((err = ::memp_trickle(env, pct, nwrotep)) != 0) {
- DB_ERROR("DbEnv::memp_trickle", err, error_policy());
- return (err);
- }
- return (err);
-}
+DB_MPOOLFILE_METHOD(get, (db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep),
+ (mpf, pgnoaddr, flags, pagep), DB_RETOK_MPGET)
+DB_MPOOLFILE_METHOD(open,
+ (const char *file, u_int32_t flags, int mode, size_t pagesize),
+ (mpf, file, flags, mode, pagesize), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(put, (void *pgaddr, u_int32_t flags),
+ (mpf, pgaddr, flags), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set, (void *pgaddr, u_int32_t flags),
+ (mpf, pgaddr, flags), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_clear_len, (u_int32_t *lenp),
+ (mpf, lenp), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_clear_len, (u_int32_t len),
+ (mpf, len), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_fileid, (u_int8_t *fileid),
+ (mpf, fileid), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_fileid, (u_int8_t *fileid),
+ (mpf, fileid), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_flags, (u_int32_t *flagsp),
+ (mpf, flagsp), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_flags, (u_int32_t flags, int onoff),
+ (mpf, flags, onoff), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_ftype, (int *ftypep),
+ (mpf, ftypep), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_ftype, (int ftype),
+ (mpf, ftype), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_lsn_offset, (int32_t *offsetp),
+ (mpf, offsetp), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_lsn_offset, (int32_t offset),
+ (mpf, offset), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_maxsize, (u_int32_t *gbytesp, u_int32_t *bytesp),
+ (mpf, gbytesp, bytesp), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_maxsize, (u_int32_t gbytes, u_int32_t bytes),
+ (mpf, gbytes, bytes), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_pgcookie, (DBT *dbt),
+ (mpf, dbt), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_pgcookie, (DBT *dbt),
+ (mpf, dbt), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(get_priority, (DB_CACHE_PRIORITY *priorityp),
+ (mpf, priorityp), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(set_priority, (DB_CACHE_PRIORITY priority),
+ (mpf, priority), DB_RETOK_STD)
+DB_MPOOLFILE_METHOD(sync, (),
+ (mpf), DB_RETOK_STD)
diff --git a/db/cxx/cxx_multi.cpp b/db/cxx/cxx_multi.cpp
new file mode 100644
index 000000000..be6287a3c
--- /dev/null
+++ b/db/cxx/cxx_multi.cpp
@@ -0,0 +1,67 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997-2003
+ * Sleepycat Software. All rights reserved.
+ */
+
+#include "db_config.h"
+
+#ifndef lint
+static const char revid[] = "$Id: cxx_multi.cpp,v 1.3 2003/02/22 01:25:43 merrells Exp $";
+#endif /* not lint */
+
+#include "db_cxx.h"
+
+DbMultipleIterator::DbMultipleIterator(const Dbt &dbt)
+ : data_((u_int8_t*)dbt.get_data()),
+ p_((u_int32_t*)(data_ + dbt.get_size() - sizeof(u_int32_t)))
+{
+}
+
+bool DbMultipleDataIterator::next(Dbt &data)
+{
+ if (*p_ == (u_int32_t)-1) {
+ data.set_data(0);
+ data.set_size(0);
+ p_ = 0;
+ } else {
+ data.set_data(data_ + *p_--);
+ data.set_size(*p_--);
+ if (data.get_size() == 0 && data.get_data() == data_)
+ data.set_data(0);
+ }
+ return (data.get_data() != 0);
+}
+
+bool DbMultipleKeyDataIterator::next(Dbt &key, Dbt &data)
+{
+ if (*p_ == (u_int32_t)-1) {
+ key.set_data(0);
+ key.set_size(0);
+ data.set_data(0);
+ data.set_size(0);
+ p_ = 0;
+ } else {
+ key.set_data(data_ + *p_--);
+ key.set_size(*p_--);
+ data.set_data(data_ + *p_--);
+ data.set_size(*p_--);
+ }
+ return (data.get_data() != 0);
+}
+
+bool DbMultipleRecnoDataIterator::next(db_recno_t &recno, Dbt &data)
+{
+ if (*p_ == (u_int32_t)0) {
+ recno = 0;
+ data.set_data(0);
+ data.set_size(0);
+ p_ = 0;
+ } else {
+ recno = *p_--;
+ data.set_data(data_ + *p_--);
+ data.set_size(*p_--);
+ }
+ return (recno != 0);
+}
diff --git a/db/cxx/cxx_txn.cpp b/db/cxx/cxx_txn.cpp
index 0abae9826..9db1c9fb9 100644
--- a/db/cxx/cxx_txn.cpp
+++ b/db/cxx/cxx_txn.cpp
@@ -1,136 +1,83 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: cxx_txn.cpp,v 11.13 2000/12/21 16:24:33 dda Exp $";
+static const char revid[] = "$Id: cxx_txn.cpp,v 11.29 2003/03/11 15:39:40 merrells Exp $";
#endif /* not lint */
#include <errno.h>
#include "db_cxx.h"
-#include "cxx_int.h"
-
-////////////////////////////////////////////////////////////////////////
-// //
-// DbTxnMgr //
-// //
-////////////////////////////////////////////////////////////////////////
-
-int DbEnv::txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags)
-{
- int err;
- DB_ENV *env = unwrap(this);
- DB_TXN *txn;
-
- if ((err = ::txn_begin(env, unwrap(pid), &txn, flags)) != 0) {
- DB_ERROR("DbEnv::txn_begin", err, error_policy());
- return (err);
- }
- DbTxn *result = new DbTxn();
- result->imp_ = wrap(txn);
- *tid = result;
- return (err);
-}
-
-int DbEnv::txn_checkpoint(u_int32_t kbyte, u_int32_t min, u_int32_t flags)
-{
- int err;
- DB_ENV *env = unwrap(this);
- if ((err = ::txn_checkpoint(env, kbyte, min, flags)) != 0 &&
- err != DB_INCOMPLETE) {
- DB_ERROR("DbEnv::txn_checkpoint", err, error_policy());
- return (err);
- }
- return (err);
+#include "dbinc/cxx_int.h"
+
+#include "db_int.h"
+#include "dbinc/txn.h"
+
+// Helper macro for simple methods that pass through to the
+// underlying C method. It may return an error or raise an exception.
+// Note this macro expects that input _argspec is an argument
+// list element (e.g., "char *arg") and that _arglist is the arguments
+// that should be passed through to the C method (e.g., "(db, arg)")
+//
+#define DBTXN_METHOD(_name, _delete, _argspec, _arglist) \
+int DbTxn::_name _argspec \
+{ \
+ int ret; \
+ DB_TXN *txn = unwrap(this); \
+ \
+ ret = txn->_name _arglist; \
+ /* Weird, but safe if we don't access this again. */ \
+ if (_delete) \
+ delete this; \
+ if (!DB_RETOK_STD(ret)) \
+ DB_ERROR(DbEnv::get_DbEnv(txn->mgrp->dbenv), \
+ "DbTxn::" # _name, ret, ON_ERROR_UNKNOWN); \
+ return (ret); \
}
-int DbEnv::txn_stat(DB_TXN_STAT **statp, db_malloc_fcn_type db_malloc_fcn)
-{
- int err;
- DB_ENV *env = unwrap(this);
- if ((err = ::txn_stat(env, statp, db_malloc_fcn)) != 0) {
- DB_ERROR("DbEnv::txn_stat", err, error_policy());
- return (err);
- }
- return (err);
-}
-
-////////////////////////////////////////////////////////////////////////
-// //
-// DbTxn //
-// //
-////////////////////////////////////////////////////////////////////////
-
+// private constructor, never called but needed by some C++ linkers
DbTxn::DbTxn()
: imp_(0)
{
}
-DbTxn::~DbTxn()
+DbTxn::DbTxn(DB_TXN *txn)
+: imp_(wrap(txn))
{
+ txn->api_internal = this;
}
-int DbTxn::abort()
+DbTxn::~DbTxn()
{
- int err;
- DB_TXN *txn;
-
- txn = unwrap(this);
- err = txn_abort(txn);
-
- // It may seem weird to delete this, but is legal as long
- // as we don't access any of its data before returning.
- //
- delete this;
-
- if (err != 0)
- DB_ERROR("DbTxn::abort", err, ON_ERROR_UNKNOWN);
-
- return (err);
}
-int DbTxn::commit(u_int32_t flags)
-{
- int err;
- DB_TXN *txn;
-
- txn = unwrap(this);
- err = txn_commit(txn, flags);
-
- // It may seem weird to delete this, but is legal as long
- // as we don't access any of its data before returning.
- //
- delete this;
-
- if (err != 0)
- DB_ERROR("DbTxn::commit", err, ON_ERROR_UNKNOWN);
-
- return (err);
-}
+DBTXN_METHOD(abort, 1, (), (txn))
+DBTXN_METHOD(commit, 1, (u_int32_t flags), (txn, flags))
+DBTXN_METHOD(discard, 1, (u_int32_t flags), (txn, flags))
u_int32_t DbTxn::id()
{
DB_TXN *txn;
txn = unwrap(this);
- return (txn_id(txn)); // no error
+ return (txn->id(txn)); // no error
}
-int DbTxn::prepare()
-{
- int err;
- DB_TXN *txn;
+DBTXN_METHOD(prepare, 0, (u_int8_t *gid), (txn, gid))
+DBTXN_METHOD(set_timeout, 0, (db_timeout_t timeout, u_int32_t flags),
+ (txn, timeout, flags))
- txn = unwrap(this);
- if ((err = txn_prepare(txn)) != 0) {
- DB_ERROR("DbTxn::prepare", err, ON_ERROR_UNKNOWN);
- return (err);
- }
- return (0);
+// static method
+DbTxn *DbTxn::wrap_DB_TXN(DB_TXN *txn)
+{
+ DbTxn *wrapped_txn = get_DbTxn(txn);
+ if (wrapped_txn == NULL)
+ wrapped_txn = new DbTxn(txn);
+ return wrapped_txn;
}