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
00037
00038
00039 #ifndef __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00040 #error DurableStoreImpl.h must only be included from within DurableStore.h
00041 #endif
00042
00043 class StorageConfig;
00044
00048 class DurableStoreImpl : public Logger {
00049 public:
00051 typedef std::map<std::string, int> RefCountMap;
00052
00056 typedef std::vector<SerializableObject*> PrototypeVector;
00057
00061 DurableStoreImpl(const char* classname, const char* logpath)
00062 : Logger(classname, logpath) {}
00063
00067 virtual ~DurableStoreImpl() {}
00068
00072 virtual int init(const StorageConfig& config) = 0;
00073
00079 virtual int get_table(DurableTableImpl** table,
00080 const std::string& db_name,
00081 int flags,
00082 PrototypeVector& prototypes) = 0;
00083
00087 virtual int del_table(const std::string& db_name) = 0;
00088
00092 virtual int get_table_names(StringVector* names) = 0;
00093
00094 protected:
00095
00101 int check_db_dir(const char* db_dir,
00102 bool* dir_exists);
00103
00107 int create_db_dir(const char* db_dir);
00108
00113 void prune_db_dir(const char* db_dir,
00114 int tidy_wait);
00115 };
00116
00117
00121 class DurableTableImpl {
00122 public:
00123 DurableTableImpl(std::string table_name, bool multitype)
00124 : table_name_(table_name), multitype_(multitype) {}
00125
00126 virtual ~DurableTableImpl() {}
00127
00136 virtual int get(const SerializableObject& key,
00137 SerializableObject* data) = 0;
00138
00151 virtual int get(const SerializableObject& key,
00152 SerializableObject** data,
00153 TypeCollection::Allocator_t allocator);
00154
00164 virtual int put(const SerializableObject& key,
00165 TypeCollection::TypeCode_t typecode,
00166 const SerializableObject* data,
00167 int flags) = 0;
00168
00173 virtual int del(const SerializableObject& key) = 0;
00174
00178 virtual size_t size() const = 0;
00179
00185 virtual DurableIterator* itr() = 0;
00186
00190 const char* name() { return table_name_.c_str(); }
00191
00192 protected:
00196 size_t flatten(const SerializableObject& key,
00197 u_char* key_buf, size_t size);
00198
00199 template<size_t _size>
00200 size_t flatten(const SerializableObject& key,
00201 ScratchBuffer<u_char*, _size>* scratch);
00202
00203 std::string table_name_;
00204 bool multitype_;
00205 };
00206
00207
00208
00209 template<size_t _size>
00210 size_t
00211 DurableTableImpl::flatten(const SerializableObject& key,
00212 ScratchBuffer<u_char*, _size>* scratch)
00213 {
00214 Marshal marshaller(Serialize::CONTEXT_LOCAL, scratch);
00215 marshaller.action(&key);
00216 return scratch->len();
00217 }