Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Grouping / Abstracting Database Transactions

by nmerriweather (Friar)
on Jan 05, 2006 at 00:17 UTC ( [id://521067]=perlquestion: print w/replies, xml ) Need Help??

nmerriweather has asked for the wisdom of the Perl Monks concerning the following question:

I have a webapp. It is made all object oriented. I'm trying to reuse components / objects as much as possible, and am running into a bit of a snag.

I've created an abstraction layer to Apache::DBI. it works like this:

WebPages check out the write handle as a 'SuperTransaction'
Objects check out the write handle as a 'Transaction' or 'NonTransaction'
If an object checks out the write handle and a 'super transaction' has begun, then we have a silent acceptance. If there is an error in the 'super transaction', we fail the attempt. The whole idea is to let the web pages group together object actions and rollback/commit if one breaks -- while letting the object actions themselves be encapsulated within transactions if necessary.

Herein lies the problem: my abstraction layer is a hack, because I couldn't find anything similar in CPAN. Now I've run into the situation where i need to nest an object transaction within an object transaction within a WebPage transaction ( I support WebObject fine. WebObjectObject is beyond what i can think of getting to work right now)

Can anyone make a suggestion on where to proceed?
  • Comment on Grouping / Abstracting Database Transactions

Replies are listed 'Best First'.
Re: Grouping / Abstracting Database Transactions
by graff (Chancellor) on Jan 05, 2006 at 02:48 UTC
    ... Now I've run into the situation where i need to nest an object transaction within an object transaction within a WebPage transaction...

    I'm guessing that it might help if you give us a little bit of example code, or maybe some pseudo-code or at least a more detailed description of the sort of transaction sequence you're trying to implement (e.g. from the web client's perspective).

    Based on what you've posted so far, I can't imagine what sort of web-based interaction model would make it necessary to do this sort of nesting. In fact, it's kind of hard to imagine what sorts of objects you're really talking about.

    For that matter, ... um ... what question did you have about your code? If it's just "where to proceed", and your "abstraction layer is a hack", why not just scrap it and start over from first principles (whatever those might be)?

Re: Grouping / Abstracting Database Transactions
by perrin (Chancellor) on Jan 05, 2006 at 05:51 UTC
    The normal way to handle transactions in a web page is to attempt to do all your work and commit at the end, and if anything goes wrong you throw an exception and roll back. Apache::DBI helps you out with this by automatically rolling back at the end in case your program died before committing.

    Can you explain why this approach is not adequate for what you're doing? Is it that some of the object actions have to be committed before continuing to the others?

Re: Grouping / Abstracting Database Transactions
by valdez (Monsignor) on Jan 05, 2006 at 09:57 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://521067]
Approved by astaines
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found