00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00036 #ifndef OW_GENERICHDBREPOSITORY_HPP_INCLUDE_GUARD_
00037 #define OW_GENERICHDBREPOSITORY_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_Types.hpp"
00040 #include "OW_HDB.hpp"
00041 #include "OW_Array.hpp"
00042 #include "OW_MutexLock.hpp"
00043 #include "OW_CIMBase.hpp"
00044 #include "OW_ServiceEnvironmentIFC.hpp"
00045 #include "OW_Logger.hpp"
00046 
00047 namespace OW_NAMESPACE
00048 {
00049 
00050 class HDBHandleLock;
00051 class OW_HDB_API GenericHDBRepository
00052 {
00053 public:
00058    GenericHDBRepository();
00062    virtual ~GenericHDBRepository();
00068    virtual void init(const ServiceEnvironmentIFCRef& env);
00076    virtual void open(const String& path);
00080    virtual void close();
00081 #if !defined(OW_DISABLE_INSTANCE_MANIPULATION) && !defined(OW_DISABLE_NAMESPACE_MANIPULATION)
00082 
00089    virtual int createNameSpace(const String& ns);
00096    void deleteNameSpace(const String& key);
00097 #endif
00098 
00105    bool nameSpaceExists(const String& key);
00109    bool isOpen() { return m_opened; }
00110    void nodeToCIMObject(CIMBase& cimObj, const HDBNode& node);
00111    void getCIMObject(CIMBase& cimObj, const String& key,
00112       HDBHandle hdl);
00113    void updateCIMObject(const CIMBase& cimObj, HDBNode& node,
00114       HDBHandle hdl);
00115    void addCIMObject(const CIMBase& cimObj, const String& key,
00116       HDBNode& parentNode, HDBHandle hdl, UInt32 nodeFlags=0);
00117    void addCIMObject(const CIMBase& cimObj, const String& key,
00118       HDBHandle hdl, UInt32 nodeFlags=0);
00126    HDBHandle getHandle();
00133    void freeHandle(HDBHandle& hdl);
00140    HDBNode getNameSpaceNode(HDBHandleLock& hdl, String key);
00141 
00142    static const String COMPONENT_NAME;
00143 
00144 protected:
00149    void throwIfNotOpen()
00150    {
00151       if (!isOpen())
00152          OW_THROW(HDBException, "Database is not open");
00153    }
00154 
00155 #ifdef OW_WIN32
00156 #pragma warning (push)
00157 #pragma warning (disable: 4251)
00158 #endif
00159 
00160    HDB m_hdb;
00161    bool m_opened;
00162    Mutex m_guard;
00163    Array<HDBHandle> m_handles;
00164    ServiceEnvironmentIFCRef m_env;
00165    enum { MAXHANDLES = 10 };
00166    friend class HDBHandleLock;
00167 
00168 #ifdef OW_WIN32
00169 #pragma warning (pop)
00170 #endif
00171 
00172 };
00181 class OW_HDB_API HDBHandleLock
00182 {
00183 public:
00184    HDBHandleLock(GenericHDBRepository* pr, const HDBHandle& hdl) :
00185       m_pr(pr), m_hdl(hdl) {}
00186    ~HDBHandleLock()
00187    {
00188       try
00189       {
00190          if (m_pr) m_pr->freeHandle(m_hdl);
00191       }
00192       catch (...)
00193       {
00194          
00195       }
00196    }
00197    HDBHandle* operator->() { return &m_hdl; }
00198    HDBHandle& operator*() { return m_hdl; }
00199    HDBHandle getHandle() { return m_hdl; }
00200 private:
00201    GenericHDBRepository* m_pr;
00202    HDBHandle m_hdl;
00203 };
00204 static const UInt32 HDBNSNODE_FLAG = 0x40000000;
00205 static const UInt32 HDBCLSNODE_FLAG = 0x20000000;
00206 static const UInt32 HDBCLSASSOCNODE_FLAG = 0x08000000;
00207 
00208 } 
00209 
00210 #endif