01: package jtaDiscRack.business;
02:
03: import javax.naming.Context;
04: import javax.naming.InitialContext;
05: import javax.transaction.UserTransaction;
06:
07: public class XaTransactionSupport {
08:
09: /**
10: * Transaction object reference
11: */
12: protected UserTransaction transaction = null;
13:
14: /**
15: * Method initializes DB transation instance
16: */
17: protected void initTransaction()
18: throws JtaDiscRackBusinessException {
19: try {
20: Context ctx = new InitialContext();
21: transaction = (UserTransaction) ctx
22: .lookup("java:comp/UserTransaction");
23: if (transaction != null) {
24: transaction.begin();
25: }
26: } catch (Exception ex) {
27: throw new JtaDiscRackBusinessException(
28: "Problems with UserTransaction begining!", ex);
29: }
30: }
31:
32: /**
33: * Method commits DB transation instance
34: */
35: protected void commitTransaction()
36: throws JtaDiscRackBusinessException {
37: try {
38: if (transaction != null) {
39: transaction.commit();
40: }
41: } catch (Exception ex) {
42: throw new JtaDiscRackBusinessException(
43: "Problems with UserTransaction commit!", ex);
44: }
45:
46: }
47:
48: protected void rollbackTransaction()
49: throws JtaDiscRackBusinessException {
50: try {
51: if (transaction != null) {
52: transaction.rollback();
53: }
54: } catch (Exception ex) {
55: throw new JtaDiscRackBusinessException(
56: "Problems with UserTransaction roolback!", ex);
57: }
58: }
59:
60: }
|