You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2008/11/03 23:38:56 UTC

svn commit: r710199 [2/4] - in /tomcat/trunk/modules/jdbc-pool: ./ doc/ java/org/apache/tomcat/jdbc/pool/ java/org/apache/tomcat/jdbc/pool/jmx/ test/org/apache/tomcat/jdbc/test/

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java?rev=710199&r1=710198&r2=710199&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java Mon Nov  3 14:38:55 2008
@@ -1,436 +1,436 @@
-/*
- * 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.io.ByteArrayInputStream;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.sql.Connection;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.spi.ObjectFactory;
-import javax.sql.DataSource;
-
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-
-/**
- * <p>JNDI object factory that creates an instance of
- * <code>BasicDataSource</code> that has been configured based on the
- * <code>RefAddr</code> values of the specified <code>Reference</code>,
- * which must match the names and data types of the
- * <code>BasicDataSource</code> bean properties.</p>
- * <br/>
- * Properties available for configuration:<br/>
- * <a href="http://commons.apache.org/dbcp/configuration.html">Commons DBCP properties</a><br/>
- *<ol>
- *  <li>initSQL - A query that gets executed once, right after the connection is established.</li>
- *  <li>testOnConnect - run validationQuery after connection has been established.</li>
- *  <li>validationInterval - avoid excess validation, only run validation at most at this frequency - time in milliseconds.</li>
- *  <li>jdbcInterceptors - a semicolon separated list of classnames extending {@link JdbcInterceptor} class.</li>
- *  <li>jmxEnabled - true of false, whether to register the pool with JMX.</li>
- *  <li>fairQueue - true of false, whether the pool should sacrifice a little bit of performance for true fairness.</li>
- *</ol>
- * @author Craig R. McClanahan
- * @author Dirk Verbeeck
- * @author Filip Hanik
- */
-public class DataSourceFactory implements ObjectFactory {
-    protected static Log log = LogFactory.getLog(DataSourceFactory.class);
-
-    protected final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
-    protected final static String PROP_DEFAULTREADONLY = "defaultReadOnly";
-    protected final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
-    protected final static String PROP_DEFAULTCATALOG = "defaultCatalog";
-    
-    protected final static String PROP_DRIVERCLASSNAME = "driverClassName";
-    protected final static String PROP_PASSWORD = "password";
-    protected final static String PROP_URL = "url";
-    protected final static String PROP_USERNAME = "username";
-
-    protected final static String PROP_MAXACTIVE = "maxActive";
-    protected final static String PROP_MAXIDLE = "maxIdle";
-    protected final static String PROP_MINIDLE = "minIdle";
-    protected final static String PROP_INITIALSIZE = "initialSize";
-    protected final static String PROP_MAXWAIT = "maxWait";
-    
-    protected final static String PROP_TESTONBORROW = "testOnBorrow";
-    protected final static String PROP_TESTONRETURN = "testOnReturn";
-    protected final static String PROP_TESTWHILEIDLE = "testWhileIdle";
-    protected final static String PROP_TESTONCONNECT = "testOnConnect";
-    protected final static String PROP_VALIDATIONQUERY = "validationQuery";
-    
-    protected final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
-    protected final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
-    protected final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
-    
-    protected final static String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED = "accessToUnderlyingConnectionAllowed";
-    
-    protected final static String PROP_REMOVEABANDONED = "removeAbandoned";
-    protected final static String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout";
-    protected final static String PROP_LOGABANDONED = "logAbandoned";
-    
-    protected final static String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements";
-    protected final static String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements";
-    protected final static String PROP_CONNECTIONPROPERTIES = "connectionProperties";
-    
-    protected final static String PROP_INITSQL = "initSQL";
-    protected final static String PROP_INTERCEPTORS = "jdbcInterceptors";
-    protected final static String PROP_VALIDATIONINTERVAL = "validationInterval";
-    protected final static String PROP_JMX_ENABLED = "jmxEnabled";
-    protected final static String PROP_FAIR_QUEUE = "fairQueue";
-    
-    public static final int UNKNOWN_TRANSACTIONISOLATION = -1;
-
-
-    protected final static String[] ALL_PROPERTIES = {
-        PROP_DEFAULTAUTOCOMMIT,
-        PROP_DEFAULTREADONLY,
-        PROP_DEFAULTTRANSACTIONISOLATION,
-        PROP_DEFAULTCATALOG,
-        PROP_DRIVERCLASSNAME,
-        PROP_MAXACTIVE,
-        PROP_MAXIDLE,
-        PROP_MINIDLE,
-        PROP_INITIALSIZE,
-        PROP_MAXWAIT,
-        PROP_TESTONBORROW,
-        PROP_TESTONRETURN,
-        PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
-        PROP_NUMTESTSPEREVICTIONRUN,
-        PROP_MINEVICTABLEIDLETIMEMILLIS,
-        PROP_TESTWHILEIDLE,
-        PROP_TESTONCONNECT,
-        PROP_PASSWORD,
-        PROP_URL,
-        PROP_USERNAME,
-        PROP_VALIDATIONQUERY,
-        PROP_VALIDATIONINTERVAL,
-        PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
-        PROP_REMOVEABANDONED,
-        PROP_REMOVEABANDONEDTIMEOUT,
-        PROP_LOGABANDONED,
-        PROP_POOLPREPAREDSTATEMENTS,
-        PROP_MAXOPENPREPAREDSTATEMENTS,
-        PROP_CONNECTIONPROPERTIES,
-        PROP_INITSQL,
-        PROP_INTERCEPTORS,
-        PROP_JMX_ENABLED,
-        PROP_FAIR_QUEUE
-    };
-
-    // -------------------------------------------------- ObjectFactory Methods
-
-    /**
-     * <p>Create and return a new <code>BasicDataSource</code> instance.  If no
-     * instance can be created, return <code>null</code> instead.</p>
-     *
-     * @param obj The possibly null object containing location or
-     *  reference information that can be used in creating an object
-     * @param name The name of this object relative to <code>nameCtx</code>
-     * @param nameCtx The context relative to which the <code>name</code>
-     *  parameter is specified, or <code>null</code> if <code>name</code>
-     *  is relative to the default initial context
-     * @param environment The possibly null environment that is used in
-     *  creating this object
-     *
-     * @exception Exception if an exception occurs creating the instance
-     */
-    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
-                                    Hashtable environment) throws Exception {
-
-        // We only know how to deal with <code>javax.naming.Reference</code>s
-        // that specify a class name of "javax.sql.DataSource"
-        if ((obj == null) || !(obj instanceof Reference)) {
-            return null;
-        }
-        Reference ref = (Reference) obj;
-        if (!"javax.sql.DataSource".equals(ref.getClassName())) {
-            return null;
-        }
-
-        Properties properties = new Properties();
-        for (int i = 0; i < ALL_PROPERTIES.length; i++) {
-            String propertyName = ALL_PROPERTIES[i];
-            RefAddr ra = ref.get(propertyName);
-            if (ra != null) {
-                String propertyValue = ra.getContent().toString();
-                properties.setProperty(propertyName, propertyValue);
-            }
-        }
-
-        return createDataSource(properties);
-    }
-
-    /**
-     * Creates and configures a {@link BasicDataSource} instance based on the
-     * given properties.
-     *
-     * @param properties the datasource configuration properties
-     * @throws Exception if an error occurs creating the data source
-     */
-    public static DataSource createDataSource(Properties properties) throws Exception {
-        org.apache.tomcat.jdbc.pool.DataSourceProxy dataSource = new org.apache.tomcat.jdbc.pool.DataSourceProxy();
-
-        String value = null;
-
-        value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT);
-        if (value != null) {
-            dataSource.getPoolProperties().setDefaultAutoCommit(Boolean.valueOf(value));
-        }
-
-        value = properties.getProperty(PROP_DEFAULTREADONLY);
-        if (value != null) {
-            dataSource.getPoolProperties().setDefaultReadOnly(Boolean.valueOf(value));
-        }
-
-        value = properties.getProperty(PROP_DEFAULTTRANSACTIONISOLATION);
-        if (value != null) {
-            int level = UNKNOWN_TRANSACTIONISOLATION;
-            if ("NONE".equalsIgnoreCase(value)) {
-                level = Connection.TRANSACTION_NONE;
-            } else if ("READ_COMMITTED".equalsIgnoreCase(value)) {
-                level = Connection.TRANSACTION_READ_COMMITTED;
-            } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) {
-                level = Connection.TRANSACTION_READ_UNCOMMITTED;
-            } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) {
-                level = Connection.TRANSACTION_REPEATABLE_READ;
-            } else if ("SERIALIZABLE".equalsIgnoreCase(value)) {
-                level = Connection.TRANSACTION_SERIALIZABLE;
-            } else {
-                try {
-                    level = Integer.parseInt(value);
-                } catch (NumberFormatException e) {
-                    System.err.println("Could not parse defaultTransactionIsolation: " + value);
-                    System.err.println("WARNING: defaultTransactionIsolation not set");
-                    System.err.println("using default value of database driver");
-                    level = UNKNOWN_TRANSACTIONISOLATION;
-                }
-            }
-            dataSource.getPoolProperties().setDefaultTransactionIsolation(level);
-        }
-
-        value = properties.getProperty(PROP_DEFAULTCATALOG);
-        if (value != null) {
-            dataSource.getPoolProperties().setDefaultCatalog(value);
-        }
-
-        value = properties.getProperty(PROP_DRIVERCLASSNAME);
-        if (value != null) {
-            dataSource.getPoolProperties().setDriverClassName(value);
-        }
-
-        value = properties.getProperty(PROP_MAXACTIVE);
-        if (value != null) {
-            dataSource.getPoolProperties().setMaxActive(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_MAXIDLE);
-        if (value != null) {
-            dataSource.getPoolProperties().setMaxIdle(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_MINIDLE);
-        if (value != null) {
-            dataSource.getPoolProperties().setMinIdle(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_INITIALSIZE);
-        if (value != null) {
-            dataSource.getPoolProperties().setInitialSize(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_MAXWAIT);
-        if (value != null) {
-            dataSource.getPoolProperties().setMaxWait(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_TESTONBORROW);
-        if (value != null) {
-            dataSource.getPoolProperties().setTestOnBorrow(Boolean.valueOf(value).booleanValue());
-        }
-
-        value = properties.getProperty(PROP_TESTONRETURN);
-        if (value != null) {
-            dataSource.getPoolProperties().setTestOnReturn(Boolean.valueOf(value).booleanValue());
-        }
-
-        value = properties.getProperty(PROP_TESTONCONNECT);
-        if (value != null) {
-            dataSource.getPoolProperties().setTestOnConnect(Boolean.valueOf(value).booleanValue());
-        }
-
-        value = properties.getProperty(PROP_TIMEBETWEENEVICTIONRUNSMILLIS);
-        if (value != null) {
-            dataSource.getPoolProperties().setTimeBetweenEvictionRunsMillis(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_NUMTESTSPEREVICTIONRUN);
-        if (value != null) {
-            dataSource.getPoolProperties().setNumTestsPerEvictionRun(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_MINEVICTABLEIDLETIMEMILLIS);
-        if (value != null) {
-            dataSource.getPoolProperties().setMinEvictableIdleTimeMillis(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_TESTWHILEIDLE);
-        if (value != null) {
-            dataSource.getPoolProperties().setTestWhileIdle(Boolean.valueOf(value).booleanValue());
-        }
-
-        value = properties.getProperty(PROP_PASSWORD);
-        if (value != null) {
-            dataSource.getPoolProperties().setPassword(value);
-        }
-
-        value = properties.getProperty(PROP_URL);
-        if (value != null) {
-            dataSource.getPoolProperties().setUrl(value);
-        }
-
-        value = properties.getProperty(PROP_USERNAME);
-        if (value != null) {
-            dataSource.getPoolProperties().setUsername(value);
-        }
-
-        value = properties.getProperty(PROP_VALIDATIONQUERY);
-        if (value != null) {
-            dataSource.getPoolProperties().setValidationQuery(value);
-        }
-
-        value = properties.getProperty(PROP_VALIDATIONINTERVAL);
-        if (value != null) {
-            dataSource.getPoolProperties().setValidationInterval(Long.parseLong(value));
-        }
-
-        value = properties.getProperty(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED);
-        if (value != null) {
-            dataSource.getPoolProperties().
-                setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(value).booleanValue());
-        }
-
-        value = properties.getProperty(PROP_REMOVEABANDONED);
-        if (value != null) {
-            dataSource.getPoolProperties().setRemoveAbandoned(Boolean.valueOf(value).booleanValue());
-        }
-
-        value = properties.getProperty(PROP_REMOVEABANDONEDTIMEOUT);
-        if (value != null) {
-            dataSource.getPoolProperties().setRemoveAbandonedTimeout(Integer.parseInt(value));
-        }
-
-        value = properties.getProperty(PROP_LOGABANDONED);
-        if (value != null) {
-            dataSource.getPoolProperties().setLogAbandoned(Boolean.valueOf(value).booleanValue());
-        }
-
-        value = properties.getProperty(PROP_POOLPREPAREDSTATEMENTS);
-        if (value != null) {
-            log.warn(PROP_POOLPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
-        }
-
-        value = properties.getProperty(PROP_MAXOPENPREPAREDSTATEMENTS);
-        if (value != null) {
-            log.warn(PROP_MAXOPENPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
-        }
-
-        value = properties.getProperty(PROP_CONNECTIONPROPERTIES);
-        if (value != null) {
-            Properties p = getProperties(value);
-            dataSource.getPoolProperties().setDbProperties(p);
-        } else {
-            dataSource.getPoolProperties().setDbProperties(new Properties());
-        }
-
-        dataSource.getPoolProperties().getDbProperties().setProperty("user",dataSource.getPoolProperties().getUsername());
-        dataSource.getPoolProperties().getDbProperties().setProperty("password",dataSource.getPoolProperties().getPassword());
-
-        value = properties.getProperty(PROP_INITSQL);
-        if (value != null) {
-            dataSource.getPoolProperties().setInitSQL(value);
-        }
-
-        value = properties.getProperty(PROP_INTERCEPTORS);
-        if (value != null) {
-            dataSource.getPoolProperties().setJdbcInterceptors(value);
-        }
-
-        value = properties.getProperty(PROP_JMX_ENABLED);
-        if (value != null) {
-            dataSource.getPoolProperties().setJmxEnabled(Boolean.parseBoolean(value));
-        }
-        
-        value = properties.getProperty(PROP_FAIR_QUEUE);
-        if (value != null) {
-            dataSource.getPoolProperties().setFairQueue(Boolean.parseBoolean(value));
-        }
-        
-
-        // Return the configured DataSource instance
-        DataSource ds = getDataSource(dataSource);
-        return ds;
-    }
-
-    public static DataSource getDataSource(org.apache.tomcat.jdbc.pool.DataSourceProxy dataSource) {
-        DataSourceHandler handler = new DataSourceHandler(dataSource);
-        DataSource ds = (DataSource)Proxy.newProxyInstance(DataSourceFactory.class.getClassLoader(), new Class[] {javax.sql.DataSource.class}, handler);
-        return ds;
-    }
-
-    /**
-     * <p>Parse properties from the string. Format of the string must be [propertyName=property;]*<p>
-     * @param propText
-     * @return Properties
-     * @throws Exception
-     */
-    static protected Properties getProperties(String propText) throws Exception {
-        Properties p = new Properties();
-        if (propText != null) {
-            p.load(new ByteArrayInputStream(propText.replace(';', '\n').
-                                            getBytes()));
-        }
-        return p;
-    }
-
-    protected static class DataSourceHandler implements InvocationHandler {
-        protected org.apache.tomcat.jdbc.pool.DataSourceProxy datasource = null;
-        protected static HashMap<Method,Method> methods = new HashMap<Method,Method>();
-        public DataSourceHandler(org.apache.tomcat.jdbc.pool.DataSourceProxy ds) {
-            this.datasource = ds;
-        }
-
-        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-            Method m = methods.get(method);
-            if (m==null) {
-                m = datasource.getClass().getMethod(method.getName(), method.getParameterTypes());
-                methods.put(method, m);
-            }
-            return m.invoke(datasource, args);
-        }
-
-    }
-}
+/*
+ * 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.io.ByteArrayInputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.Connection;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import javax.sql.DataSource;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+/**
+ * <p>JNDI object factory that creates an instance of
+ * <code>BasicDataSource</code> that has been configured based on the
+ * <code>RefAddr</code> values of the specified <code>Reference</code>,
+ * which must match the names and data types of the
+ * <code>BasicDataSource</code> bean properties.</p>
+ * <br/>
+ * Properties available for configuration:<br/>
+ * <a href="http://commons.apache.org/dbcp/configuration.html">Commons DBCP properties</a><br/>
+ *<ol>
+ *  <li>initSQL - A query that gets executed once, right after the connection is established.</li>
+ *  <li>testOnConnect - run validationQuery after connection has been established.</li>
+ *  <li>validationInterval - avoid excess validation, only run validation at most at this frequency - time in milliseconds.</li>
+ *  <li>jdbcInterceptors - a semicolon separated list of classnames extending {@link JdbcInterceptor} class.</li>
+ *  <li>jmxEnabled - true of false, whether to register the pool with JMX.</li>
+ *  <li>fairQueue - true of false, whether the pool should sacrifice a little bit of performance for true fairness.</li>
+ *</ol>
+ * @author Craig R. McClanahan
+ * @author Dirk Verbeeck
+ * @author Filip Hanik
+ */
+public class DataSourceFactory implements ObjectFactory {
+    protected static Log log = LogFactory.getLog(DataSourceFactory.class);
+
+    protected final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
+    protected final static String PROP_DEFAULTREADONLY = "defaultReadOnly";
+    protected final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
+    protected final static String PROP_DEFAULTCATALOG = "defaultCatalog";
+    
+    protected final static String PROP_DRIVERCLASSNAME = "driverClassName";
+    protected final static String PROP_PASSWORD = "password";
+    protected final static String PROP_URL = "url";
+    protected final static String PROP_USERNAME = "username";
+
+    protected final static String PROP_MAXACTIVE = "maxActive";
+    protected final static String PROP_MAXIDLE = "maxIdle";
+    protected final static String PROP_MINIDLE = "minIdle";
+    protected final static String PROP_INITIALSIZE = "initialSize";
+    protected final static String PROP_MAXWAIT = "maxWait";
+    
+    protected final static String PROP_TESTONBORROW = "testOnBorrow";
+    protected final static String PROP_TESTONRETURN = "testOnReturn";
+    protected final static String PROP_TESTWHILEIDLE = "testWhileIdle";
+    protected final static String PROP_TESTONCONNECT = "testOnConnect";
+    protected final static String PROP_VALIDATIONQUERY = "validationQuery";
+    
+    protected final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
+    protected final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
+    protected final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
+    
+    protected final static String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED = "accessToUnderlyingConnectionAllowed";
+    
+    protected final static String PROP_REMOVEABANDONED = "removeAbandoned";
+    protected final static String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout";
+    protected final static String PROP_LOGABANDONED = "logAbandoned";
+    
+    protected final static String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements";
+    protected final static String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements";
+    protected final static String PROP_CONNECTIONPROPERTIES = "connectionProperties";
+    
+    protected final static String PROP_INITSQL = "initSQL";
+    protected final static String PROP_INTERCEPTORS = "jdbcInterceptors";
+    protected final static String PROP_VALIDATIONINTERVAL = "validationInterval";
+    protected final static String PROP_JMX_ENABLED = "jmxEnabled";
+    protected final static String PROP_FAIR_QUEUE = "fairQueue";
+    
+    public static final int UNKNOWN_TRANSACTIONISOLATION = -1;
+
+
+    protected final static String[] ALL_PROPERTIES = {
+        PROP_DEFAULTAUTOCOMMIT,
+        PROP_DEFAULTREADONLY,
+        PROP_DEFAULTTRANSACTIONISOLATION,
+        PROP_DEFAULTCATALOG,
+        PROP_DRIVERCLASSNAME,
+        PROP_MAXACTIVE,
+        PROP_MAXIDLE,
+        PROP_MINIDLE,
+        PROP_INITIALSIZE,
+        PROP_MAXWAIT,
+        PROP_TESTONBORROW,
+        PROP_TESTONRETURN,
+        PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
+        PROP_NUMTESTSPEREVICTIONRUN,
+        PROP_MINEVICTABLEIDLETIMEMILLIS,
+        PROP_TESTWHILEIDLE,
+        PROP_TESTONCONNECT,
+        PROP_PASSWORD,
+        PROP_URL,
+        PROP_USERNAME,
+        PROP_VALIDATIONQUERY,
+        PROP_VALIDATIONINTERVAL,
+        PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
+        PROP_REMOVEABANDONED,
+        PROP_REMOVEABANDONEDTIMEOUT,
+        PROP_LOGABANDONED,
+        PROP_POOLPREPAREDSTATEMENTS,
+        PROP_MAXOPENPREPAREDSTATEMENTS,
+        PROP_CONNECTIONPROPERTIES,
+        PROP_INITSQL,
+        PROP_INTERCEPTORS,
+        PROP_JMX_ENABLED,
+        PROP_FAIR_QUEUE
+    };
+
+    // -------------------------------------------------- ObjectFactory Methods
+
+    /**
+     * <p>Create and return a new <code>BasicDataSource</code> instance.  If no
+     * instance can be created, return <code>null</code> instead.</p>
+     *
+     * @param obj The possibly null object containing location or
+     *  reference information that can be used in creating an object
+     * @param name The name of this object relative to <code>nameCtx</code>
+     * @param nameCtx The context relative to which the <code>name</code>
+     *  parameter is specified, or <code>null</code> if <code>name</code>
+     *  is relative to the default initial context
+     * @param environment The possibly null environment that is used in
+     *  creating this object
+     *
+     * @exception Exception if an exception occurs creating the instance
+     */
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+                                    Hashtable environment) throws Exception {
+
+        // We only know how to deal with <code>javax.naming.Reference</code>s
+        // that specify a class name of "javax.sql.DataSource"
+        if ((obj == null) || !(obj instanceof Reference)) {
+            return null;
+        }
+        Reference ref = (Reference) obj;
+        if (!"javax.sql.DataSource".equals(ref.getClassName())) {
+            return null;
+        }
+
+        Properties properties = new Properties();
+        for (int i = 0; i < ALL_PROPERTIES.length; i++) {
+            String propertyName = ALL_PROPERTIES[i];
+            RefAddr ra = ref.get(propertyName);
+            if (ra != null) {
+                String propertyValue = ra.getContent().toString();
+                properties.setProperty(propertyName, propertyValue);
+            }
+        }
+
+        return createDataSource(properties);
+    }
+
+    /**
+     * Creates and configures a {@link BasicDataSource} instance based on the
+     * given properties.
+     *
+     * @param properties the datasource configuration properties
+     * @throws Exception if an error occurs creating the data source
+     */
+    public static DataSource createDataSource(Properties properties) throws Exception {
+        org.apache.tomcat.jdbc.pool.DataSourceProxy dataSource = new org.apache.tomcat.jdbc.pool.DataSourceProxy();
+
+        String value = null;
+
+        value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT);
+        if (value != null) {
+            dataSource.getPoolProperties().setDefaultAutoCommit(Boolean.valueOf(value));
+        }
+
+        value = properties.getProperty(PROP_DEFAULTREADONLY);
+        if (value != null) {
+            dataSource.getPoolProperties().setDefaultReadOnly(Boolean.valueOf(value));
+        }
+
+        value = properties.getProperty(PROP_DEFAULTTRANSACTIONISOLATION);
+        if (value != null) {
+            int level = UNKNOWN_TRANSACTIONISOLATION;
+            if ("NONE".equalsIgnoreCase(value)) {
+                level = Connection.TRANSACTION_NONE;
+            } else if ("READ_COMMITTED".equalsIgnoreCase(value)) {
+                level = Connection.TRANSACTION_READ_COMMITTED;
+            } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) {
+                level = Connection.TRANSACTION_READ_UNCOMMITTED;
+            } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) {
+                level = Connection.TRANSACTION_REPEATABLE_READ;
+            } else if ("SERIALIZABLE".equalsIgnoreCase(value)) {
+                level = Connection.TRANSACTION_SERIALIZABLE;
+            } else {
+                try {
+                    level = Integer.parseInt(value);
+                } catch (NumberFormatException e) {
+                    System.err.println("Could not parse defaultTransactionIsolation: " + value);
+                    System.err.println("WARNING: defaultTransactionIsolation not set");
+                    System.err.println("using default value of database driver");
+                    level = UNKNOWN_TRANSACTIONISOLATION;
+                }
+            }
+            dataSource.getPoolProperties().setDefaultTransactionIsolation(level);
+        }
+
+        value = properties.getProperty(PROP_DEFAULTCATALOG);
+        if (value != null) {
+            dataSource.getPoolProperties().setDefaultCatalog(value);
+        }
+
+        value = properties.getProperty(PROP_DRIVERCLASSNAME);
+        if (value != null) {
+            dataSource.getPoolProperties().setDriverClassName(value);
+        }
+
+        value = properties.getProperty(PROP_MAXACTIVE);
+        if (value != null) {
+            dataSource.getPoolProperties().setMaxActive(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_MAXIDLE);
+        if (value != null) {
+            dataSource.getPoolProperties().setMaxIdle(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_MINIDLE);
+        if (value != null) {
+            dataSource.getPoolProperties().setMinIdle(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_INITIALSIZE);
+        if (value != null) {
+            dataSource.getPoolProperties().setInitialSize(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_MAXWAIT);
+        if (value != null) {
+            dataSource.getPoolProperties().setMaxWait(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_TESTONBORROW);
+        if (value != null) {
+            dataSource.getPoolProperties().setTestOnBorrow(Boolean.valueOf(value).booleanValue());
+        }
+
+        value = properties.getProperty(PROP_TESTONRETURN);
+        if (value != null) {
+            dataSource.getPoolProperties().setTestOnReturn(Boolean.valueOf(value).booleanValue());
+        }
+
+        value = properties.getProperty(PROP_TESTONCONNECT);
+        if (value != null) {
+            dataSource.getPoolProperties().setTestOnConnect(Boolean.valueOf(value).booleanValue());
+        }
+
+        value = properties.getProperty(PROP_TIMEBETWEENEVICTIONRUNSMILLIS);
+        if (value != null) {
+            dataSource.getPoolProperties().setTimeBetweenEvictionRunsMillis(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_NUMTESTSPEREVICTIONRUN);
+        if (value != null) {
+            dataSource.getPoolProperties().setNumTestsPerEvictionRun(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_MINEVICTABLEIDLETIMEMILLIS);
+        if (value != null) {
+            dataSource.getPoolProperties().setMinEvictableIdleTimeMillis(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_TESTWHILEIDLE);
+        if (value != null) {
+            dataSource.getPoolProperties().setTestWhileIdle(Boolean.valueOf(value).booleanValue());
+        }
+
+        value = properties.getProperty(PROP_PASSWORD);
+        if (value != null) {
+            dataSource.getPoolProperties().setPassword(value);
+        }
+
+        value = properties.getProperty(PROP_URL);
+        if (value != null) {
+            dataSource.getPoolProperties().setUrl(value);
+        }
+
+        value = properties.getProperty(PROP_USERNAME);
+        if (value != null) {
+            dataSource.getPoolProperties().setUsername(value);
+        }
+
+        value = properties.getProperty(PROP_VALIDATIONQUERY);
+        if (value != null) {
+            dataSource.getPoolProperties().setValidationQuery(value);
+        }
+
+        value = properties.getProperty(PROP_VALIDATIONINTERVAL);
+        if (value != null) {
+            dataSource.getPoolProperties().setValidationInterval(Long.parseLong(value));
+        }
+
+        value = properties.getProperty(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED);
+        if (value != null) {
+            dataSource.getPoolProperties().
+                setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(value).booleanValue());
+        }
+
+        value = properties.getProperty(PROP_REMOVEABANDONED);
+        if (value != null) {
+            dataSource.getPoolProperties().setRemoveAbandoned(Boolean.valueOf(value).booleanValue());
+        }
+
+        value = properties.getProperty(PROP_REMOVEABANDONEDTIMEOUT);
+        if (value != null) {
+            dataSource.getPoolProperties().setRemoveAbandonedTimeout(Integer.parseInt(value));
+        }
+
+        value = properties.getProperty(PROP_LOGABANDONED);
+        if (value != null) {
+            dataSource.getPoolProperties().setLogAbandoned(Boolean.valueOf(value).booleanValue());
+        }
+
+        value = properties.getProperty(PROP_POOLPREPAREDSTATEMENTS);
+        if (value != null) {
+            log.warn(PROP_POOLPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
+        }
+
+        value = properties.getProperty(PROP_MAXOPENPREPAREDSTATEMENTS);
+        if (value != null) {
+            log.warn(PROP_MAXOPENPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
+        }
+
+        value = properties.getProperty(PROP_CONNECTIONPROPERTIES);
+        if (value != null) {
+            Properties p = getProperties(value);
+            dataSource.getPoolProperties().setDbProperties(p);
+        } else {
+            dataSource.getPoolProperties().setDbProperties(new Properties());
+        }
+
+        dataSource.getPoolProperties().getDbProperties().setProperty("user",dataSource.getPoolProperties().getUsername());
+        dataSource.getPoolProperties().getDbProperties().setProperty("password",dataSource.getPoolProperties().getPassword());
+
+        value = properties.getProperty(PROP_INITSQL);
+        if (value != null) {
+            dataSource.getPoolProperties().setInitSQL(value);
+        }
+
+        value = properties.getProperty(PROP_INTERCEPTORS);
+        if (value != null) {
+            dataSource.getPoolProperties().setJdbcInterceptors(value);
+        }
+
+        value = properties.getProperty(PROP_JMX_ENABLED);
+        if (value != null) {
+            dataSource.getPoolProperties().setJmxEnabled(Boolean.parseBoolean(value));
+        }
+        
+        value = properties.getProperty(PROP_FAIR_QUEUE);
+        if (value != null) {
+            dataSource.getPoolProperties().setFairQueue(Boolean.parseBoolean(value));
+        }
+        
+
+        // Return the configured DataSource instance
+        DataSource ds = getDataSource(dataSource);
+        return ds;
+    }
+
+    public static DataSource getDataSource(org.apache.tomcat.jdbc.pool.DataSourceProxy dataSource) {
+        DataSourceHandler handler = new DataSourceHandler(dataSource);
+        DataSource ds = (DataSource)Proxy.newProxyInstance(DataSourceFactory.class.getClassLoader(), new Class[] {javax.sql.DataSource.class}, handler);
+        return ds;
+    }
+
+    /**
+     * <p>Parse properties from the string. Format of the string must be [propertyName=property;]*<p>
+     * @param propText
+     * @return Properties
+     * @throws Exception
+     */
+    static protected Properties getProperties(String propText) throws Exception {
+        Properties p = new Properties();
+        if (propText != null) {
+            p.load(new ByteArrayInputStream(propText.replace(';', '\n').
+                                            getBytes()));
+        }
+        return p;
+    }
+
+    protected static class DataSourceHandler implements InvocationHandler {
+        protected org.apache.tomcat.jdbc.pool.DataSourceProxy datasource = null;
+        protected static HashMap<Method,Method> methods = new HashMap<Method,Method>();
+        public DataSourceHandler(org.apache.tomcat.jdbc.pool.DataSourceProxy ds) {
+            this.datasource = ds;
+        }
+
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+            Method m = methods.get(method);
+            if (m==null) {
+                m = datasource.getClass().getMethod(method.getName(), method.getParameterTypes());
+                methods.put(method, m);
+            }
+            return m.invoke(datasource, args);
+        }
+
+    }
+}

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java?rev=710199&r1=710198&r2=710199&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java Mon Nov  3 14:38:55 2008
@@ -1,308 +1,308 @@
-/*
- * 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.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Iterator;
-
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-
-/**
- *
- * <p>Title: Uber Pool</p>
- *
- * <p>Description: A simple, yet efficient and powerful connection pool</p>
- *
- * <p>Copyright: Copyright (c) 2008 Filip Hanik</p>
- *
- * <p> </p>
- *
- * @author Filip Hanik
- * @version 1.0
- */
-
-public class DataSourceProxy  {
-    protected static Log log = LogFactory.getLog(DataSourceProxy.class);
-    
-    protected Driver driver;
-    protected PoolProperties poolProperties = new PoolProperties();
-
-    public DataSourceProxy() {
-    }
-
-
-    public boolean isWrapperFor(Class<?> iface) throws SQLException {
-        // we are not a wrapper of anything
-        return false;
-    }
-
-
-    public <T> T unwrap(Class<T> iface) throws SQLException {
-        //we can't unwrap anything
-        return null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Connection getConnection(String username, String password) throws SQLException {
-        return getConnection();
-    }
-
-    public PoolProperties getPoolProperties() {
-        return poolProperties;
-    }
-
-    /**
-     * Sets up the connection pool, by creating a pooling driver.
-     * @return Driver
-     * @throws SQLException
-     */
-    public synchronized Driver createDriver() throws SQLException {
-        if (driver != null) {
-            return driver;
-        } else {
-            driver = new org.apache.tomcat.jdbc.pool.Driver(getPoolProperties());
-            return driver;
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-
-    public Connection getConnection() throws SQLException {
-        if (driver == null)
-            driver = createDriver();
-        return driver.connect(poolProperties.getPoolName(), null);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public PooledConnection getPooledConnection() throws SQLException {
-        return (PooledConnection) getConnection();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public PooledConnection getPooledConnection(String username,
-                                                String password) throws SQLException {
-        return (PooledConnection) getConnection();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public PrintWriter getLogWriter() throws SQLException {
-        return null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setLogWriter(PrintWriter out) throws SQLException {
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public int getLoginTimeout() {
-        if (poolProperties == null) {
-            return 0;
-        } else {
-            return poolProperties.getMaxWait() / 1000;
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setLoginTimeout(int i) {
-        if (poolProperties == null) {
-            return;
-        } else {
-            poolProperties.setMaxWait(1000 * i);
-        }
-
-    }
-
-
-    public void close() {
-        close(false);
-    }
-    public void close(boolean all) {
-        try {
-            if (driver != null) {
-                Driver d = driver;
-                driver = null;
-                d.closePool(poolProperties.getPoolName(), all);
-            }
-        }catch (Exception x) {
-            x.printStackTrace();
-        }
-    }
-
-    protected void finalize() throws Throwable {
-        //terminate the pool?
-        close(true);
-    }
-
-    public int getPoolSize() throws SQLException{
-        if (driver == null)
-            driver = createDriver();
-        return driver.getPool(getPoolProperties().getPoolName()).getSize();
-    }
-
-   public String toString() {
-        return super.toString()+"{"+getPoolProperties()+"}";
-    }
-
-/*-----------------------------------------------------------------------*/
-//      PROPERTIES WHEN NOT USED WITH FACTORY
-/*------------------------------------------------------------------------*/
-    public void setPoolProperties(PoolProperties poolProperties) {
-        this.poolProperties = poolProperties;
-    }
-
-    public void setDriverClassName(String driverClassName) {
-        this.poolProperties.setDriverClassName(driverClassName);
-    }
-
-    public void setInitialSize(int initialSize) {
-        this.poolProperties.setInitialSize(initialSize);
-    }
-
-    public void setInitSQL(String initSQL) {
-        this.poolProperties.setInitSQL(initSQL);
-    }
-
-    public void setLogAbandoned(boolean logAbandoned) {
-        this.poolProperties.setLogAbandoned(logAbandoned);
-    }
-
-    public void setMaxActive(int maxActive) {
-        this.poolProperties.setMaxIdle(maxActive);
-    }
-
-    public void setMaxIdle(int maxIdle) {
-        this.poolProperties.setMaxIdle(maxIdle);
-    }
-
-    public void setMaxWait(int maxWait) {
-        this.poolProperties.setMaxWait(maxWait);
-    }
-
-    public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
-        this.poolProperties.setMinEvictableIdleTimeMillis(
-            minEvictableIdleTimeMillis);
-    }
-
-    public void setMinIdle(int minIdle) {
-        this.setMinIdle(minIdle);
-    }
-
-    public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
-        this.poolProperties.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
-    }
-
-    public void setPassword(String password) {
-        this.poolProperties.setPassword(password);
-        this.poolProperties.getDbProperties().setProperty("password",this.poolProperties.getPassword());
-    }
-
-    public void setRemoveAbandoned(boolean removeAbandoned) {
-        this.poolProperties.setRemoveAbandoned(removeAbandoned);
-    }
-
-    public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
-        this.poolProperties.setRemoveAbandonedTimeout(removeAbandonedTimeout);
-    }
-
-    public void setTestOnBorrow(boolean testOnBorrow) {
-        this.poolProperties.setTestOnBorrow(testOnBorrow);
-    }
-
-    public void setTestOnConnect(boolean testOnConnect) {
-        this.poolProperties.setTestOnConnect(testOnConnect);
-    }
-
-    public void setTestOnReturn(boolean testOnReturn) {
-        this.poolProperties.setTestOnReturn(testOnReturn);
-    }
-
-    public void setTestWhileIdle(boolean testWhileIdle) {
-        this.poolProperties.setTestWhileIdle(testWhileIdle);
-    }
-
-    public void setTimeBetweenEvictionRunsMillis(int
-                                                 timeBetweenEvictionRunsMillis) {
-        this.poolProperties.setTimeBetweenEvictionRunsMillis(
-            timeBetweenEvictionRunsMillis);
-    }
-
-    public void setUrl(String url) {
-        this.poolProperties.setUrl(url);
-    }
-
-    public void setUsername(String username) {
-        this.poolProperties.setUsername(username);
-        this.poolProperties.getDbProperties().setProperty("user",getPoolProperties().getUsername());
-    }
-
-    public void setValidationInterval(long validationInterval) {
-        this.poolProperties.setValidationInterval(validationInterval);
-    }
-
-    public void setValidationQuery(String validationQuery) {
-        this.poolProperties.setValidationQuery(validationQuery);
-    }
-
-    public void setJdbcInterceptors(String interceptors) {
-        this.getPoolProperties().setJdbcInterceptors(interceptors);
-    }
-
-    public void setJmxEnabled(boolean enabled) {
-        this.getPoolProperties().setJmxEnabled(enabled);
-    }
-    
-    public void setFairQueue(boolean fairQueue) {
-        this.getPoolProperties().setFairQueue(fairQueue);
-    }
-    
-    public void setConnectionProperties(String properties) {
-        try {
-            java.util.Properties prop = DataSourceFactory.getProperties(properties);
-            Iterator i = prop.keySet().iterator();
-            while (i.hasNext()) {
-                String key = (String)i.next();
-                String value = prop.getProperty(key);
-                getPoolProperties().getDbProperties().setProperty(key, value);
-            }
-            
-        }catch (Exception x) {
-            log.error("Unable to parse connection properties.", x);
-            throw new RuntimeException(x);
-        }
-    }
-
-
-}
+/*
+ * 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.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Iterator;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+/**
+ *
+ * <p>Title: Uber Pool</p>
+ *
+ * <p>Description: A simple, yet efficient and powerful connection pool</p>
+ *
+ * <p>Copyright: Copyright (c) 2008 Filip Hanik</p>
+ *
+ * <p> </p>
+ *
+ * @author Filip Hanik
+ * @version 1.0
+ */
+
+public class DataSourceProxy  {
+    protected static Log log = LogFactory.getLog(DataSourceProxy.class);
+    
+    protected Driver driver;
+    protected PoolProperties poolProperties = new PoolProperties();
+
+    public DataSourceProxy() {
+    }
+
+
+    public boolean isWrapperFor(Class<?> iface) throws SQLException {
+        // we are not a wrapper of anything
+        return false;
+    }
+
+
+    public <T> T unwrap(Class<T> iface) throws SQLException {
+        //we can't unwrap anything
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Connection getConnection(String username, String password) throws SQLException {
+        return getConnection();
+    }
+
+    public PoolProperties getPoolProperties() {
+        return poolProperties;
+    }
+
+    /**
+     * Sets up the connection pool, by creating a pooling driver.
+     * @return Driver
+     * @throws SQLException
+     */
+    public synchronized Driver createDriver() throws SQLException {
+        if (driver != null) {
+            return driver;
+        } else {
+            driver = new org.apache.tomcat.jdbc.pool.Driver(getPoolProperties());
+            return driver;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+
+    public Connection getConnection() throws SQLException {
+        if (driver == null)
+            driver = createDriver();
+        return driver.connect(poolProperties.getPoolName(), null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PooledConnection getPooledConnection() throws SQLException {
+        return (PooledConnection) getConnection();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PooledConnection getPooledConnection(String username,
+                                                String password) throws SQLException {
+        return (PooledConnection) getConnection();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PrintWriter getLogWriter() throws SQLException {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setLogWriter(PrintWriter out) throws SQLException {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getLoginTimeout() {
+        if (poolProperties == null) {
+            return 0;
+        } else {
+            return poolProperties.getMaxWait() / 1000;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setLoginTimeout(int i) {
+        if (poolProperties == null) {
+            return;
+        } else {
+            poolProperties.setMaxWait(1000 * i);
+        }
+
+    }
+
+
+    public void close() {
+        close(false);
+    }
+    public void close(boolean all) {
+        try {
+            if (driver != null) {
+                Driver d = driver;
+                driver = null;
+                d.closePool(poolProperties.getPoolName(), all);
+            }
+        }catch (Exception x) {
+            x.printStackTrace();
+        }
+    }
+
+    protected void finalize() throws Throwable {
+        //terminate the pool?
+        close(true);
+    }
+
+    public int getPoolSize() throws SQLException{
+        if (driver == null)
+            driver = createDriver();
+        return driver.getPool(getPoolProperties().getPoolName()).getSize();
+    }
+
+   public String toString() {
+        return super.toString()+"{"+getPoolProperties()+"}";
+    }
+
+/*-----------------------------------------------------------------------*/
+//      PROPERTIES WHEN NOT USED WITH FACTORY
+/*------------------------------------------------------------------------*/
+    public void setPoolProperties(PoolProperties poolProperties) {
+        this.poolProperties = poolProperties;
+    }
+
+    public void setDriverClassName(String driverClassName) {
+        this.poolProperties.setDriverClassName(driverClassName);
+    }
+
+    public void setInitialSize(int initialSize) {
+        this.poolProperties.setInitialSize(initialSize);
+    }
+
+    public void setInitSQL(String initSQL) {
+        this.poolProperties.setInitSQL(initSQL);
+    }
+
+    public void setLogAbandoned(boolean logAbandoned) {
+        this.poolProperties.setLogAbandoned(logAbandoned);
+    }
+
+    public void setMaxActive(int maxActive) {
+        this.poolProperties.setMaxIdle(maxActive);
+    }
+
+    public void setMaxIdle(int maxIdle) {
+        this.poolProperties.setMaxIdle(maxIdle);
+    }
+
+    public void setMaxWait(int maxWait) {
+        this.poolProperties.setMaxWait(maxWait);
+    }
+
+    public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
+        this.poolProperties.setMinEvictableIdleTimeMillis(
+            minEvictableIdleTimeMillis);
+    }
+
+    public void setMinIdle(int minIdle) {
+        this.setMinIdle(minIdle);
+    }
+
+    public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
+        this.poolProperties.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
+    }
+
+    public void setPassword(String password) {
+        this.poolProperties.setPassword(password);
+        this.poolProperties.getDbProperties().setProperty("password",this.poolProperties.getPassword());
+    }
+
+    public void setRemoveAbandoned(boolean removeAbandoned) {
+        this.poolProperties.setRemoveAbandoned(removeAbandoned);
+    }
+
+    public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
+        this.poolProperties.setRemoveAbandonedTimeout(removeAbandonedTimeout);
+    }
+
+    public void setTestOnBorrow(boolean testOnBorrow) {
+        this.poolProperties.setTestOnBorrow(testOnBorrow);
+    }
+
+    public void setTestOnConnect(boolean testOnConnect) {
+        this.poolProperties.setTestOnConnect(testOnConnect);
+    }
+
+    public void setTestOnReturn(boolean testOnReturn) {
+        this.poolProperties.setTestOnReturn(testOnReturn);
+    }
+
+    public void setTestWhileIdle(boolean testWhileIdle) {
+        this.poolProperties.setTestWhileIdle(testWhileIdle);
+    }
+
+    public void setTimeBetweenEvictionRunsMillis(int
+                                                 timeBetweenEvictionRunsMillis) {
+        this.poolProperties.setTimeBetweenEvictionRunsMillis(
+            timeBetweenEvictionRunsMillis);
+    }
+
+    public void setUrl(String url) {
+        this.poolProperties.setUrl(url);
+    }
+
+    public void setUsername(String username) {
+        this.poolProperties.setUsername(username);
+        this.poolProperties.getDbProperties().setProperty("user",getPoolProperties().getUsername());
+    }
+
+    public void setValidationInterval(long validationInterval) {
+        this.poolProperties.setValidationInterval(validationInterval);
+    }
+
+    public void setValidationQuery(String validationQuery) {
+        this.poolProperties.setValidationQuery(validationQuery);
+    }
+
+    public void setJdbcInterceptors(String interceptors) {
+        this.getPoolProperties().setJdbcInterceptors(interceptors);
+    }
+
+    public void setJmxEnabled(boolean enabled) {
+        this.getPoolProperties().setJmxEnabled(enabled);
+    }
+    
+    public void setFairQueue(boolean fairQueue) {
+        this.getPoolProperties().setFairQueue(fairQueue);
+    }
+    
+    public void setConnectionProperties(String properties) {
+        try {
+            java.util.Properties prop = DataSourceFactory.getProperties(properties);
+            Iterator i = prop.keySet().iterator();
+            while (i.hasNext()) {
+                String key = (String)i.next();
+                String value = prop.getProperty(key);
+                getPoolProperties().getDbProperties().setProperty(key, value);
+            }
+            
+        }catch (Exception x) {
+            log.error("Unable to parse connection properties.", x);
+            throw new RuntimeException(x);
+        }
+    }
+
+
+}

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java?rev=710199&r1=710198&r2=710199&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java Mon Nov  3 14:38:55 2008
@@ -1,121 +1,121 @@
-/*
- * 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
+/*
+ * 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

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/Driver.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java?rev=710199&r1=710198&r2=710199&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java Mon Nov  3 14:38:55 2008
@@ -1,51 +1,51 @@
-/*
- * 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.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-/**
- * @author Filip Hanik
- * @version 1.0
- */
-public abstract class JdbcInterceptor implements InvocationHandler {
-    public  static final String CLOSE_VAL = "close";
-
-    private JdbcInterceptor next = null;
-
-    public JdbcInterceptor() {
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        if (getNext()!=null) return getNext().invoke(this,method,args);
-        else throw new NullPointerException();
-    }
-
-    public JdbcInterceptor getNext() {
-        return next;
-    }
-
-    public void setNext(JdbcInterceptor next) {
-        this.next = next;
-    }
-
-    public abstract void reset(ConnectionPool parent, PooledConnection con);
-}
+/*
+ * 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.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
+public abstract class JdbcInterceptor implements InvocationHandler {
+    public  static final String CLOSE_VAL = "close";
+
+    private JdbcInterceptor next = null;
+
+    public JdbcInterceptor() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        if (getNext()!=null) return getNext().invoke(this,method,args);
+        else throw new NullPointerException();
+    }
+
+    public JdbcInterceptor getNext() {
+        return next;
+    }
+
+    public void setNext(JdbcInterceptor next) {
+        this.next = next;
+    }
+
+    public abstract void reset(ConnectionPool parent, PooledConnection con);
+}

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org