View Javadoc

1   /*
2    * $Id: DataSourceWrapper.java 19209 2010-08-26 05:15:09Z 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  import javax.transaction.TransactionManager;
20  
21  /**
22   * Using for unification XADataSource and DataSource
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)
35      {
36          this.xaDataSource = xaDataSource;
37      }
38  
39      public int getLoginTimeout() throws SQLException
40      {
41          return xaDataSource.getLoginTimeout();
42      }
43  
44      public void setLoginTimeout(int seconds) throws SQLException
45      {
46          xaDataSource.setLoginTimeout(seconds);
47      }
48  
49      public PrintWriter getLogWriter() throws SQLException
50      {
51          return xaDataSource.getLogWriter();
52      }
53  
54      public void setLogWriter(PrintWriter out) throws SQLException
55      {
56          xaDataSource.setLogWriter(out);
57      }
58  
59      public Connection getConnection() throws SQLException
60      {
61          return new ConnectionWrapper(xaDataSource.getXAConnection());
62      }
63  
64      public Connection getConnection(String username, String password) throws SQLException
65      {
66          return new ConnectionWrapper(xaDataSource.getXAConnection(username, password));    
67      }
68  
69      /**
70       * @return Returns the underlying XADataSource.
71       */
72      public XADataSource getXaDataSource()
73      {
74          return xaDataSource;
75      }
76  
77      /**
78       * @param xads The XADataSource to set.
79       */
80      public void setXaDataSource(XADataSource xads)
81      {
82          this.xaDataSource = xads;
83      }
84  
85      public boolean isWrapperFor(Class<?> iface) throws SQLException
86      {
87          return false;
88      }
89  
90      public <T> T unwrap(Class<T> iface) throws SQLException
91      {
92          return null;
93      }
94  
95  }