All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cloud.piranha.extension.datasource.XADataSourceWrapper Maven / Gradle / Ivy

There is a newer version: 25.1.0
Show newest version
/*
 * Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *   3. Neither the name of the copyright holder nor the names of its
 *      contributors may be used to endorse or promote products derived from
 *      this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package cloud.piranha.extension.datasource;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.ShardingKeyBuilder;
import java.util.logging.Logger;

import javax.sql.DataSource;
import javax.sql.XAConnection;
import javax.sql.XADataSource;

/**
 * Wrapper for an XADataSource, that implements DataSource as well.
 *
 * 

* This wrapper can be specifically used in places where a DataSource is required but an XADataSource * is available. * * @author Arjan Tijms * */ public class XADataSourceWrapper implements DataSource, XADataSource { /** * The data source wrapped by this wrapper */ private XADataSource wrapped; /** * Creates a wrapper with the given data source * * @param wrapped the data source being wrapped */ public XADataSourceWrapper(XADataSource wrapped) { this.wrapped = wrapped; } /** * Return the data source being wrapped * @return the wrapped data source */ public XADataSource getWrapped() { return wrapped; } @Override public T unwrap(Class iface) throws SQLException { if (!isWrapperFor(iface)) { throw new SQLException("Can not unwrap for " + iface); } return (T) wrapped; } @Override public boolean isWrapperFor(Class iface) throws SQLException { return iface != null && iface.isAssignableFrom(wrapped.getClass()); } @Override public Connection getConnection() throws SQLException { return getXAConnection().getConnection(); } @Override public Connection getConnection(String username, String password) throws SQLException { return getXAConnection(username, password).getConnection(); } @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { return wrapped.getParentLogger(); } @Override public PrintWriter getLogWriter() throws SQLException { return wrapped.getLogWriter(); } @Override public void setLogWriter(PrintWriter out) throws SQLException { wrapped.setLogWriter(out); } @Override public void setLoginTimeout(int seconds) throws SQLException { wrapped.setLoginTimeout(seconds); } @Override public int getLoginTimeout() throws SQLException { return wrapped.getLoginTimeout(); } @Override public ShardingKeyBuilder createShardingKeyBuilder() throws SQLException { return wrapped.createShardingKeyBuilder(); } @Override public XAConnection getXAConnection() throws SQLException { return wrapped.getXAConnection(); } @Override public XAConnection getXAConnection(String user, String password) throws SQLException { return wrapped.getXAConnection(user, password); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy