View Javadoc

1   /*
2    * $Id: DataSourceWrapper.java 22409 2011-07-14 05:14:27Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.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  
20  /**
21   * Using for unification XADataSource and DataSource
22   */
23  public class DataSourceWrapper implements DataSource
24  {
25  
26      private XADataSource xaDataSource;
27  
28      public DataSourceWrapper()
29      {
30          super();
31      }
32  
33      public DataSourceWrapper(XADataSource xaDataSource)
34      {
35          this.xaDataSource = xaDataSource;
36      }
37  
38      @Override
39      public int getLoginTimeout() throws SQLException
40      {
41          return xaDataSource.getLoginTimeout();
42      }
43  
44      @Override
45      public void setLoginTimeout(int seconds) throws SQLException
46      {
47          xaDataSource.setLoginTimeout(seconds);
48      }
49  
50      @Override
51      public PrintWriter getLogWriter() throws SQLException
52      {
53          return xaDataSource.getLogWriter();
54      }
55  
56      @Override
57      public void setLogWriter(PrintWriter out) throws SQLException
58      {
59          xaDataSource.setLogWriter(out);
60      }
61  
62      @Override
63      public Connection getConnection() throws SQLException
64      {
65          return new ConnectionWrapper(xaDataSource.getXAConnection());
66      }
67  
68      @Override
69      public Connection getConnection(String username, String password) throws SQLException
70      {
71          return new ConnectionWrapper(xaDataSource.getXAConnection(username, password));
72      }
73  
74      /**
75       * @return Returns the underlying XADataSource.
76       */
77      public XADataSource getXaDataSource()
78      {
79          return xaDataSource;
80      }
81  
82      /**
83       * @param xads The XADataSource to set.
84       */
85      public void setXaDataSource(XADataSource xads)
86      {
87          this.xaDataSource = xads;
88      }
89  
90      @Override
91      public boolean isWrapperFor(Class<?> iface) throws SQLException
92      {
93          return false;
94      }
95  
96      @Override
97      public <T> T unwrap(Class<T> iface) throws SQLException
98      {
99          return null;
100     }
101 
102 }