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

org.javasimon.jdbcx4.WrappingSimonDataSource Maven / Gradle / Ivy

package org.javasimon.jdbcx4;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
import javax.sql.DataSource;

import org.javasimon.jdbc4.SimonConnection;
import org.javasimon.jdbc4.WrapperSupport;

/**
 * WrappingSimonDataSource allows to wrap existing datasource instead of providing
 * the Driver and URL information. For example - it can be used with Spring easily:
 * 
{@code
 * 
 *     
 *     
 * 
 *
 * 
 *     
 *     
 *     
 *     
 *     
 *     
 * }
* * @author Radovan Sninsky * @author Richard "Virgo" Richter * @since 2.4 */ public class WrappingSimonDataSource extends AbstractSimonDataSource implements DataSource { private DataSource ds; private WrapperSupport wrapperSupport; public DataSource getDataSource() { return ds; } public void setDataSource(DataSource ds) { this.ds = ds; this.wrapperSupport = new WrapperSupport<>(ds, DataSource.class); } /** * Attempts to establish a connection with the data source that this {@code DataSource} object represents. * * @return a connection to the data source * @throws SQLException if a database access error occurs */ @Override public Connection getConnection() throws SQLException { return new SimonConnection(getDataSource().getConnection(), getPrefix()); } /** * Attempts to establish a connection with the data source that this {@code DataSource} object represents. * * @param user the database user on whose behalf the connection is being made * @param password the user's password * @return a connection to the data source * @throws SQLException if a database access error occurs */ @Override public Connection getConnection(String user, String password) throws SQLException { return new SimonConnection(getDataSource().getConnection(user, password), getPrefix()); } @Override public T unwrap(Class iface) throws SQLException { return wrapperSupport.unwrap(iface); } @Override public boolean isWrapperFor(Class iface) throws SQLException { return wrapperSupport.isWrapperFor(iface); } @Override protected String doGetRealDataSourceClassName() { return this.configuration.getRealDataSourceName(); } @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { return ds.getParentLogger(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy