reSIProcate/repro  9694
BerkeleyDb.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_BERKELEYDB_HXX)
00002 #define RESIP_BERKELEYDB_HXX 
00003 
00004 #ifdef WIN32
00005 #include <db_cxx.h>
00006 #elif HAVE_CONFIG_H
00007 #include "config.h"
00008 #include DB_HEADER
00009 //#elif defined(__APPLE__) 
00010 //#include <db42/db_cxx.h>
00011 #else
00012 #include <db_cxx.h>
00013 #endif
00014 
00015 #include "rutil/Data.hxx"
00016 #include "repro/AbstractDb.hxx"
00017 
00018 namespace resip
00019 {
00020   class TransactionUser;
00021 }
00022 
00023 namespace repro
00024 {
00025 
00026 class BerkeleyDb: public AbstractDb
00027 {
00028    public:
00029       BerkeleyDb();
00030       BerkeleyDb( const resip::Data& dbPath, const resip::Data& dbName = resip::Data::Empty );
00031       
00032       virtual ~BerkeleyDb();
00033 
00034       virtual bool isSane() {return mSane; }
00035       
00036    private:
00037       void init(const resip::Data& dbPath, const resip::Data& dbName);
00038       static int getSecondaryKeyCallback(Db *db, const Dbt *pkey, const Dbt *pdata, Dbt *skey);
00039 
00040       class TableInfo
00041       {
00042       public:
00043          TableInfo() : mDb(0), mCursor(0), mTransaction(0), mSecondaryDb(0), mSecondaryCursor(0) {}
00044          Db*    mDb;
00045          Dbc*   mCursor;
00046          DbTxn* mTransaction;
00047          Db*    mSecondaryDb;
00048          Dbc*   mSecondaryCursor;
00049       };
00050 
00051       DbEnv* mEnv;
00052       TableInfo mTableInfo[MaxTable];
00053       
00054       bool mSane;
00055       
00056       // Db manipulation routines
00057       virtual bool dbWriteRecord(const Table table, 
00058                                  const resip::Data& key, 
00059                                  const resip::Data& data);
00060       virtual bool dbReadRecord(const Table table, 
00061                                 const resip::Data& key, 
00062                                 resip::Data& data) const; // return false if not found
00063       virtual void dbEraseRecord(const Table table, 
00064                                  const resip::Data& key,
00065                                  bool isSecondaryKey=false);  // allows deleting records from a table that supports secondary keying using a secondary key
00066       virtual resip::Data dbNextKey(const Table table, 
00067                                     bool first=true); // return empty if no more  
00068       virtual bool dbNextRecord(const Table table,
00069                                 const resip::Data& key,
00070                                 resip::Data& data,
00071                                 bool forUpdate,
00072                                 bool first=false);  // return false if no more
00073       virtual bool dbBeginTransaction(const Table table);
00074       virtual bool dbCommitTransaction(const Table table);
00075       virtual bool dbRollbackTransaction(const Table table);
00076 };
00077 
00078 }
00079 #endif  
00080 
00081 /* ====================================================================
00082  * The Vovida Software License, Version 1.0 
00083  * 
00084  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00085  * 
00086  * Redistribution and use in source and binary forms, with or without
00087  * modification, are permitted provided that the following conditions
00088  * are met:
00089  * 
00090  * 1. Redistributions of source code must retain the above copyright
00091  *    notice, this list of conditions and the following disclaimer.
00092  * 
00093  * 2. Redistributions in binary form must reproduce the above copyright
00094  *    notice, this list of conditions and the following disclaimer in
00095  *    the documentation and/or other materials provided with the
00096  *    distribution.
00097  * 
00098  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00099  *    and "Vovida Open Communication Application Library (VOCAL)" must
00100  *    not be used to endorse or promote products derived from this
00101  *    software without prior written permission. For written
00102  *    permission, please contact vocal@vovida.org.
00103  *
00104  * 4. Products derived from this software may not be called "VOCAL", nor
00105  *    may "VOCAL" appear in their name, without prior written
00106  *    permission of Vovida Networks, Inc.
00107  * 
00108  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00109  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00110  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00111  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00112  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00113  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00114  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00115  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00116  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00117  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00118  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00119  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00120  * DAMAGE.
00121  * 
00122  * ====================================================================
00123  * 
00124  * This software consists of voluntary contributions made by Vovida
00125  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00126  * Inc.  For more information on Vovida Networks, Inc., please see
00127  * <http://www.vovida.org/>.
00128  *
00129  */