summaryrefslogtreecommitdiff
path: root/project2/sql
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-11-16 00:53:10 +0000
committerrandomdan <randomdan@localhost>2011-11-16 00:53:10 +0000
commite02feb8ed1e7e99bde7b87f7baaa46422cf2dcbb (patch)
tree3637aa5ba3fd48b9fc62498e814dc44b68151d4c /project2/sql
parentLog errors from TaskHost (diff)
downloadproject2-e02feb8ed1e7e99bde7b87f7baaa46422cf2dcbb.tar.bz2
project2-e02feb8ed1e7e99bde7b87f7baaa46422cf2dcbb.tar.xz
project2-e02feb8ed1e7e99bde7b87f7baaa46422cf2dcbb.zip
Transactional caches
Diffstat (limited to 'project2/sql')
-rw-r--r--project2/sql/sqlCache.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp
index 44b4399..d6875ac 100644
--- a/project2/sql/sqlCache.cpp
+++ b/project2/sql/sqlCache.cpp
@@ -195,7 +195,7 @@ class SqlCache : public Cache {
sql.append(", ?");
}
sql.appendf(")");
- ModifyPtr m(db->getReadonly().newModifyCommand(sql));
+ ModifyPtr m(db->getWritable().newModifyCommand(sql));
unsigned int offset = 0;
m->bindParamI(offset++, row++);
BOOST_FOREACH(const Values::value_type & a, attrs) {
@@ -222,10 +222,14 @@ class SqlCache : public Cache {
PresenterPtr openFor(const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps)
{
+ Buffer sp;
+ sp.appendf("SAVEPOINT sp%p", this);
+ ModifyPtr s = ModifyPtr(db->getWritable().newModifyCommand(sp));
+ s->execute();
// Header
Buffer del;
del.appendf("INSERT INTO %s(p2_time) VALUES(?)", HeaderTable.c_str());
- ModifyPtr h = ModifyPtr(db->getReadonly().newModifyCommand(del));
+ ModifyPtr h = ModifyPtr(db->getWritable().newModifyCommand(del));
h->bindParamT(0, time(NULL));
h->execute();
// Record set header
@@ -237,15 +241,27 @@ class SqlCache : public Cache {
offset = 0;
applyKeys(boost::bind(appendKeyBinds, &sql, &offset), ps);
sql.appendf(")");
- ModifyPtr m(db->getReadonly().newModifyCommand(sql));
+ ModifyPtr m(db->getWritable().newModifyCommand(sql));
offset = 0;
applyKeys(boost::bind(bindKeyValues, m.get(), &offset, _2), ps);
m->execute();
return new SqlCachePresenter(n, f, db);
}
- void close(const Glib::ustring & , const Glib::ustring & , const IHaveParameters * )
+ void save(const Glib::ustring & , const Glib::ustring & , const IHaveParameters * )
{
+ Buffer sp;
+ sp.appendf("RELEASE SAVEPOINT sp%p", this);
+ ModifyPtr s = ModifyPtr(db->getWritable().newModifyCommand(sp));
+ s->execute();
+ }
+
+ void discard(const Glib::ustring & , const Glib::ustring & , const IHaveParameters * )
+ {
+ Buffer sp;
+ sp.appendf("ROLLBACK TO SAVEPOINT sp%p", this);
+ ModifyPtr s = ModifyPtr(db->getWritable().newModifyCommand(sp));
+ s->execute();
}
private:
@@ -285,12 +301,13 @@ class CustomSqlCacheLoader : public ElementLoaderImpl<SqlCache> {
{
if (!SqlCache::DataSource.empty()) {
boost::intrusive_ptr<CommonObjects> co = new CommonObjects();
- const RdbmsDataSource * db = co->dataSource<RdbmsDataSource>(SqlCache::DataSource);
+ RdbmsDataSource * db = co->dataSource<RdbmsDataSource>(SqlCache::DataSource);
Buffer del;
del.appendf("DELETE FROM %s WHERE p2_time < ?", SqlCache::HeaderTable.c_str());
- ModifyPtr m(db->getReadonly().newModifyCommand(del));
+ ModifyPtr m(db->getWritable().newModifyCommand(del));
m->bindParamT(0, time(NULL) - SqlCache::CacheLife);
m->execute();
+ db->commit();
}
}