newbie transaction question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

newbie transaction question

jnl1
hi all...

   within a controller operations, i need to save 2 objects.  they both either succeed or both fail (one transaction).   how does a controller handle transactions?  according to graeme's book, a you can set the transaction level on a service, but do I need to create a service in order to accomplish saving 2 objects within a controller within a single transaction ?

thanks in adv...
Reply | Threaded
Open this post in threaded view
|

Re: newbie transaction question

Dmitriy Kopylenko-3
Use 'withTransaction' dynamic method of GORM-enhanced model class which takes a closure passing in an instance of a Spring's TransactionStatus e.g.

MyModelClass.withTransaction { txStatus ->
    obj1.save ()
    obj2.save()
}



2007/12/8, jnl1 <[hidden email]>:

hi all...

   within a controller operations, i need to save 2 objects.  they both
either succeed or both fail (one transaction).   how does a controller
handle transactions?  according to graeme's book, a you can set the
transaction level on a service, but do I need to create a service in order
to accomplish saving 2 objects within a controller within a single
transaction ?

thanks in adv...

--
View this message in context: http://www.nabble.com/newbie-transaction-question-tp14235128p14235128.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: newbie transaction question

jnl1
thanks Dmitriy...i tried your example and it works like a champ.  also got a service working.  

does anyone have a ptr to which is preferred a service or closure ? (I'm assuming they have some difference)...

thanks...


Dmitriy Kopylenko-3 wrote
Use 'withTransaction' dynamic method of GORM-enhanced model class which
takes a closure passing in an instance of a Spring's TransactionStatus e.g.

MyModelClass.withTransaction { txStatus ->
    obj1.save()
    obj2.save()
}



2007/12/8, jnl1 <itsJim01@yahoo.com>:
>
>
> hi all...
>
>    within a controller operations, i need to save 2 objects.  they both
> either succeed or both fail (one transaction).   how does a controller
> handle transactions?  according to graeme's book, a you can set the
> transaction level on a service, but do I need to create a service in order
> to accomplish saving 2 objects within a controller within a single
> transaction ?
>
> thanks in adv...
>
> --
> View this message in context:
> http://www.nabble.com/newbie-transaction-question-tp14235128p14235128.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

Re: newbie transaction question

Dmitriy Kopylenko-3
Well, it's a more of a bigger architectural style, etc. There is no rule of thumb, etc., but for example if you have a large chunk of a [application] logic, etc. you'd better off abstract it as a "service" (some call it "service facade"). This way you also get a level of reuse, opportunity to expose the service as a "remote" invokable artifact (in SOA, ROA, etc. fashion), etc.

On the other hand if you have a need to execute some small piece of code transactionally as a part of let's say Grails Controller's action workflow, the 'withTransaction' method should suffice.

But again, it's my my own take, and you should see for yourself, what fits best in your own cases. [trust but verify] :-)

Cheers,
Dmitriy.

2007/12/9, jnl1 <[hidden email]>:

thanks Dmitriy...i tried your example and it works like a champ.  also got a
service working.

does anyone have a ptr to which is preferred a service or closure ? (I'm
assuming they have some difference)...

thanks...



Dmitriy Kopylenko-3 wrote:

>
> Use 'withTransaction' dynamic method of GORM-enhanced model class which
> takes a closure passing in an instance of a Spring's TransactionStatus
> e.g.
>
> MyModelClass.withTransaction { txStatus ->
>     obj1.save()
>     obj2.save()
> }
>
>
>
> 2007/12/8, jnl1 <[hidden email]>:
>>
>>
>> hi all...
>>
>>    within a controller operations, i need to save 2 objects.  they both
>> either succeed or both fail (one transaction).   how does a controller
>> handle transactions?  according to graeme's book, a you can set the
>> transaction level on a service, but do I need to create a service in
>> order
>> to accomplish saving 2 objects within a controller within a single
>> transaction ?
>>
>> thanks in adv...
>>
>> --
>> View this message in context:
>> http://www.nabble.com/newbie-transaction-question-tp14235128p14235128.html
>> Sent from the grails - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>
>

--
View this message in context: http://www.nabble.com/newbie-transaction-question-tp14235128p14245956.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

TagLib g:checkBox Improperly Overrides HTML "value" parameter - resurrected

jens.riboe
I'm using Grails 1.0-RC1 and stumbled on the g:checkBox tag, which seems
to treat all non-zero values of the 'value' attribute as CHECKED.
This has been resolved in the past according to JIRA
(http://jira.codehaus.org/browse/GRAILS-1237) in 0.6-RC1, but apparently
not in 1.0-RC1.
Any comments? Am I missing something?

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email