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 | 0 | super(); |
33 | 0 | } |
34 | |
|
35 | |
public DataSourceWrapper(XADataSource xads, TransactionManager tm) |
36 | 0 | { |
37 | 0 | this.xads = xads; |
38 | 0 | this.tm = tm; |
39 | 0 | } |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public int getLoginTimeout() throws SQLException |
47 | |
{ |
48 | 0 | return xads.getLoginTimeout(); |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public void setLoginTimeout(int seconds) throws SQLException |
57 | |
{ |
58 | 0 | xads.setLoginTimeout(seconds); |
59 | 0 | } |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public PrintWriter getLogWriter() throws SQLException |
67 | |
{ |
68 | 0 | return xads.getLogWriter(); |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public void setLogWriter(PrintWriter out) throws SQLException |
77 | |
{ |
78 | 0 | xads.setLogWriter(out); |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public Connection getConnection() throws SQLException |
87 | |
{ |
88 | 0 | final ConnectionWrapper connWrapper = new ConnectionWrapper(xads.getXAConnection(), tm); |
89 | 0 | connWrapper.setAutoCommit(false); |
90 | 0 | return connWrapper; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public Connection getConnection(String username, String password) throws SQLException |
99 | |
{ |
100 | 0 | final ConnectionWrapper connWrapper = new ConnectionWrapper(xads.getXAConnection(username, password), tm); |
101 | 0 | connWrapper.setAutoCommit(false); |
102 | 0 | return connWrapper; |
103 | |
} |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public TransactionManager getTransactionManager() |
109 | |
{ |
110 | 0 | return tm; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public void setTransactionManager(TransactionManager tm) |
117 | |
{ |
118 | 0 | this.tm = tm; |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public XADataSource getXaDataSource() |
125 | |
{ |
126 | 0 | return xads; |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public void setXaDataSource(XADataSource xads) |
133 | |
{ |
134 | 0 | this.xads = xads; |
135 | 0 | } |
136 | |
} |