Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
transaction gets tedious.. simple wrapper?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Qiang  
View profile  
 More options Feb 27 2012, 5:25 am
From: Qiang <junkyardp...@gmail.com>
Date: Mon, 27 Feb 2012 02:25:54 -0800 (PST)
Local: Mon, Feb 27 2012 5:25 am
Subject: transaction gets tedious.. simple wrapper?
I have few places in my models need transaction. however, doing
following over and over again gets tedious.. I am wondering how do
other peopel do it?

    public function delete_news($news_id) {

        $news = $this->get_news($news_id);
        if ( ! $news ) {
            throw new Exception('error_news_not_found');
        }

        $con = Propel::getConnection(M_NewsPeer::DATABASE_NAME);
        $con->beginTransaction();

        try {
            $news->setDeleted(1);
            $news->save($con);
            $con->commit();
        } catch (Exception $e) {
            $con->rollback();
            throw $e;
        }
    }

I see that doctrine has convience wrapper usage like the following:

<?php
// $em instanceof EntityManager
$em->transactional(function($em) {
    //... do some work
    $user = new User;
    $user->setName('George');
    $em->persist($user);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richtermeister  
View profile  
 More options Feb 27 2012, 12:14 pm
From: Richtermeister <nex...@gmail.com>
Date: Mon, 27 Feb 2012 09:14:48 -0800 (PST)
Local: Mon, Feb 27 2012 12:14 pm
Subject: Re: transaction gets tedious.. simple wrapper?
Hey Quiang,

based on your example I don't think you need a transaction there.
A transaction is used to ensure 2 or more related changes (usually to
2 or more models) are assured to happen together, or not at all.
In your case you're only updating one model. Imagine it failed,
there's no inconsistency that you are guarding against, the database
would be in exactly the same state, whether you roll back or not.

I know this is not really answering your question, but with that
feedback in mind you might find that you only need transactions in a
few places, not everywhere.

Daniel

On Feb 27, 2:25 am, Qiang <junkyardp...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francois Zaninotto  
View profile  
 More options Feb 27 2012, 12:25 pm
From: Francois Zaninotto <fzanino...@gmail.com>
Date: Mon, 27 Feb 2012 18:25:17 +0100
Local: Mon, Feb 27 2012 12:25 pm
Subject: Re: [propel] Re: transaction gets tedious.. simple wrapper?

Nevertheless, I think Quiang's idea could ease the path for some devs. This
could be a welcome addition to Propel2, but it introduces a second way of
doing the same thing (a transaction), and I'm not particularily fond of
that. It means more documentation, and more confusion for the users.

What do others think?

François

2012/2/27 Richtermeister <nex...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Qiang  
View profile  
 More options Feb 27 2012, 9:39 pm
From: Qiang <junkyardp...@gmail.com>
Date: Mon, 27 Feb 2012 18:39:59 -0800 (PST)
Local: Mon, Feb 27 2012 9:39 pm
Subject: Re: transaction gets tedious.. simple wrapper?
Hi Francois,

coming from the Perl land familiar with it's popular ORM DBIx::Class,
I really enjoy the txn_do($coderef) method which takes a code
reference argument and does:

Executes $coderef with (optional) arguments @coderef_args atomically,
returning its result (if any). If an exception is caught, a rollback
is issued and the exception is rethrown. If the rollback fails, (i.e.
throws an exception) an exception is thrown that includes a "Rollback
failed" message.

copied from http://search.cpan.org/~arodland/DBIx-Class-0.08196/lib/DBIx/Class/St...
the souce code of it is here http://search.cpan.org/src/ARODLAND/DBIx-Class-0.08196/lib/DBIx/Class...

So in the end, it saves developer writing commit and rollback all over
the places..  hopefully the above could be somewhat a pointer for
Propel.

Richtermeister, thanks for pointing that out. agree that transaction
is not necessary in the above case of single operation.

cheers,

On 2月28日, 上午1时25分, Francois Zaninotto <fzanino...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francois Zaninotto  
View profile  
 More options Feb 28 2012, 2:46 am
From: Francois Zaninotto <fzanino...@gmail.com>
Date: Tue, 28 Feb 2012 08:46:23 +0100
Local: Tues, Feb 28 2012 2:46 am
Subject: Re: [propel] Re: transaction gets tedious.. simple wrapper?

Qiang,

I recognized your Perl background when you suggested something that may
lead Propel to TIMTOWTDI (There Is More Than One Way To Do It), which is
the only opposition I have to your suggestion.

Cheers,

François

2012/2/28 Qiang <junkyardp...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William DURAND  
View profile  
 More options Feb 28 2012, 3:07 am
From: William DURAND <william.dura...@gmail.com>
Date: Tue, 28 Feb 2012 09:07:24 +0100
Local: Tues, Feb 28 2012 3:07 am
Subject: Re: [propel] Re: transaction gets tedious.. simple wrapper?

Hi,

 I like the idea to add a new method on the connection class (transactional(\closure) for instance), it's a convenient way to use transactions, and it really makes sense IMO. But, it's a bit restrictive because you won't be able to use a single transaction everywhere (let's say if you cannot put all of your code in one closure). So we need to keep existing methods, and then we'll provide two ways to use transactions.

In one hand, Propel has always provided an intuitive, and convenient API. That's why I think it makes sense to add this feature.
In another hand, it duplicates features, even if it eases things.

Let's wait more feedback from users.

My 2cents

Cheers,
William

Le 28 févr. 2012 à 08:46, Francois Zaninotto <fzanino...@gmail.com> a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richtermeister  
View profile  
 More options Feb 29 2012, 2:23 pm
From: Richtermeister <nex...@gmail.com>
Date: Wed, 29 Feb 2012 11:23:37 -0800 (PST)
Local: Wed, Feb 29 2012 2:23 pm
Subject: Re: transaction gets tedious.. simple wrapper?
As it is there's different ways of doing things.. I can work with a
criteria, a query, criterions.. all to the same effect where the only
difference is convenience.
So, I'd be +1 on adding that method, too.

Daniel

On Feb 28, 12:07 am, William DURAND <william.dura...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »