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_H__
00040 #define __OASYS_DURABLE_STORE_H__
00041
00042 #include <list>
00043 #include <string>
00044
00045 #include "../debug/Log.h"
00046 #include "../debug/DebugUtils.h"
00047
00048 #include "../serialize/Serialize.h"
00049 #include "../serialize/StringSerialize.h"
00050 #include "../serialize/TypeCollection.h"
00051
00052 #include "../thread/SpinLock.h"
00053
00054 #include "../util/LRUList.h"
00055 #include "../util/StringUtils.h"
00056 #include "../util/ScratchBuffer.h"
00057
00058 #include "DurableStoreKey.h"
00059
00060 namespace oasys {
00061
00062
00063 class DurableStore;
00064 class DurableStoreImpl;
00065 template <typename _Type> class DurableTable;
00066 template <typename _Type> class SingleTypeDurableTable;
00067 template <typename _Type, typename _Collection> class MultiTypeDurableTable;
00068 template <typename _Type> class DurableObjectCache;
00069 class DurableTableImpl;
00070 class DurableIterator;
00071
00075 enum DurableStoreResult_t {
00076 DS_OK = 0,
00077 DS_NOTFOUND = -1,
00078 DS_BUFSIZE = -2,
00079 DS_BUSY = -3,
00080 DS_EXISTS = -4,
00081 DS_BADTYPE = -5,
00082 DS_ERR = -1000,
00083 };
00084
00088 const char* durable_strerror(int result);
00089
00093 enum DurableStoreFlags_t {
00094 DS_CREATE = 1 << 0,
00095 DS_EXCL = 1 << 1,
00096 DS_MULTITYPE = 1 << 2,
00097
00098
00099 DS_HASH = 1 << 10,
00100 DS_BTREE = 1 << 11,
00101 };
00102
00103
00104
00105 #define __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00106 #include "DurableStoreImpl.h"
00107 #include "DurableIterator.h"
00108 #include "DurableTable.h"
00109 #include "DurableObjectCache.h"
00110 #include "DurableTable.tcc"
00111 #include "DurableObjectCache.tcc"
00112 #undef __OASYS_DURABLE_STORE_INTERNAL_HEADER__
00113
00117 class DurableStore : public Logger {
00118 public:
00123 DurableStore(const char* logpath)
00124 : Logger("DurableStore", logpath), impl_(0)
00125 {
00126 }
00127
00131 ~DurableStore();
00132
00140 int create_store(const StorageConfig& config,
00141 bool* clean_shutdown = NULL);
00142
00144 DurableStoreImpl* impl() { return impl_; }
00145
00156 template <typename _DataType>
00157 int get_table(SingleTypeDurableTable<_DataType>** table,
00158 std::string table_name,
00159 int flags,
00160 DurableObjectCache<_DataType>* cache = NULL);
00161
00171 template <typename _BaseType, typename _Collection>
00172 int get_table(MultiTypeDurableTable<_BaseType, _Collection>** table,
00173 std::string table_name,
00174 int flags,
00175 DurableObjectCache<_BaseType>* cache = NULL);
00176
00186 int get_table(StaticTypedDurableTable** table,
00187 std::string table_name,
00188 int flags,
00189 DurableObjectCache< SerializableObject >* cache = NULL);
00190
00194 int del_table(std::string table_name);
00195
00203 int get_table_names(StringVector* table_names);
00204
00205 private:
00210 typedef DurableStoreImpl::PrototypeVector PrototypeVector;
00211
00213 DurableStore(const DurableStore& other);
00214
00215 DurableStoreImpl* impl_;
00216
00217 std::string clean_shutdown_file_;
00218 };
00219
00220 #include "DurableStore.tcc"
00221
00222 }
00223
00224 #endif // __OASYS_DURABLE_STORE_H__