Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

cxx_txn.cpp

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: cxx_txn.cpp,v 12.2 2005/06/16 20:21:03 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #include <errno.h>
00013 
00014 #include "db_cxx.h"
00015 #include "dbinc/cxx_int.h"
00016 
00017 #include "db_int.h"
00018 #include "dbinc/txn.h"
00019 
00020 // Helper macro for simple methods that pass through to the
00021 // underlying C method. It may return an error or raise an exception.
00022 // Note this macro expects that input _argspec is an argument
00023 // list element (e.g., "char *arg") and that _arglist is the arguments
00024 // that should be passed through to the C method (e.g., "(db, arg)")
00025 //
00026 #define DBTXN_METHOD(_name, _delete, _argspec, _arglist)                   \
00027 int DbTxn::_name _argspec                                                  \
00028 {                                                                          \
00029         int ret;                                                           \
00030         DB_TXN *txn = unwrap(this);                                        \
00031         DbEnv *dbenv = DbEnv::get_DbEnv(txn->mgrp->dbenv);                 \
00032                                                                            \
00033         ret = txn->_name _arglist;                                         \
00034         /* Weird, but safe if we don't access this again. */               \
00035         if (_delete)                                                       \
00036                 delete this;                                               \
00037         if (!DB_RETOK_STD(ret))                                            \
00038                 DB_ERROR(dbenv, "DbTxn::" # _name, ret, ON_ERROR_UNKNOWN); \
00039         return (ret);                                                      \
00040 }
00041 
00042 // private constructor, never called but needed by some C++ linkers
00043 DbTxn::DbTxn()
00044 :       imp_(0)
00045 {
00046 }
00047 
00048 DbTxn::DbTxn(DB_TXN *txn)
00049 :       imp_(txn)
00050 {
00051         txn->api_internal = this;
00052 }
00053 
00054 DbTxn::~DbTxn()
00055 {
00056 }
00057 
00058 DBTXN_METHOD(abort, 1, (), (txn))
00059 DBTXN_METHOD(commit, 1, (u_int32_t flags), (txn, flags))
00060 DBTXN_METHOD(discard, 1, (u_int32_t flags), (txn, flags))
00061 
00062 u_int32_t DbTxn::id()
00063 {
00064         DB_TXN *txn;
00065 
00066         txn = unwrap(this);
00067         return (txn->id(txn));          // no error
00068 }
00069 
00070 DBTXN_METHOD(get_name, 0, (const char **namep), (txn, namep))
00071 DBTXN_METHOD(prepare, 0, (u_int8_t *gid), (txn, gid))
00072 DBTXN_METHOD(set_name, 0, (const char *name), (txn, name))
00073 DBTXN_METHOD(set_timeout, 0, (db_timeout_t timeout, u_int32_t flags),
00074     (txn, timeout, flags))
00075 
00076 // static method
00077 DbTxn *DbTxn::wrap_DB_TXN(DB_TXN *txn)
00078 {
00079         DbTxn *wrapped_txn = get_DbTxn(txn);
00080         return (wrapped_txn != NULL) ?  wrapped_txn : new DbTxn(txn);
00081 }

Generated on Sun Dec 25 12:14:18 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2