it_bus_pdk/dbm.h

00001 #ifndef _IT_BUS_DBM_H_
00002 #define _IT_BUS_DBM_H_
00003 
00004 // @Copyright 2004 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 
00007 #include <it_dsa/types.h>
00008 #include <it_ts/recursive_mutex.h>
00009 #include <it_bus/logging_defs.h>
00010 #include <it_bus/types.h>
00011 #include <it_bus/api_defines.h>
00012 #include <it_bus_pdk/db_exception.h>
00013 #include <it_bus_pdk/db_config.h>
00014 
00015 namespace IT_Bus
00016 {
00017     class IT_DBM_API DBM;
00018 
00019     // Database iterator
00020     //
00021     class IT_DBM_API DBIterator
00022     {
00023       public:
00024         DBIterator(
00025             DBM*     db,
00026             DBC*     cursor,
00027             void*    key,
00028             IT_ULong key_len
00029         );
00030         DBIterator(
00031             const DBIterator& it
00032         );
00033         ~DBIterator();
00034 
00035         DBIterator&
00036         operator=(
00037             const DBIterator& it
00038         );
00039 
00040         void
00041         get_value(
00042             void*&    key,
00043             IT_ULong& key_len,
00044             void*&    val,
00045             IT_ULong& val_len,
00046             void*     (*alloc_key)(size_t)   = 0,
00047             void*     (*alloc_value)(size_t) = 0
00048         );
00049 
00050         IT_Bool
00051         operator==(
00052             const DBIterator& dbi
00053         ) const;
00054 
00055         IT_Bool
00056         operator!=(
00057             const DBIterator& dbi
00058         ) const
00059         {
00060             return !operator==(dbi);
00061         }
00062 
00063         DBIterator&
00064         operator++();
00065 
00066       private:
00067         char     m_store[64];
00068         DBM*     m_db;
00069         DBC*     m_cursor;
00070         void*    m_key;
00071         IT_ULong m_key_len;
00072         IT_Bool  m_heap;
00073 
00074       friend class DBM;
00075     };
00076 
00077     // Database manager
00078     //
00079     class IT_DBM_API DBM
00080     {
00081       public:
00082         DBM(
00083             const char* db_name,
00084             DBConfig*   cfg
00085         ) IT_THROW_DECL((DBException));
00086 
00087         ~DBM();
00088 
00089         void
00090         open_db(
00091             const char* name
00092         ) IT_THROW_DECL((DBException));
00093 
00094         IT_Pair<DBIterator, IT_Bool>
00095         insert(
00096             void*    key,
00097             IT_ULong key_len,
00098             void*    val,
00099             IT_ULong val_len,
00100             IT_Bool  overwrite = IT_FALSE
00101         ) IT_THROW_DECL((DBException));
00102 
00103         DBIterator
00104         find(
00105             void*       key,
00106             IT_ULong    key_len,
00107             IT_Bool     have_recursed = IT_FALSE
00108         ) const IT_THROW_DECL((DBException));
00109 
00110         IT_Bool
00111         erase(
00112             void*    key,
00113             IT_ULong key_len
00114         ) IT_THROW_DECL((DBException));
00115 
00116         IT_ULong
00117         get_size() const IT_THROW_DECL((DBException));
00118 
00119         DBIterator
00120         begin(
00121             IT_Bool have_recursed = IT_FALSE
00122         ) const;
00123 
00124         inline DBIterator
00125         end() const;    
00126 
00127       protected:
00128         IT_DECLARE_BUS_LOGGER_MEM
00129 
00130       private:
00131 
00132         void
00133         mark_db_for_reopening();
00134 
00135         void
00136         reopen_db();
00137 
00138         void
00139         close_db();
00140 
00141         IT_String           m_db_name;
00142         IT_Bool             m_should_reopen_db;
00143         DB*                 m_db;
00144         DBC*                m_cur;
00145         DBConfig*           m_cfg;      
00146         DBEnv*              m_env;
00147         IT_RecursiveMutex   m_mutex;
00148 
00149         // private and unimplemented to prevent copying
00150         DBM(const DBM&);
00151         void operator=(const DBM&);
00152 
00153         friend class DBEnv;
00154     };
00155 
00156     IT_DBM_API DBIterator
00157     DBM::end() const
00158     {
00159         DBM* ncthis = IT_CONST_CAST(DBM*, this);
00160         return DBIterator(ncthis, 0, 0, 0);
00161     }
00162 
00163 }
00164 
00165 #endif  

Generated on Thu Sep 7 11:39:33 2006 for Artix by  doxygen 1.4.7