30e9b6660f5e7395612a159d12c2eb894b93cf8a
[JavaForFun] /
1 package de.spring.example;
2
3 import org.springframework.jdbc.datasource.DataSourceTransactionManager;
4 import org.springframework.transaction.TransactionStatus;
5
6
7 public class TransactionManagerN2A {
8         private static TransactionManagerN2A instance = new TransactionManagerN2A();
9         private DataSourceTransactionManager transactionManager;
10         private TransactionStatus transactionStatus;
11
12         //Why could you want to extend this class?
13         private TransactionManagerN2A() {}
14         
15         public static TransactionManagerN2A getInstance() {
16         return instance;
17         }
18         
19         public void initTransaction()
20         {
21                 transactionStatus = this.transactionManager.getTransaction(null);
22         }
23         
24         public void rollbackTransaction()
25         {
26                 this.transactionManager.rollback(this.transactionStatus);
27         }
28         
29         public void commitTransaction()
30         {
31                 this.transactionManager.commit(this.transactionStatus);
32         }
33         
34         
35         /************************* Setters and getters *******************************************/
36         public void setTransactionManager(final DataSourceTransactionManager  transactionManager) 
37         {
38                 this.transactionManager = transactionManager;
39         }
40 }
41