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