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.pool;
019
020import java.sql.SQLException;
021
022import javax.sql.PooledConnection;
023
024import net.sf.hajdbc.DatabaseCluster;
025import net.sf.hajdbc.sql.CommonDataSource;
026
027/**
028 * @author Paul Ferraro
029 *
030 */
031public class ConnectionPoolDataSource extends CommonDataSource<javax.sql.ConnectionPoolDataSource, ConnectionPoolDataSourceDatabase, ConnectionPoolDataSourceProxyFactory> implements javax.sql.ConnectionPoolDataSource
032{
033        /**
034         * Constructs a new ConnectionPoolDataSource
035         */
036        public ConnectionPoolDataSource()
037        {
038                super(ConnectionPoolDataSourceDatabaseClusterConfiguration.class);
039        }
040
041        @Override
042        public ConnectionPoolDataSourceProxyFactory createProxyFactory(DatabaseCluster<javax.sql.ConnectionPoolDataSource, ConnectionPoolDataSourceDatabase> cluster)
043        {
044                return new ConnectionPoolDataSourceProxyFactory(cluster);
045        }
046
047        /**
048         * @see javax.sql.ConnectionPoolDataSource#getPooledConnection()
049         */
050        @Override
051        public PooledConnection getPooledConnection() throws SQLException
052        {
053                String user = this.getUser();
054                return (user != null) ? this.getProxy().getPooledConnection(user, this.getPassword()) : this.getProxy().getPooledConnection();
055        }
056
057        /**
058         * @see javax.sql.ConnectionPoolDataSource#getPooledConnection(java.lang.String, java.lang.String)
059         */
060        @Override
061        public PooledConnection getPooledConnection(String user, String password) throws SQLException
062        {
063                return this.getProxy().getPooledConnection(user, password);
064        }
065}