Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two phase commit question !

 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a few transactions that i want all to commit or none. These transactions are in different classes and retrieve their own connection objects and for now calling commit on their connection object.
I would appreciate if anyone could tell me how to join them together in one main class and apply the two phase commit on them. Following is the example of my scenario

Class 1 & 2 Performing inserts in the following way

Class 3 to join the two inserts from Class1 & 2


this code does not work well. Can someone tell me what changes should i make to make it work.
Thanks alot
GUL
 
Bhupendra Malviya
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gul,
Modify your code to do the following,
1: Modify insert function to return the result(ie res ) of execute statement
2: Use con.commit in your third class depending on the values returned by class 1 and class2
ie if(res1 && res2)
{
then commit 2 statements from class1 and class2;
}
else
rollback
I hope it works...
Bhupendra Malviya
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying. the problem is that both the classes have different Connection objects. to commit them on using if statement, i will have to pass back the connection object and than call con.commit on that, which is what i m trying to avoid.
GUL
 
Bhupendra Malviya
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other thing that you can try is ...
Instead of using local connection object pass a connection object reference from class 3 to class 1 & 2.
Bhupendra
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yah that works, i have created a utility class to perform the database operations like running the query and getting the connection.. now i m passing the class reference to the other classes 1&2 where they can retrieve the current connection.
This way i can easily maintain one connection in all the classes without clogging up the code, i think.
Thanks again for the reply and helping
GUL
 
Shankar sanjay
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gul,

Still i am not clear, Can you please send the three class files?

removed@removed

thanks.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at the UseTheForumNotEmail and RespectYourCoranchersPrivacy pages (just click them).

Anyway, this conversation is over eight years old; I'm not sure the people who participated in this thread are still around.

Also, consider removing your email address from your post, unless you want to get a ton of spam. Spam bots are harvesting email addresses from public pages aggressively.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic