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

com.tacitknowledge.util.migration.jdbc.util.ConnectionWrapperDataSource Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version
/* Copyright 2004 Tacit Knowledge
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tacitknowledge.util.migration.jdbc.util;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

/**
 * A partial DataSource implementation that simply wraps a single,
 * already opened Connection.
 * 

* Only the two getConnection methods are supported. * * @author Scott Askew ([email protected]) */ public class ConnectionWrapperDataSource implements DataSource { /** * The message used in UnsupportedOperationExceptions. */ public static final String UNSUPPORTED_OPERATION_EXCEPTION_MSG = ConnectionWrapperDataSource.class + " is not a fully functioning DataSource and only" + " supports the getConnection methods."; /** * The underlying connection */ private Connection connection = null; /** * Creates a new ConnectionWrapperDataSource. * * @param connection the connection to use for this data source */ public ConnectionWrapperDataSource(Connection connection) { this.connection = connection; } /** {@inheritDoc} */ public Connection getConnection() throws SQLException { return connection; } /** {@inheritDoc} */ public Connection getConnection(String user, String pass) throws SQLException { return connection; } /** {@inheritDoc} */ public PrintWriter getLogWriter() throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MSG); } /** {@inheritDoc} */ public void setLogWriter(PrintWriter arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MSG); } /** {@inheritDoc} */ public int getLoginTimeout() throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MSG); } /** {@inheritDoc} */ public void setLoginTimeout(int arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MSG); } /** {@inheritDoc} */ public boolean isWrapperFor(Class iface) { return connection != null && iface.isAssignableFrom(connection.getClass()); } /** {@inheritDoc} */ public Object unwrap(Class iface) { return connection; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy