00001 #ifndef _SQLPERSIST_HH_
00002 #define _SQLPERSIST_HH_
00003
00004 #if defined(WIN32)
00005 # ifdef SQLPERSIST_EXPORTS
00006 # define SQLPERSIST_API __declspec(dllexport)
00007 # else
00008 # define SQLPERSIST_API __declspec(dllimport)
00009 # endif
00010 #else
00011 # ifdef HAVE_GCC_VISIBILITY
00012 # define SQLPERSIST_API __attribute__ ((visibility("default")))
00013 # else
00014 # define SQLPERSIST_API
00015 # endif
00016 #endif
00017
00018
00019 #include <vos/vos/vos.hh>
00020 #include <vos/extensions/sqlpersist/sqldb.hh>
00021
00022 namespace VOS {
00023 class SQLWriteThread
00024 {
00025 private:
00026 SQLDatabase* database;
00027 VUtil::SynchronizedQueue<std::string*>* queryqueue;
00028
00029 public:
00030 SQLWriteThread(SQLDatabase* database);
00031 SQLWriteThread(const SQLWriteThread& swt);
00032
00033 void operator()();
00034
00035 void push_queryf(const char* q, ...);
00036 };
00037
00038
00039 class SQLPERSIST_API SQLPersistance : public VobjectExtension, public SiteExtension, public Persistance
00040 {
00041 private:
00042 SQLDatabase* database;
00043 void setupDatabase(const char* dbname);
00044 bool readingDB;
00045 SQLWriteThread* writethread;
00046
00047 public:
00048 SQLPersistance(SQLDatabase* db, const char* dbname);
00049
00050 virtual void wipeDatabase();
00051
00052 virtual void siteExtensionAttachedTo(Site* vb);
00053
00054 virtual void destroy() { }
00055
00056 virtual void post_createVobject(VobjectState& state, Vobject* requester, VobjectBase* newvobject);
00057 virtual void post_renameVobject(VobjectState& state, Vobject* requester,
00058 const std::string& oldname, const std::string& newname);
00059
00060 virtual void post_addType(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00061 Vobject* requester, const std::string& s);
00062 virtual void post_removeType(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00063 Vobject* requester, const std::string& s);
00064 virtual void post_insertChild(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00065 Vobject* requester,
00066 int position, const std::string& contextual_name, Vobject* child);
00067 virtual void post_setChild(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00068 Vobject* requester,
00069 int position, const std::string& contextual_name, Vobject* child,
00070 const std::string& oldcontextual_name, Vobject* oldchild);
00071 virtual void post_removeChild(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00072 Vobject* requester,
00073 ParentChildRelation* pcr,
00074 bool strict);
00075 virtual void post_addToACL(AccessControlState* acs, Vobject* requester, const std::string& ACLname, Vobject* id,
00076 const std::string& oldACLname);
00077 virtual void post_removeFromACL(AccessControlState* acs, Vobject* requester, const std::string& ACLname, Vobject* id);
00078 virtual void post_deleteACL(AccessControlState* acs, Vobject* requester,
00079 const std::string& policies, AccessControlList* oldacl);
00080 virtual void post_setDefaultPolicy(AccessControlState* acs, Vobject* requester, const std::string& policy,
00081 const std::string& oldpolicy);
00082
00083 virtual void beginTransaction();
00084 virtual void endTransaction();
00085 virtual bool storeBlock(Vobject* from, const std::string& key, const std::string& data);
00086 virtual bool getBlock(Vobject* from, const std::string& key, std::string& data);
00087 virtual bool blockExists(Vobject* from, const std::string& key);
00088 virtual bool removeBlock(Vobject* from, const std::string& key);
00089 virtual bool isLoadingDB() { return readingDB; }
00090 };
00091 }
00092
00093 #endif