What's the best way to have a set of calls be part of a single (DB) transaction?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kurt_B
Posted On:   Wednesday, April 20, 2005 11:18 PM

What's the best way to have a set of calls be part of a single transaction? I have a DB powered web app and a number of methods that I call need to be done as part of a transction. Currently this is how I'm doing things: // Object in the model public class MyClass { method1(java.sql.Connection con) {logic and sql commands....} method2(java.sql.Connection con) {logic and sql commands....} } // Structs Action - accept user input and modify objects in the model public class MyStrutsAction { ...... public void execute(......) { java.sql.Connection con = getConnection();    More>>

What's the best way to have a set of calls be part of a single transaction?


I have a DB powered web app and a number of methods that I call need to be done as part of a transction.


Currently this is how I'm doing things:



// Object in the model

public class MyClass {



method1(java.sql.Connection con) {logic and sql commands....}

method2(java.sql.Connection con) {logic and sql commands....}

}



// Structs Action - accept user input and modify objects in the model

public class MyStrutsAction {

......

public void execute(......) {

java.sql.Connection con = getConnection();

con.setAutoCommit(false);



MyClass mc = new MyClass();

mc.method1(con);

mc.method2(con);



con.commit();

con.close();

}

}


Is there a better way to have a block of method calls all use the same DB transaction but NOT have to pass the DB connection object to all of my methods?

- Kurt

   <<Less
About | Sitemap | Contact