Thread: [Cppcms-users] Continued discussion on bug 3536452 - transaction in progress
Brought to you by:
artyom-beilis
From: <ele...@ex...> - 2012-06-24 05:57:19
|
I didn't want to re-open the bug again, but there's a still an idea i'd like to discuss. Artyom mentioned creating a "custom" transaction class to support something like BEGIN {EXCLUSIVE|IMMEDIATE} An idea would be to add a default constructor to cppcdb::transaction so that users can inherit from it instead of creating standalone transaction classes. The current constructor cppdb::transaction(cppdb::session&) calls begin() within itself so it cannot be modified. Maybe we could also add a cppdb::transaction_base interface class with virtual commit() = 0 and rollback() = 0 functions. If Artyom thinks this might be useful, I can create a patch to support such functionality. Petr |
From: <ele...@ex...> - 2012-06-24 06:17:28
|
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? |
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 > |
From: <ele...@ex...> - 2012-06-24 11:02:47
|
Good idea. Although I'd call the guard class "transaction_guard" instead to let the user know that cppdb::transaction and cppdb::transaction_guard guard are related. Either that or nest the guard class inside transaction. Which one do you prefer? |