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
00031
00032
00033
00034
00035
00036 #ifndef INCL_BLOCKING_SQLLITE_KEY_VALUE_STORE
00037 #define INCL_BLOCKING_SQLLITE_KEY_VALUE_STORE
00038
00042 #include <sqlite3.h>
00043
00044 #include <semaphore.h>
00045
00046 #include "client/SQLiteKeyValueStore.h"
00047
00048 BEGIN_NAMESPACE
00049
00050 class BlockingSQLiteKeyValueStore : public SQLiteKeyValueStore {
00051
00052 mutable sem_t sema;
00053 mutable sem_t sema_save;
00054
00055 private:
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 virtual Enumeration & query(const StringBuffer & sql) const
00067 {
00068 sem_wait(&sema);
00069 Enumeration& e = SQLiteKeyValueStore::query(sql);
00070 sem_post(&sema);
00071 return e;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 virtual int execute(const StringBuffer & sql)
00083 {
00084 int ret;
00085 sem_wait(&sema);
00086 ret = SQLiteKeyValueStore::execute(sql);
00087 sem_post(&sema);
00088 return ret;
00089 }
00090
00091 virtual bool enumeration_hasMoreElement()
00092 {
00093 bool ret;
00094 sem_wait(&sema);
00095 ret = SQLiteKeyValueStore::enumeration_hasMoreElement();
00096 sem_post(&sema);
00097 return ret;
00098 }
00099
00100 virtual ArrayElement* enumeration_getNextElement()
00101 {
00102 ArrayElement * ret;
00103 sem_wait(&sema);
00104 ret = SQLiteKeyValueStore::enumeration_getNextElement();
00105 sem_post(&sema);
00106 return ret;
00107 }
00108
00109 public:
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 BlockingSQLiteKeyValueStore(const StringBuffer & table, const StringBuffer & colKey, const StringBuffer & colValue,
00122 const StringBuffer & path)
00123 : SQLiteKeyValueStore(table,colKey,colValue,path)
00124 {
00125 sem_init(&sema,0,1);
00126 sem_init(&sema_save,0,1);
00127 }
00128
00129
00130
00131
00132
00133
00134 virtual ~BlockingSQLiteKeyValueStore()
00135 {
00136 }
00137
00141 virtual Enumeration& getProperties() const
00142 {
00143 sem_wait(&sema);
00144 Enumeration & e = SQLiteKeyValueStore::getProperties();
00145 sem_post(&sema);
00146 return e;
00147 }
00148
00156 virtual int save()
00157 {
00158 int ret;
00159 sem_wait(&sema_save);
00160 ret = SQLiteKeyValueStore::save();
00161 sem_post(&sema_save);
00162 return ret;
00163 }
00164 };
00165
00166
00167 END_NAMESPACE
00168
00171 #endif