00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00029 #include "Types.h"
00030
00032 typedef std::map<KeyImpl*, value_type> KeyFieldMap;
00033
00035 typedef std::pair<FieldImpl*, std::string> TextFieldPair;
00036
00038 typedef std::map<KeyFieldMap, SavableManagerPtr> ByKeyCache;
00039
00041 typedef std::map<TextFieldPair, SavableManagerPtr> ByValueCache;
00042
00057 class SavableManager : public boost::enable_shared_from_this<SavableManager>
00058 {
00059 public:
00070 static SavableManagersPtr getmulti(ValuesPtr values);
00071
00083 static SavableManagersPtr getmulti(ValuesPtr values, const Joins& joins);
00084
00086 static SavableManagerPtr getnew(TableImplPtr table);
00087
00089 static SavableManagerPtr bykey(KeyValuePtr key);
00090
00092 static SavableManagerPtr bykeys(KeysPtr keys);
00093
00095 static SavableManagerPtr byvalue(ValuePtr value);
00096
00098 static KeysPtr lookupvalue(ValuePtr value);
00099
00101 static size_t count(SelectionMaskPtr mask);
00102
00104 static size_t count(KeysPtr keys);
00105
00106
00108 void erase();
00109
00111 void save();
00112
00114 void discard();
00115
00117 bool exists() const;
00118
00120 bool lock();
00121
00123 void unlock();
00124
00125
00127 void bindKeys(sqlite3* db, sqlite3_stmt* stmt, const int startpos = 1) const;
00128
00130 void bindFields(sqlite3* db, sqlite3_stmt* stmt, const int startpos = 1) const;
00131
00133 void bindUpdate(sqlite3* db, sqlite3_stmt* stmt) const;
00134
00136 void bindLookup(sqlite3* db, sqlite3_stmt* stmt) const;
00137
00138
00145 void parseInsert(sqlite3* db);
00146
00148 void parseSelect(sqlite3_stmt* stmt, const int startpos = 0);
00149
00151 void parseLookup(sqlite3_stmt* stmt);
00152
00153
00155 TableImplPtr getTable() const;
00156
00158 ValuePtr getValue(FieldImplPtr field) const;
00159
00161 KeysPtr getKeys() const;
00162
00164 size_t primaryKeySize() const;
00165
00166
00168 std::string toString();
00169
00171 Strings fieldList() const;
00172
00174 std::string getDiff() const;
00175
00177 bool isDirty() const;
00178
00179
00181 void setKeys(KeysPtr keys);
00182
00184 void setValue(ValuePtr value);
00185
00187 void setValue(FieldImplPtr field, cstring value);
00188
00190 void setValue(FieldImplPtr field, value_type value);
00191
00193 void setValue(KeyImplPtr field, value_type value);
00194
00195 private:
00197 SavableManager(TableImplPtr table);
00198
00200 ~SavableManager();
00201
00202
00204 void cleanup();
00205
00206
00208 static void doFullCache(SavableManagerPtr manager);
00209
00211 static void doUncache(SavableManagerPtr manager);
00212
00214 static void doRecache(SavableManagerPtr manager);
00215
00217 static KeyFieldMap constructMap(SavableManagerPtr keys);
00218
00220 static KeyFieldMap constructMap(KeysPtr keys);
00221
00223 static TextFieldPair constructPair(FieldValuePtr value);
00224
00226 static std::string fromMap(const KeyFieldMap& map);
00227
00228
00229 static ByKeyCache ms_byKeyCache;
00230 static ByValueCache ms_byValueCache;
00233 friend SmartPtrDelete(SavableManager);
00234 friend class SelectionMask;
00235
00236 TableImplPtr m_table;
00237 ValuePtr m_lookupvalue;
00239 FieldValueMap m_fields;
00240 FieldValueMap m_orig;
00242 bool m_newentry;
00243 bool m_locked;
00244 };