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.pool.sql; 019 020import java.io.PrintWriter; 021import java.sql.Connection; 022import java.sql.DriverManager; 023import java.sql.SQLException; 024import java.util.logging.Logger; 025 026import javax.sql.ConnectionPoolDataSource; 027import javax.sql.PooledConnection; 028 029/** 030 * @author Paul Ferraro 031 */ 032public class DriverConnectionPoolDataSource implements ConnectionPoolDataSource 033{ 034 String url; 035 036 /** 037 * {@inheritDoc} 038 * @see javax.sql.ConnectionPoolDataSource#getPooledConnection() 039 */ 040 @Override 041 public PooledConnection getPooledConnection() 042 { 043 ConnectionFactory factory = new ConnectionFactory() 044 { 045 @Override 046 public Connection getConnection() throws SQLException 047 { 048 return DriverManager.getConnection(DriverConnectionPoolDataSource.this.url); 049 } 050 }; 051 052 return new DriverPooledConnection(factory); 053 } 054 055 /** 056 * {@inheritDoc} 057 * @see javax.sql.ConnectionPoolDataSource#getPooledConnection(java.lang.String, java.lang.String) 058 */ 059 @Override 060 public PooledConnection getPooledConnection(final String user, final String password) 061 { 062 ConnectionFactory factory = new ConnectionFactory() 063 { 064 @Override 065 public Connection getConnection() throws SQLException 066 { 067 return DriverManager.getConnection(DriverConnectionPoolDataSource.this.url, user, password); 068 } 069 }; 070 071 return new DriverPooledConnection(factory); 072 } 073 074 /** 075 * {@inheritDoc} 076 * @see javax.sql.CommonDataSource#getLogWriter() 077 */ 078 @Override 079 public PrintWriter getLogWriter() 080 { 081 // TODO Auto-generated method stub 082 return null; 083 } 084 085 /** 086 * {@inheritDoc} 087 * @see javax.sql.CommonDataSource#getLoginTimeout() 088 */ 089 @Override 090 public int getLoginTimeout() 091 { 092 // TODO Auto-generated method stub 093 return 0; 094 } 095 096 /** 097 * {@inheritDoc} 098 * @see javax.sql.CommonDataSource#setLogWriter(java.io.PrintWriter) 099 */ 100 @Override 101 public void setLogWriter(PrintWriter arg0) 102 { 103 // TODO Auto-generated method stub 104 105 } 106 107 /** 108 * {@inheritDoc} 109 * @see javax.sql.CommonDataSource#setLoginTimeout(int) 110 */ 111 @Override 112 public void setLoginTimeout(int arg0) 113 { 114 // TODO Auto-generated method stub 115 116 } 117 118 /** 119 * {@inheritDoc} 120 * @see javax.sql.CommonDataSource#getParentLogger() 121 */ 122 @Override 123 public Logger getParentLogger() 124 { 125 // TODO Auto-generated method stub 126 return null; 127 } 128}