1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.jdbc.xa;
12
13 import java.io.PrintWriter;
14 import java.sql.Connection;
15 import java.sql.SQLException;
16
17 import javax.sql.DataSource;
18 import javax.sql.XADataSource;
19 import javax.transaction.TransactionManager;
20
21
22
23
24 public class DataSourceWrapper implements DataSource
25 {
26
27 private XADataSource xads;
28 private TransactionManager tm;
29
30 public DataSourceWrapper()
31 {
32 super();
33 }
34
35 public DataSourceWrapper(XADataSource xads, TransactionManager tm)
36 {
37 this.xads = xads;
38 this.tm = tm;
39 }
40
41
42
43
44
45
46 public int getLoginTimeout() throws SQLException
47 {
48 return xads.getLoginTimeout();
49 }
50
51
52
53
54
55
56 public void setLoginTimeout(int seconds) throws SQLException
57 {
58 xads.setLoginTimeout(seconds);
59 }
60
61
62
63
64
65
66 public PrintWriter getLogWriter() throws SQLException
67 {
68 return xads.getLogWriter();
69 }
70
71
72
73
74
75
76 public void setLogWriter(PrintWriter out) throws SQLException
77 {
78 xads.setLogWriter(out);
79 }
80
81
82
83
84
85
86 public Connection getConnection() throws SQLException
87 {
88 final ConnectionWrapper connWrapper = new ConnectionWrapper(xads.getXAConnection(), tm);
89 connWrapper.setAutoCommit(false);
90 return connWrapper;
91 }
92
93
94
95
96
97
98 public Connection getConnection(String username, String password) throws SQLException
99 {
100 final ConnectionWrapper connWrapper = new ConnectionWrapper(xads.getXAConnection(username, password), tm);
101 connWrapper.setAutoCommit(false);
102 return connWrapper;
103 }
104
105
106
107
108 public TransactionManager getTransactionManager()
109 {
110 return tm;
111 }
112
113
114
115
116 public void setTransactionManager(TransactionManager tm)
117 {
118 this.tm = tm;
119 }
120
121
122
123
124 public XADataSource getXaDataSource()
125 {
126 return xads;
127 }
128
129
130
131
132 public void setXaDataSource(XADataSource xads)
133 {
134 this.xads = xads;
135 }
136 }