[odb-users] Simultaneous transactions with two databases

Boris Kolpackov boris at codesynthesis.com
Wed Aug 24 03:59:57 EDT 2011


Hi Nicolas,

Nicolas ALBEZA <n.albeza at gmail.com> writes:

> In the application i'm currently writing, i need to access two databases at
> the same time, in such a way that DB2 is accessed while DB1's transaction is
> still "active".
> 
> Is there a way to do that without triggering the
> "transaction_already_in_progress" exception ?
> 
> I think that spawning a thread would do the trick, but i'd like to know if
> there is less expensive solutions available.

Yes, creating a separate thread is the only option right now, and I
agree, it is not a very good one.

The other day I actually thought that sooner or later someone will want
to multiplex several transactions in the same thread and that we should
probably think about a way to support this. It happened sooner than I
expected ;-).

Here how I see this could work:

transaction t1 (db1->begin (), false); // false for "don't make it current"
transaction t2 (db2->begin (), false);

transaction::current (t1);

db1->load (...);

transaction::current (t2);

db2->load (...);

transaction::current (t1);

db1->update (...);
t1.commit ();

transaction::current (t2);

db2->update (...);
t2.commit ();

Would something like this help in your case?

Boris



More information about the odb-users mailing list