Announcement Announcement Module
Collapse
No announcement yet.
Passing parameters into TransactionTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing parameters into TransactionTemplate

    I'm trying to evaluate the pros/cons of the TransactionTemplate vs PlatformTransactionManager mechanisms for programmatic transaction management. From the API and the User Guide samples, I gather there is not an easy way to pass in data values to the TransactionTemplate's doInTransaction method.

    The simplest way I could think of is to create another class that takes the parameters in the constructor. For example,

    Code:
    public class MyUpdate implements TransactionCallbackWithoutResult {
       private int parm1;
       private int parm2;
       public MyUpdate(int parm1, int parm2) {
          this.parm1 = parm1;
          this.parm2 = parm2;
       }
    
       protected void doInTransactionWithoutResult(TransactionStatus status) {
          //  do stuff with parm1 and parm2
       }
    }
    Then I can use the TransactionTemplate as follows.

    Code:
    tt.execute(new MyUpdate(parm1, parm2));
    Is this what others are doing?

    Thanks,
    - Paul

  • #2
    Checkout the sample code - you can use inner classes (ad-hoc definitions) which will have visibility on the parent class variables.

    your class...
    some code..
    private int parm1;
    private int parm2;

    execute(new TransactionCallbackWithoutResult()
    {
    protected void doInTransactionWithoutResult(TransactionStatus status) {
    // do stuff with parm1 and parm2
    }
    });

    Comment

    Working...
    X