You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Navjot Singh <na...@net4india.net> on 2003/06/12 17:14:17 UTC

[OT] Transaction Safe Java Code

Hi List,

I have 2 methods that i am calling in same sequence.

+ txnMethod1()
+ txnMethod2()

I wish either both of them get _executed_ or none of them.

Can i rollback the state to what was before method1's 
_execution_ if method2 fails?

Is it possible or i should start thinking simple?

---------------
regards
Navjot Singh
Net4India Ltd.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Transaction Safe Java Code

Posted by Erik Price <ep...@ptc.com>.

Johan wrote:
> Maybe to simple :-)
> consider the following snippet
> 
> int x = 0;
> try {
>     x=x+10;
>     x=x+10;
>     somethingMightThrowingAnException(x);
>     x=x+10;
> } catch (Exception e) {
> }
> 
> if somethingMightThrowingAnException(x) is not throwing an exception x 
> would be 30 in the end. but if somethingMightThrowingAnException(x) is 
> throwing an exception the value of x=20. For the transaction it should 
> be 0.

True, but I was trying to say that there's nothing in the JLS to do what 
the OP wants... the closes thing it offers is the exception mechanism.

> I think you need a transactionmanager to solve this problem.

Yes, that's got to be the best advice yet.




Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] Transaction Safe Java Code

Posted by Navjot Singh <na...@net4india.net>.
thanks john,

Your example was too simple in my case as this is stuff i used to do when i
ams stuck with such cases.
Guess all(ok, not all ;-) of us think alike more or less :-)

But now it was something different so couldn't rely on this way.

Thanks for the links.
-navjot


|-----Original Message-----
|From: Johan [mailto:java_dev@nilling.nl]
|Sent: Thursday, June 12, 2003 11:53 PM
|To: Struts Users Mailing List
|Subject: Re: [OT] Transaction Safe Java Code
|
|
|Just found something of interest
|http://www.objectweb.org/jotm
|http://www.objectweb.org/jotm/current/jotm/doc/howto-tomcat-jotm.html
|
|A opensource transactionmanager which you can use to solve your problem.
|
|Johan
|
|Johan wrote:
|> Maybe to simple :-)
|> consider the following snippet
|>
|> int x = 0;
|> try {
|>     x=x+10;
|>     x=x+10;
|>     somethingMightThrowingAnException(x);
|>     x=x+10;
|> } catch (Exception e) {
|> }
|>
|> if somethingMightThrowingAnException(x) is not throwing an exception x
|> would be 30 in the end. but if somethingMightThrowingAnException(x) is
|> throwing an exception the value of x=20. For the transaction it should
|> be 0.
|>
|> I think you need a transactionmanager to solve this problem.
|>
|> Johan
|>
|> Erik Price wrote:
|>
|>>
|>>
|>> Navjot Singh wrote:
|>>
|>>> Hi List,
|>>>
|>>> I have 2 methods that i am calling in same sequence.
|>>>
|>>> + txnMethod1()
|>>> + txnMethod2()
|>>>
|>>> I wish either both of them get _executed_ or none of them.
|>>>
|>>> Can i rollback the state to what was before method1's _execution_ if
|>>> method2 fails?
|>>>
|>>> Is it possible or i should start thinking simple?
|>>
|>>
|>>
|>> Think simple: throw an exception.
|>>
|>>
|>>
|>> Erik
|>>
|>>
|>> ---------------------------------------------------------------------
|>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
|>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
|>>
|>>
|>
|>
|
|
|--
|Nilling Software Design
|Postbus 43
|2280 AA  Rijswijk ZH
|w: http://www.nilling.nl
|
|
|---------------------------------------------------------------------
|To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
|For additional commands, e-mail: struts-user-help@jakarta.apache.org
|
|


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Transaction Safe Java Code

Posted by Johan <ja...@nilling.nl>.
Just found something of interest
http://www.objectweb.org/jotm
http://www.objectweb.org/jotm/current/jotm/doc/howto-tomcat-jotm.html

A opensource transactionmanager which you can use to solve your problem.

Johan

Johan wrote:
> Maybe to simple :-)
> consider the following snippet
> 
> int x = 0;
> try {
>     x=x+10;
>     x=x+10;
>     somethingMightThrowingAnException(x);
>     x=x+10;
> } catch (Exception e) {
> }
> 
> if somethingMightThrowingAnException(x) is not throwing an exception x 
> would be 30 in the end. but if somethingMightThrowingAnException(x) is 
> throwing an exception the value of x=20. For the transaction it should 
> be 0.
> 
> I think you need a transactionmanager to solve this problem.
> 
> Johan
> 
> Erik Price wrote:
> 
>>
>>
>> Navjot Singh wrote:
>>
>>> Hi List,
>>>
>>> I have 2 methods that i am calling in same sequence.
>>>
>>> + txnMethod1()
>>> + txnMethod2()
>>>
>>> I wish either both of them get _executed_ or none of them.
>>>
>>> Can i rollback the state to what was before method1's _execution_ if 
>>> method2 fails?
>>>
>>> Is it possible or i should start thinking simple?
>>
>>
>>
>> Think simple: throw an exception.
>>
>>
>>
>> Erik
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
> 
> 


-- 
Nilling Software Design
Postbus 43
2280 AA  Rijswijk ZH
w: http://www.nilling.nl


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Transaction Safe Java Code

Posted by Johan <ja...@nilling.nl>.
Maybe to simple :-)
consider the following snippet

int x = 0;
try {
	x=x+10;
	x=x+10;
	somethingMightThrowingAnException(x);
	x=x+10;
} catch (Exception e) {
}

if somethingMightThrowingAnException(x) is not throwing an exception x 
would be 30 in the end. but if somethingMightThrowingAnException(x) is 
throwing an exception the value of x=20. For the transaction it should 
be 0.

I think you need a transactionmanager to solve this problem.

Johan

Erik Price wrote:
> 
> 
> Navjot Singh wrote:
> 
>> Hi List,
>>
>> I have 2 methods that i am calling in same sequence.
>>
>> + txnMethod1()
>> + txnMethod2()
>>
>> I wish either both of them get _executed_ or none of them.
>>
>> Can i rollback the state to what was before method1's _execution_ if 
>> method2 fails?
>>
>> Is it possible or i should start thinking simple?
> 
> 
> Think simple: throw an exception.
> 
> 
> 
> Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


-- 
Nilling Software Design
Postbus 43
2280 AA  Rijswijk ZH
w: http://www.nilling.nl


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Transaction Safe Java Code

Posted by Erik Price <ep...@ptc.com>.

Navjot Singh wrote:
> Hi List,
> 
> I have 2 methods that i am calling in same sequence.
> 
> + txnMethod1()
> + txnMethod2()
> 
> I wish either both of them get _executed_ or none of them.
> 
> Can i rollback the state to what was before method1's 
> _execution_ if method2 fails?
> 
> Is it possible or i should start thinking simple?

Think simple: throw an exception.



Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] Transaction Safe Java Code

Posted by Navjot Singh <na...@net4india.net>.
Guess you have understood in wrong way.

Both are NOT data base methods, they could be any Java methods. I am not
talkin database txns. it's java transactions !!
I hope it make it clear.

-navjot singh


|-----Original Message-----
|From: Ravi Kora [mailto:rkora@1bigthink.com]
|Sent: Thursday, June 12, 2003 9:12 PM
|To: 'Struts Users Mailing List'
|Subject: RE: [OT] Transaction Safe Java Code
|
|
|If you r using the same connection for both the methods, then u can
|rollback. I wud suggest you to do sth like this
|Main method()
|{
|Open ur connection
|  Method1(pass connection object);
|  Method2(pass connection object);
| Rollback or commit the connection based on ur exceptions etc.
|Close the connection
|}
|
|I guess the above shud be doable.
|-Ravi
|
|> -----Original Message-----
|> From: Navjot Singh [mailto:navjot.s@net4india.net]
|> Sent: Thursday, June 12, 2003 11:14 AM
|> To: Struts Users Mailing List
|> Subject: [OT] Transaction Safe Java Code
|>
|>
|> Hi List,
|>
|> I have 2 methods that i am calling in same sequence.
|>
|> + txnMethod1()
|> + txnMethod2()
|>
|> I wish either both of them get _executed_ or none of them.
|>
|> Can i rollback the state to what was before method1's
|> _execution_ if method2 fails?
|>
|> Is it possible or i should start thinking simple?
|>
|> ---------------
|> regards
|> Navjot Singh
|> Net4India Ltd.
|>
|>
|> ---------------------------------------------------------------------
|> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
|> For additional commands, e-mail: struts-user-help@jakarta.apache.org
|>
|>
|
|
|
|---------------------------------------------------------------------
|To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
|For additional commands, e-mail: struts-user-help@jakarta.apache.org
|
|


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] Transaction Safe Java Code

Posted by Ravi Kora <rk...@1bigthink.com>.
If you r using the same connection for both the methods, then u can
rollback. I wud suggest you to do sth like this
Main method()
{
Open ur connection
  Method1(pass connection object);
  Method2(pass connection object);
 Rollback or commit the connection based on ur exceptions etc.
Close the connection
}

I guess the above shud be doable.
-Ravi

> -----Original Message-----
> From: Navjot Singh [mailto:navjot.s@net4india.net] 
> Sent: Thursday, June 12, 2003 11:14 AM
> To: Struts Users Mailing List
> Subject: [OT] Transaction Safe Java Code
> 
> 
> Hi List,
> 
> I have 2 methods that i am calling in same sequence.
> 
> + txnMethod1()
> + txnMethod2()
> 
> I wish either both of them get _executed_ or none of them.
> 
> Can i rollback the state to what was before method1's 
> _execution_ if method2 fails?
> 
> Is it possible or i should start thinking simple?
> 
> ---------------
> regards
> Navjot Singh
> Net4India Ltd.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org