001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc.sql;
019
020import java.sql.Connection;
021import java.sql.SQLException;
022
023import net.sf.hajdbc.DatabaseCluster;
024
025/**
026 * @author Paul Ferraro
027 */
028public class DataSource extends CommonDataSource<javax.sql.DataSource, DataSourceDatabase, DataSourceProxyFactory> implements javax.sql.DataSource
029{
030        /**
031         * Constructs a new DataSource
032         */
033        public DataSource()
034        {
035                super(DataSourceDatabaseClusterConfiguration.class);
036        }
037
038        @Override
039        public DataSourceProxyFactory createProxyFactory(DatabaseCluster<javax.sql.DataSource, DataSourceDatabase> cluster)
040        {
041                return new DataSourceProxyFactory(cluster);
042        }
043
044        /**
045         * @see javax.sql.DataSource#getConnection()
046         */
047        @Override
048        public Connection getConnection() throws SQLException
049        {
050                String user = this.getUser();
051                return (user != null) ? this.getProxy().getConnection(user, this.getPassword()) : this.getProxy().getConnection();
052        }
053
054        /**
055         * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
056         */
057        @Override
058        public Connection getConnection(String user, String password) throws SQLException
059        {
060                return this.getProxy().getConnection(user, password);
061        }
062
063        /**
064         * @see java.sql.Wrapper#isWrapperFor(java.lang.Class)
065         */
066        @Override
067        public boolean isWrapperFor(Class<?> targetClass) throws SQLException
068        {
069                return this.getProxy().isWrapperFor(targetClass);
070        }
071
072        /**
073         * @see java.sql.Wrapper#unwrap(java.lang.Class)
074         */
075        @Override
076        public <T> T unwrap(Class<T> targetClass) throws SQLException
077        {
078                return this.getProxy().unwrap(targetClass);
079        }
080}