00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00019 #error DurableStoreImpl.h must only be included from within DurableStore.h
00020 #endif
00021
00022 class StorageConfig;
00023
00027 class DurableStoreImpl : public Logger {
00028 public:
00030 typedef std::map<std::string, int> RefCountMap;
00031
00035 typedef std::vector<SerializableObject*> PrototypeVector;
00036
00040 DurableStoreImpl(const char* classname, const char* logpath)
00041 : Logger(classname, logpath) {}
00042
00046 virtual ~DurableStoreImpl() {}
00047
00051 virtual int init(const StorageConfig& config) = 0;
00052
00058 virtual int get_table(DurableTableImpl** table,
00059 const std::string& db_name,
00060 int flags,
00061 PrototypeVector& prototypes) = 0;
00062
00066 virtual int del_table(const std::string& db_name) = 0;
00067
00071 virtual int get_table_names(StringVector* names) = 0;
00072
00076 virtual std::string get_info() const = 0;
00077
00078 protected:
00079
00085 int check_db_dir(const char* db_dir,
00086 bool* dir_exists);
00087
00091 int create_db_dir(const char* db_dir);
00092
00097 void prune_db_dir(const char* db_dir,
00098 int tidy_wait);
00099 };
00100
00101
00105 class DurableTableImpl {
00106 public:
00107 DurableTableImpl(std::string table_name, bool multitype)
00108 : table_name_(table_name), multitype_(multitype) {}
00109
00110 virtual ~DurableTableImpl() {}
00111
00120 virtual int get(const SerializableObject& key,
00121 SerializableObject* data) = 0;
00122
00135 virtual int get(const SerializableObject& key,
00136 SerializableObject** data,
00137 TypeCollection::Allocator_t allocator);
00138
00148 virtual int put(const SerializableObject& key,
00149 TypeCollection::TypeCode_t typecode,
00150 const SerializableObject* data,
00151 int flags) = 0;
00152
00157 virtual int del(const SerializableObject& key) = 0;
00158
00162 virtual size_t size() const = 0;
00163
00169 virtual DurableIterator* itr() = 0;
00170
00174 const char* name() { return table_name_.c_str(); }
00175
00176 protected:
00180 size_t flatten(const SerializableObject& key,
00181 u_char* key_buf, size_t size);
00182
00183 template<size_t _size>
00184 size_t flatten(const SerializableObject& key,
00185 ScratchBuffer<u_char*, _size>* scratch);
00186
00187 std::string table_name_;
00188 bool multitype_;
00189 };
00190
00191
00192
00193 template<size_t _size>
00194 size_t
00195 DurableTableImpl::flatten(const SerializableObject& key,
00196 ScratchBuffer<u_char*, _size>* scratch)
00197 {
00198 Marshal marshaller(Serialize::CONTEXT_LOCAL, scratch);
00199 marshaller.action(&key);
00200 return scratch->len();
00201 }