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 #ifndef OW_ASSOCDB2_HPP_INCLUDE_GUARD_
00031 #define OW_ASSOCDB2_HPP_INCLUDE_GUARD_
00032 #include "OW_config.h"
00033 #include "OW_Types.hpp"
00034 #include "OW_Array.hpp"
00035 #include "OW_String.hpp"
00036 #include "OW_File.hpp"
00037 #include "OW_MutexLock.hpp"
00038 #include "OW_CIMFwd.hpp"
00039 #include "OW_ServiceEnvironmentIFC.hpp"
00040 #include "OW_SortedVectorSet.hpp"
00041 #include "OW_CIMObjectPath.hpp"
00042 #include "OW_ResultHandlerIFC.hpp"
00043 #include "OW_dbDatabase.hpp"
00044
00045 #include <db.h>
00046
00047 namespace OW_NAMESPACE
00048 {
00049
00053 class AssocDbEntry2
00054 {
00055 public:
00056 AssocDbEntry2(std::istream& istrm);
00057 AssocDbEntry2()
00058 : m_objectName(CIMNULL)
00059 , m_offset(-1L)
00060 {}
00061 AssocDbEntry2(const CIMObjectPath& objectName,
00062 const String& role,
00063 const String& resultRole);
00064 struct entry
00065 {
00066 entry ()
00067 : m_associatedObject(CIMNULL)
00068 , m_associationPath(CIMNULL)
00069 {}
00070 String m_assocClass;
00071 String m_resultClass;
00072 CIMObjectPath m_associatedObject;
00073 CIMObjectPath m_associationPath;
00074
00075 void writeObject(std::ostream& ostrm) const;
00076 void readObject(std::istream& istrm);
00077 };
00078 void writeObject(std::ostream& ostrm) const;
00079 void readObject(std::istream& istrm);
00080 Int32 getOffset() const { return m_offset; }
00081 void setOffset(Int32 offset) { m_offset = offset; }
00082 static String makeKey(const CIMObjectPath& objectName, const String& role,
00083 const String& resultRole);
00084
00085 String makeKey() const;
00086 private:
00087 struct dummy
00088 {
00089 void nonnull() {};
00090 };
00091 typedef void (dummy::*safe_bool)();
00092 public:
00093 operator safe_bool () const
00094 { return (m_objectName) ? &dummy::nonnull : 0; }
00095 safe_bool operator!() const
00096 { return (m_objectName) ? 0: &dummy::nonnull; }
00097 public:
00098 CIMObjectPath m_objectName;
00099 String m_role;
00100 String m_resultRole;
00101 Array<entry> m_entries;
00102 Int32 m_offset;
00103 };
00104 std::ostream& operator << (std::ostream& ostrm, const AssocDbEntry2& arg);
00105 typedef Array<AssocDbEntry2> AssocDbEntry2Array;
00106 bool operator==(const AssocDbEntry2::entry& lhs, const AssocDbEntry2::entry& rhs);
00108 class AssocDb2;
00110 typedef ResultHandlerIFC<AssocDbEntry2::entry> AssocDbEntry2ResultHandlerIFC;
00111
00112 class AssocDb2
00113 {
00114 public:
00118 AssocDb2(ServiceEnvironmentIFCRef env);
00122 ~AssocDb2();
00126 void open(const String& fileName, ::DB_ENV* env, ::DB_TXN* txn);
00130 void close();
00138 bool hasAssocEntries(const String& ns, const CIMObjectPath& instanceName);
00143 void addEntry(const CIMObjectPath& objectName,
00144 const String& assocClassName, const String& resultClass,
00145 const String& role, const String& resultRole,
00146 const CIMObjectPath& associatedObject,
00147 const CIMObjectPath& assocClassPath);
00155 void addEntries(const String& ns, const CIMInstance& assocInstance);
00156 void addEntries(const String& ns, const CIMClass& assocClass);
00161 void deleteEntry(const CIMObjectPath& objectName,
00162 const String& assocClassName, const String& resultClass,
00163 const String& role, const String& resultRole,
00164 const CIMObjectPath& associatedObject,
00165 const CIMObjectPath& assocClassPath);
00173 void deleteEntries(const String& ns, const CIMInstance& assocInstance);
00174 void deleteEntries(const String& ns, const CIMClass& assocClass);
00184 void getAllEntries(const CIMObjectPath& objectName,
00185 const SortedVectorSet<String>* passocClasses,
00186 const SortedVectorSet<String>* presultClasses,
00187 const String& role,
00188 const String& resultRole,
00189 AssocDbEntry2ResultHandlerIFC& result);
00190 private:
00191 AssocDbEntry2 findEntry(const String& objectKey);
00192 void deleteEntry(const AssocDbEntry2& entry);
00193 void addEntry(const AssocDbEntry2& entry);
00194 void addOrDeleteEntries(const String& ns, const CIMInstance& assocInstance, bool add);
00195 void addOrDeleteEntries(const String& ns, const CIMClass& assocClass, bool add);
00196 ServiceEnvironmentIFCRef m_env;
00197 dbDatabase m_db;
00198 };
00199
00200 }
00201
00202 #endif