Re: [Cppcms-users] Continued discussion on bug 3536452 - transaction in progress
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-06-24 10:21:45
|
I think it would be better to create some kind of generic guard class with different commits/rollbacks: // information about statements class guard { guard(); guard(std::string const &on_start) guard(std::string const &on_start, std::string const &on_commit); guard(std::string const &on_start, std::string const &on_commit, std::string const &on_rollback); // set explicitly void on_start(std::string const &); // default begin void on_commit(std::string const &); // default commit void on_rollback(std::string const &); // default rollback; }; Now out transaction constructors would look like: // ordinary transaction transaction(cppdb::session &sql); // custom transaction transaction(cppdb::session &sql,guard const &g); Now when I can run stuff like cppdb::guard myguard("BEGIN IMMEDIATE"); cppdb::scope tr(sql,myguard); ... tr.commit(); or use it with savepoints or nested transactions Define guard cppdb::guard myguard( "SAVEPOINT temp", "ROLLBACK TO SAVEPOINT temp", "RELEASE SAVEPOINT temp"); or more explicitlu cppdb::guard myguard; myguard.on_start("SAVEPOINT temp"); myguard.on_commit("RELEASE SAVEPOINT temp"); myguard.on_rollback("ROLLBACK TO SAVEPOINT temp"); And now do stuff like: cppdb::transaction tr(sql); for(...) { cppdb::transaction sp(sql,myguard); ... sp.commit(); } tr.commit(); This would be much more complete interface. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ ----- Original Message ----- > From: "ele...@ex..." <ele...@ex...> > > Here is another idea. > > 1) Create a cppdb::base_transaction class and implement the current > cppdb::transaction in it, but without calling begin() in it's constructor. > > Make its functions/destructor virtual if users want to overload & support > polymorphism. > > 2) Make cppdb::transaction inherit from base_transaction and call > session::begin() in it's constructor, so that current behavior is kept and > there wont be any API breakage. > > 3) Users will then be able to inherit from cppdb::base_transaction and > create their own transaction classes. > > This should avoid adding a default constructor and possibly confuse users. > > Is this a solid proposal Artyom? > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |