From 7fd065b8e1c6650b3d17d89c49162c39ea118d59 Mon Sep 17 00:00:00 2001 From: fhanik Date: Tue, 25 Nov 2008 23:37:00 +0000 Subject: [PATCH] Remove the Driver class, its not used anymore, and if it was used, there needs to be a way to instantiate from a properties file or similar git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@720668 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tomcat/jdbc/pool/DataSourceProxy.java | 32 +++--- .../java/org/apache/tomcat/jdbc/pool/Driver.java | 121 --------------------- 2 files changed, 16 insertions(+), 137 deletions(-) delete mode 100644 modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java index c5bb1fc12..0391001c7 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java @@ -41,7 +41,7 @@ import org.apache.juli.logging.LogFactory; public class DataSourceProxy { protected static Log log = LogFactory.getLog(DataSourceProxy.class); - protected Driver driver; + protected volatile ConnectionPool pool = null; protected PoolProperties poolProperties = new PoolProperties(); public DataSourceProxy() { @@ -75,12 +75,12 @@ public class DataSourceProxy { * @return Driver * @throws SQLException */ - public synchronized Driver createDriver() throws SQLException { - if (driver != null) { - return driver; + public synchronized ConnectionPool createPool() throws SQLException { + if (pool != null) { + return pool; } else { - driver = new org.apache.tomcat.jdbc.pool.Driver(getPoolProperties()); - return driver; + pool = new ConnectionPool(poolProperties); + return pool; } } @@ -89,9 +89,9 @@ public class DataSourceProxy { */ public Connection getConnection() throws SQLException { - if (driver == null) - driver = createDriver(); - return driver.connect(poolProperties.getPoolName(), null); + if (pool == null) + return createPool().getConnection(); + return pool.getConnection(); } /** @@ -151,10 +151,10 @@ public class DataSourceProxy { } public void close(boolean all) { try { - if (driver != null) { - Driver d = driver; - driver = null; - d.closePool(poolProperties.getPoolName(), all); + if (pool != null) { + final ConnectionPool p = pool; + pool = null; + if (p!=null) p.close(all); } }catch (Exception x) { x.printStackTrace(); @@ -167,9 +167,9 @@ public class DataSourceProxy { } public int getPoolSize() throws SQLException{ - if (driver == null) - driver = createDriver(); - return driver.getPool(getPoolProperties().getPoolName()).getSize(); + final ConnectionPool p = pool; + if (p == null) return 0; + else return p.getSize(); } public String toString() { diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java deleted file mode 100644 index 85d38618b..000000000 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.tomcat.jdbc.pool; - - -import java.sql.Connection; -import java.sql.DriverPropertyInfo; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Properties; - -import org.apache.juli.logging.Log; -import org.apache.juli.logging.LogFactory; -/** - * @author Filip Hanik - * @version 1.0 - */ -public class Driver implements java.sql.Driver { - - protected static Log log = LogFactory.getLog(Driver.class); - - protected static HashMap pooltable = new HashMap(11); - - public Driver() throws SQLException { - } - - public Driver(PoolProperties properties) throws SQLException { - init(properties); - } //Driver - - public void init(PoolProperties properties) throws SQLException { - if (pooltable.get(properties.getPoolName()) != null) - throw new SQLException("Pool identified by:" + properties.getPoolName() + " already exists."); - ConnectionPool pool = new ConnectionPool(properties); - pooltable.put(properties.getPoolName(), pool); - } - - public void closePool(String url, boolean all) throws SQLException { - ConnectionPool pool = (ConnectionPool) pooltable.get(url); - if (pool == null) { - throw new SQLException("No connection pool established for URL:" + url); - } else { - pool.close(all); - } - pooltable.remove(url); - } - - /** - * {@inheritDoc} - */ - public Connection connect(String url, Properties info) throws SQLException { - ConnectionPool pool = (ConnectionPool) pooltable.get(url); - if (pool == null) { - throw new SQLException("No connection pool established for URL:" + url); - } else { - try { - return pool.getConnection(); - } catch (SQLException forward) { - throw forward; - } catch (Exception e) { - throw new SQLException("Unknow pool exception:" + ConnectionPool.getStackTrace(e)); - } //catch - } //end if - } //connect - - /** - * {@inheritDoc} - */ - public boolean acceptsURL(String url) throws SQLException { - /* check if the driver has a connection pool with that name */ - return (pooltable.get(url) != null ? true : false); - } //acceptsUrl - - /** - * {@inheritDoc} - */ - public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws - SQLException { - return new DriverPropertyInfo[0]; - } //getPropertyInfo - - /** - * {@inheritDoc} - */ - public int getMajorVersion() { - return 1; - } - - /** - * {@inheritDoc} - */ - public int getMinorVersion() { - return 0; - } - - /** - * {@inheritDoc} - */ - public boolean jdbcCompliant() { - return true; - } - - public ConnectionPool getPool(String url) throws SQLException { - return (ConnectionPool) pooltable.get(url); - } - -} //class -- 2.11.0