001: /*
002: * $Id: DataSourceWrapper.java 10489 2008-01-23 17:53:38Z dfeist $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.transport.jdbc.xa;
012:
013: import java.io.PrintWriter;
014: import java.sql.Connection;
015: import java.sql.SQLException;
016:
017: import javax.sql.DataSource;
018: import javax.sql.XADataSource;
019: import javax.transaction.TransactionManager;
020:
021: /**
022: * Using for unification XADataSource and DataSource
023: */
024: public class DataSourceWrapper implements DataSource {
025:
026: private XADataSource xaDataSource;
027:
028: public DataSourceWrapper() {
029: super ();
030: }
031:
032: public DataSourceWrapper(XADataSource xaDataSource,
033: TransactionManager tm) {
034: this .xaDataSource = xaDataSource;
035: }
036:
037: /*
038: * (non-Javadoc)
039: *
040: * @see javax.sql.DataSource#getLoginTimeout()
041: */
042: public int getLoginTimeout() throws SQLException {
043: return xaDataSource.getLoginTimeout();
044: }
045:
046: /*
047: * (non-Javadoc)
048: *
049: * @see javax.sql.DataSource#setLoginTimeout(int)
050: */
051: public void setLoginTimeout(int seconds) throws SQLException {
052: xaDataSource.setLoginTimeout(seconds);
053: }
054:
055: /*
056: * (non-Javadoc)
057: *
058: * @see javax.sql.DataSource#getLogWriter()
059: */
060: public PrintWriter getLogWriter() throws SQLException {
061: return xaDataSource.getLogWriter();
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
068: */
069: public void setLogWriter(PrintWriter out) throws SQLException {
070: xaDataSource.setLogWriter(out);
071: }
072:
073: /*
074: * (non-Javadoc)
075: *
076: * @see javax.sql.DataSource#getConnection()
077: */
078: public Connection getConnection() throws SQLException {
079: final Connection connWrapper = new ConnectionWrapper(
080: xaDataSource.getXAConnection());
081: connWrapper.setAutoCommit(false);
082: return connWrapper;
083: }
084:
085: /*
086: * (non-Javadoc)
087: *
088: * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
089: */
090: public Connection getConnection(String username, String password)
091: throws SQLException {
092: final Connection connWrapper = new ConnectionWrapper(
093: xaDataSource.getXAConnection(username, password));
094: connWrapper.setAutoCommit(false);
095: return connWrapper;
096: }
097:
098: /**
099: * @return Returns the underlying XADataSource.
100: */
101: public XADataSource getXaDataSource() {
102: return xaDataSource;
103: }
104:
105: /**
106: * @param xads The XADataSource to set.
107: */
108: public void setXaDataSource(XADataSource xads) {
109: this.xaDataSource = xads;
110: }
111: }
|