[Libpqxx-general] Liskov Substitution and Transactions

Maurice Gittens mainmanmauricio at gmail.com
Sat Apr 25 08:45:50 UTC 2009


Jeroen,


On Sat, Apr 25, 2009 at 9:16 AM, Jeroen Vermeulen <jtv at xs4all.nl> wrote:

> Maurice Gittens wrote:
>
>  This should help me to do the trick.
>>
>
> BTW please post any feedback you may have on this API.  Daniel Frey did
> some splendid work on it, and if you feel it's fit for practical third-party
> use I'd like to move it out of the pqxx::internal namespace.
>
>
> Jeroen



Since you seem interested in API feedback I'll share an annoyance I
encountered with the
transaction API.

I'm writing A JIT Compiler that emits pqxx calls and it is inconvenient that
the transaction API does not
seem to adhere to the Liskov Substitution principle.

But it is possible that I am simply missing something.

Consider the following syntax.

void foo()
{
   print "before the transaction\n";

   transaction tx
   {
      ... // code

      transaction nested_tx
      {
         ... code
         nested_tx.rollback();
      }

      tx.commit()
   }


   print "after the transaction\n";
}

The JIT compiler maintains a stack of transaction objects which is
conceptually pushed on entry to
transaction blocks and popped on exit.

I need a type common to all pqxx transaction classes which allows me to
abstract away
the difference between non-nested, nested and possibly also nontransactions.

My problem is that I can't seem to find which base class to use.

I've tried to declare the stack as:

std::vector<pqxx::dbtransaction*> TxStack;

But this does not work because the destructor of pqxx::dbtransaction is
protected or something.

I currently maintain a stack of subtransactions and separately a pointer to
the "main" transaction
of type pqxx::basic_transaction.

Any pointers to how I can solve this problem more elegantly?

Kind regards,
Maurice
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://pgfoundry.org/pipermail/libpqxx-general/attachments/20090425/7141650e/attachment.html 


More information about the Libpqxx-general mailing list