diff --git a/.cvsignore b/.cvsignore index 754e821..51f795f 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1,8 +1,8 @@ -*.ipr -*.iml -*.iws -bin -dist -build -classes +*.ipr +*.iml +*.iws +bin +dist +build +classes javadoc \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..efe6829 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.ipr +*.iml +*.iws +bin +dist +build +classes +javadoc +/CVS/ +CVS \ No newline at end of file diff --git a/build.properties b/build.properties index add7653..27dcf4f 100644 --- a/build.properties +++ b/build.properties @@ -1,26 +1,26 @@ -# Project -proj.name=simplepool -proj.version=1.0 - -# Locations -path.build=build -path.src=src -path.dist=dist -path.lib=lib -path.javadoc=javadoc - -# Jar -jar.name=${proj.name} - -# Examples -ex.name=${proj.name}-examples-${proj.version} -path.ex=${proj.name}-examples - -# Release -release.name=${proj.name}-${proj.version} - -# Javadoc -javadoc.title=SimplePool API -javadoc.api.link=http://java.sun.com/j2se/1.4.2/docs/api -javadoc.servlet.link=http://java.sun.com/products/servlet/2.3/javadoc/ +# Project +proj.name=simplepool +proj.version=1.0 + +# Locations +path.build=build +path.src=src +path.dist=dist +path.lib=lib +path.javadoc=javadoc + +# Jar +jar.name=${proj.name} + +# Examples +ex.name=${proj.name}-examples-${proj.version} +path.ex=${proj.name}-examples + +# Release +release.name=${proj.name}-${proj.version} + +# Javadoc +javadoc.title=SimplePool API +javadoc.api.link=http://java.sun.com/j2se/1.4.2/docs/api +javadoc.servlet.link=http://java.sun.com/products/servlet/2.3/javadoc/ javadoc.packages=net.java.dev.simplepool.* \ No newline at end of file diff --git a/build.xml b/build.xml index 623da7a..97abf91 100644 --- a/build.xml +++ b/build.xml @@ -1,88 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/conf/server.xml b/conf/server.xml index 8f04d69..093ca18 100644 --- a/conf/server.xml +++ b/conf/server.xml @@ -1,107 +1,107 @@ - - - - - - - - - - - - - - factory - org.apache.catalina.users.MemoryUserDatabaseFactory - - - pathname - conf/tomcat-users.xml - - - - - - - - - factory - net.java.dev.simplepool.SimplePoolDataSourceFactory - - - driver - com.mysql.jdbc.Driver - - - user - dbuser - - - password - test - - - jdbcUrl - jdbc:mysql://localhost:3306/dbname - - - minConns - 8 - - - maxConns - 30 - - - maxConnTime - 1 - - - maxCheckoutSeconds - 60 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + factory + org.apache.catalina.users.MemoryUserDatabaseFactory + + + pathname + conf/tomcat-users.xml + + + + + + + + + factory + net.java.dev.simplepool.SimplePoolDataSourceFactory + + + driver + com.mysql.jdbc.Driver + + + user + dbuser + + + password + test + + + jdbcUrl + jdbc:mysql://localhost:3306/dbname + + + minConns + 8 + + + maxConns + 30 + + + maxConnTime + 1 + + + maxCheckoutSeconds + 60 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/test.jsp b/conf/test.jsp index 50f1043..9a9272e 100644 --- a/conf/test.jsp +++ b/conf/test.jsp @@ -1,21 +1,21 @@ -<% out.write(""); %> -<%@ page contentType="text/xml;charset=UTF-8"%> -<%@ page session="false"%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> - - - - - select * from entry - - - - - - - - <c:out value="${row.name}"/> - - - +<% out.write(""); %> +<%@ page contentType="text/xml;charset=UTF-8"%> +<%@ page session="false"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> + + + + + select * from entry + + + + + + + + <c:out value="${row.name}"/> + + + diff --git a/lib/commons-logging-api.jar b/lib/commons-logging-api.jar index 209bcdf..ade9a13 100644 Binary files a/lib/commons-logging-api.jar and b/lib/commons-logging-api.jar differ diff --git a/simplepool-examples/WEB-INF/web.xml b/simplepool-examples/WEB-INF/web.xml index 9d99df2..a744016 100644 --- a/simplepool-examples/WEB-INF/web.xml +++ b/simplepool-examples/WEB-INF/web.xml @@ -1,52 +1,52 @@ - - - - SimplePool Examples - - - + + + + SimplePool Examples + + + \ No newline at end of file diff --git a/simplepool-examples/conf/server.xml b/simplepool-examples/conf/server.xml index 9004b93..32fa328 100644 --- a/simplepool-examples/conf/server.xml +++ b/simplepool-examples/conf/server.xml @@ -1,62 +1,62 @@ - - - - - - - - - - - - - - - - - - - factory - net.java.dev.simplepool.SimplePoolDataSourceFactory - - - driver - com.mysql.jdbc.Driver - - - user - dbuser - - - password - dbpassword - - - jdbcUrl - jdbc:mysql://localhost:3306/dbname - - - minConns - 8 - - - maxConns - 30 - - - maxConnTime - 1 - - - maxCheckoutSeconds - 60 - - - - - - - - + + + + + + + + + + + + + + + + + + + factory + net.java.dev.simplepool.SimplePoolDataSourceFactory + + + driver + com.mysql.jdbc.Driver + + + user + dbuser + + + password + dbpassword + + + jdbcUrl + jdbc:mysql://localhost:3306/dbname + + + minConns + 8 + + + maxConns + 30 + + + maxConnTime + 1 + + + maxCheckoutSeconds + 60 + + + + + + + + \ No newline at end of file diff --git a/simplepool-examples/includes/inst.css b/simplepool-examples/includes/inst.css index df6d749..e93674e 100644 --- a/simplepool-examples/includes/inst.css +++ b/simplepool-examples/includes/inst.css @@ -1,4 +1,4 @@ -/* $Id$ +/* $Id: inst.css,v 1.1 2004/03/20 13:36:08 erik Exp $ This file contains rules that extend or override the more basic formatting defined in tigris.css. Edit it to customize the look of applications using tigris.css (instances). You are responsible for maintaining your own set of (optional) deltas from tigris.css defaults; this file is intended as an example. diff --git a/simplepool-examples/includes/tigris.css b/simplepool-examples/includes/tigris.css index 85892d0..8b5a955 100644 --- a/simplepool-examples/includes/tigris.css +++ b/simplepool-examples/includes/tigris.css @@ -1,4 +1,4 @@ -/* $Id$ +/* $Id: tigris.css,v 1.1 2004/03/20 13:36:08 erik Exp $ This file defines basic default formatting for HTML conforming to Tigris application style. To extend or override these rules for your instance, edit inst.css instead of this file. */ diff --git a/simplepool-examples/index.html b/simplepool-examples/index.html index 2719bc3..f997450 100644 --- a/simplepool-examples/index.html +++ b/simplepool-examples/index.html @@ -1,54 +1,54 @@ - - - - -simplepool: Examples - - - - - - - - -
-
-
-

simplepool
- Examples

-
-

Project Home

-
-
- - - - - - - - - - - - - -
SummaryA simple database connection pool for webapps using JSTL.
Example 1JNDI DataSource Examples
Example 2Servlet DataSource Examples
-
-
-

Description

-

SimplePool is a simple database connection pool implementation for web applications, specifically those using JSTL.

-

The connection pool can be created, accessed and managed via JNDI or a provided Servlet.

-

The examples above have been tailored for use with Tomcat and MySQL.

-
-
-
-
- - + + + + +simplepool: Examples + + + + + + + + +
+
+
+

simplepool
+ Examples

+
+

Project Home

+
+
+ + + + + + + + + + + + + +
SummaryA simple database connection pool for webapps using JSTL.
Example 1JNDI DataSource Examples
Example 2Servlet DataSource Examples
+
+
+

Description

+

SimplePool is a simple database connection pool implementation for web applications, specifically those using JSTL.

+

The connection pool can be created, accessed and managed via JNDI or a provided Servlet.

+

The examples above have been tailored for use with Tomcat and MySQL.

+
+
+
+
+ + diff --git a/simplepool-examples/jndi/index.jsp b/simplepool-examples/jndi/index.jsp index d36fea8..88e1961 100644 --- a/simplepool-examples/jndi/index.jsp +++ b/simplepool-examples/jndi/index.jsp @@ -1,84 +1,84 @@ - -<%@page import="javax.naming.*" %> - - - -simplepool: JNDI DataSource Examples - - - - - - - - - -
-
-
-

simplepool
- JNDI DataSource Examples

-
-

Examples Home

-

Please read the instructions before trying to run the examples.

-
-
- - - - - - - - - - - - - -
SummaryA simple database connection pool example using JDNI.
Example 1Scriptlet Example [source]
Example 2JSTL Example [source]
-
-
-

Instructions

-

JNDI is used to create, access and manage the connection pool.

-

First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.

-

The JNDI DataSource is defined as naming resource in the current webapp context, as shown in this minimal server configuration file.

-

The JNDI DataSource is configured using the following parameters:

-
    -
  • The varName parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.
  • -
  • The driver parameter is used to specify the name of the JDBC driver class to be registered. For example: com.mysql.jdbc.Driver.
  • -
  • The user parameter is used to specify the database username, if any.
  • -
  • The password parameter is used to specify the database password, if any.
  • -
  • The jdbcUrl parameter is used to specify the JDBC URL associated with the database. For example: jdbc:mysql://localhost:3306/dbname.
  • -
  • The minConns parameter is used to specify the minimum number of connections to start the pool with.
  • -
  • The maxConns parameter is used to specify the maximum number of connections to be dynamically created in the pool.
  • -
  • The maxConnTime parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.
  • -
  • The maxCheckoutSeconds parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.
  • -
-

Please note that all parameters are required.

-

Please take a minute to incorporate the JDNI DataSource example in your $CATALINE_HOME/conf/server.xml. Once done, please restart Tomcat. The examples will be functional upon restart.

-

Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.

-
-
-
-
- - + +<%@page import="javax.naming.*" %> + + + +simplepool: JNDI DataSource Examples + + + + + + + + + +
+
+
+

simplepool
+ JNDI DataSource Examples

+
+

Examples Home

+

Please read the instructions before trying to run the examples.

+
+
+ + + + + + + + + + + + + +
SummaryA simple database connection pool example using JDNI.
Example 1Scriptlet Example [source]
Example 2JSTL Example [source]
+
+
+

Instructions

+

JNDI is used to create, access and manage the connection pool.

+

First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.

+

The JNDI DataSource is defined as naming resource in the current webapp context, as shown in this minimal server configuration file.

+

The JNDI DataSource is configured using the following parameters:

+
    +
  • The varName parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.
  • +
  • The driver parameter is used to specify the name of the JDBC driver class to be registered. For example: com.mysql.jdbc.Driver.
  • +
  • The user parameter is used to specify the database username, if any.
  • +
  • The password parameter is used to specify the database password, if any.
  • +
  • The jdbcUrl parameter is used to specify the JDBC URL associated with the database. For example: jdbc:mysql://localhost:3306/dbname.
  • +
  • The minConns parameter is used to specify the minimum number of connections to start the pool with.
  • +
  • The maxConns parameter is used to specify the maximum number of connections to be dynamically created in the pool.
  • +
  • The maxConnTime parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.
  • +
  • The maxCheckoutSeconds parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.
  • +
+

Please note that all parameters are required.

+

Please take a minute to incorporate the JDNI DataSource example in your $CATALINE_HOME/conf/server.xml. Once done, please restart Tomcat. The examples will be functional upon restart.

+

Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.

+
+
+
+
+ + diff --git a/simplepool-examples/jndi/jstl.jsp b/simplepool-examples/jndi/jstl.jsp index 7d1eead..5ebb577 100644 --- a/simplepool-examples/jndi/jstl.jsp +++ b/simplepool-examples/jndi/jstl.jsp @@ -1,27 +1,27 @@ -<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> -<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> - - +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> +<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> + + SimplePool JNDI/JSTL Example - - - <%-- Execute the query using our JNDI DataSource --%> - + + + <%-- Execute the query using our JNDI DataSource --%> + SHOW TABLES - - + +

Tables

-
    - - <%-- - Loop through the result set and - display the current column value - --%> +
      + + <%-- + Loop through the result set and + display the current column value + --%>
    • -
      - -
        + + +
          diff --git a/simplepool-examples/jndi/scriptlet.jsp b/simplepool-examples/jndi/scriptlet.jsp index 928bc4d..e271102 100644 --- a/simplepool-examples/jndi/scriptlet.jsp +++ b/simplepool-examples/jndi/scriptlet.jsp @@ -1,45 +1,45 @@ -<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %> - - - SimplePool JNDI Example +<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %> + + + SimplePool JNDI Example - - - <% - // Get a new initial JNDI context - Context ctx = new InitialContext(); - + + + <% + // Get a new initial JNDI context + Context ctx = new InitialContext(); + // Get a reference to our JNDI DataSource - DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/JNDIPoolDS"); - - // Get a connection from the pool - Connection conn = ds.getConnection(); - - // Create a new statement - Statement stmt = conn.createStatement(); - - // Execute the query - ResultSet rst = stmt.executeQuery("SHOW TABLES"); - %> - + DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/JNDIPoolDS"); + + // Get a connection from the pool + Connection conn = ds.getConnection(); + + // Create a new statement + Statement stmt = conn.createStatement(); + + // Execute the query + ResultSet rst = stmt.executeQuery("SHOW TABLES"); + %> +

          Tables

          -
            - <% - // Loop through the result set and - // display the current column value - while (rst.next()) { - %> -
          • <%= rst.getString(1) %>
          • - <% - } - %> -
              - - <% - // Close the result set, statement and connection - rst.close(); - stmt.close(); - conn.close(); - %> +
                + <% + // Loop through the result set and + // display the current column value + while (rst.next()) { + %> +
              • <%= rst.getString(1) %>
              • + <% + } + %> +
                  + + <% + // Close the result set, statement and connection + rst.close(); + stmt.close(); + conn.close(); + %> diff --git a/simplepool-examples/licenses/JSTL License.txt b/simplepool-examples/licenses/JSTL License.txt index c62d44b..36866bd 100644 --- a/simplepool-examples/licenses/JSTL License.txt +++ b/simplepool-examples/licenses/JSTL License.txt @@ -1,56 +1,56 @@ -/* ========================================================================= * - * * - * The Apache Software License, Version 1.1 * - * * - * Copyright (c) 1999, 2000 The Apache Software Foundation. * - * All rights reserved. * - * * - * ========================================================================= * - * * - * Redistribution and use in source and binary forms, with or without modi- * - * fication, are permitted provided that the following conditions are met: * - * * - * 1. Redistributions of source code must retain the above copyright notice, * - * this list of conditions and the following disclaimer. * - * * - * 2. Redistributions in binary form must reproduce the above copyright * - * notice, this list of conditions and the following disclaimer in the * - * documentation and/or other materials provided with the distribution. * - * * - * 3. The end-user documentation included with the redistribution, if any, * - * must include the following acknowlegement: * - * * - * "This product includes software developed by the Apache Software * - * Foundation ." * - * * - * Alternately, this acknowlegement may appear in the software itself, if * - * and wherever such third-party acknowlegements normally appear. * - * * - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * - * Foundation" must not be used to endorse or promote products derived * - * from this software without prior written permission. For written * - * permission, please contact . * - * * - * 5. Products derived from this software may not be called "Apache" nor may * - * "Apache" appear in their names without prior written permission of the * - * Apache Software Foundation. * - * * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * - * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * - * POSSIBILITY OF SUCH DAMAGE. * - * * - * ========================================================================= * - * * - * This software consists of voluntary contributions made by many indivi- * - * duals on behalf of the Apache Software Foundation. For more information * - * on the Apache Software Foundation, please see . * - * * - * ========================================================================= */ +/* ========================================================================= * + * * + * The Apache Software License, Version 1.1 * + * * + * Copyright (c) 1999, 2000 The Apache Software Foundation. * + * All rights reserved. * + * * + * ========================================================================= * + * * + * Redistribution and use in source and binary forms, with or without modi- * + * fication, are permitted provided that the following conditions are met: * + * * + * 1. Redistributions of source code must retain the above copyright notice, * + * this list of conditions and the following disclaimer. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the following disclaimer in the * + * documentation and/or other materials provided with the distribution. * + * * + * 3. The end-user documentation included with the redistribution, if any, * + * must include the following acknowlegement: * + * * + * "This product includes software developed by the Apache Software * + * Foundation ." * + * * + * Alternately, this acknowlegement may appear in the software itself, if * + * and wherever such third-party acknowlegements normally appear. * + * * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * + * Foundation" must not be used to endorse or promote products derived * + * from this software without prior written permission. For written * + * permission, please contact . * + * * + * 5. Products derived from this software may not be called "Apache" nor may * + * "Apache" appear in their names without prior written permission of the * + * Apache Software Foundation. * + * * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * + * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * + * POSSIBILITY OF SUCH DAMAGE. * + * * + * ========================================================================= * + * * + * This software consists of voluntary contributions made by many indivi- * + * duals on behalf of the Apache Software Foundation. For more information * + * on the Apache Software Foundation, please see . * + * * + * ========================================================================= */ diff --git a/simplepool-examples/licenses/SimplePool License.txt b/simplepool-examples/licenses/SimplePool License.txt index f4a44ec..75c22f0 100644 --- a/simplepool-examples/licenses/SimplePool License.txt +++ b/simplepool-examples/licenses/SimplePool License.txt @@ -1,38 +1,38 @@ -/* - * $Source$ - * $Revision$ - * $Date$ - * - * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) - * All rights reserved. - * - * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of the authors nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * $Source: /home/cvsroot/manywhere/simplepool/simplepool-examples/licenses/SimplePool\040License.txt,v $ + * $Revision: 1.1 $ + * $Date: 2004/03/20 13:36:08 $ + * + * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) + * All rights reserved. + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ \ No newline at end of file diff --git a/simplepool-examples/servlet/index.jsp b/simplepool-examples/servlet/index.jsp index 68307da..83d0e15 100644 --- a/simplepool-examples/servlet/index.jsp +++ b/simplepool-examples/servlet/index.jsp @@ -1,77 +1,77 @@ - -<%@page import="javax.naming.*" %> - - - -simplepool: Servlet DataSource Examples - - - - - - - - - -
                  -
                  -
                  -

                  simplepool
                  - Servlet DataSource Examples

                  -
                  -

                  Examples Home

                  -

                  Please read the instructions before trying to run the examples.

                  -
                  -
                  - - - - - - - - - - - - - -
                  SummaryA simple database connection pool example using the SimplePool Servlet.
                  Example 1Scriptlet Example [source]
                  Example 2JSTL Example [source]
                  -
                  -
                  -

                  Instructions

                  -

                  The SimplePoolServlet is used to create, access and manage the connection pool.

                  -

                  First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.

                  -

                  The SimplePoolServlet is configured using a set of required initialization parameters, as show in this webapp's WEB-INF/web.xml under the <servlet/> section:

                  -
                    -
                  • The varName initialization parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.
                  • -
                  • The driver initialization parameter is used to specify the name of the JDBC driver class to be registered. For example: com.mysql.jdbc.Driver.
                  • -
                  • The user initialization parameter is used to specify the database username, if any.
                  • -
                  • The password initialization parameter is used to specify the database password, if any.
                  • -
                  • The jdbcUrl initialization parameter is used to specify the JDBC URL associated with the database. For example: jdbc:mysql://localhost:3306/dbname.
                  • -
                  • The minConns initialization parameter is used to specify the minimum number of connections to start the pool with.
                  • -
                  • The maxConns initialization parameter is used to specify the maximum number of connections to be dynamically created in the pool.
                  • -
                  • The maxConnTime initialization parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.
                  • -
                  • The maxCheckoutSeconds initialization parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.
                  • -
                  -

                  Please note that all parameters are required.

                  -

                  Please take a minute to uncomment the <servlet/> declaration and configure the Servlet's initialization parameters in this webapp's WEB-INF/web.xml. Once done, please restart the webapp and/or Tomcat. The examples will be functional upon restart.

                  -

                  Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.

                  -
                  -
                  -
                  -
                  - - + +<%@page import="javax.naming.*" %> + + + +simplepool: Servlet DataSource Examples + + + + + + + + + +
                  +
                  +
                  +

                  simplepool
                  + Servlet DataSource Examples

                  +
                  +

                  Examples Home

                  +

                  Please read the instructions before trying to run the examples.

                  +
                  +
                  + + + + + + + + + + + + + +
                  SummaryA simple database connection pool example using the SimplePool Servlet.
                  Example 1Scriptlet Example [source]
                  Example 2JSTL Example [source]
                  +
                  +
                  +

                  Instructions

                  +

                  The SimplePoolServlet is used to create, access and manage the connection pool.

                  +

                  First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.

                  +

                  The SimplePoolServlet is configured using a set of required initialization parameters, as show in this webapp's WEB-INF/web.xml under the <servlet/> section:

                  +
                    +
                  • The varName initialization parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.
                  • +
                  • The driver initialization parameter is used to specify the name of the JDBC driver class to be registered. For example: com.mysql.jdbc.Driver.
                  • +
                  • The user initialization parameter is used to specify the database username, if any.
                  • +
                  • The password initialization parameter is used to specify the database password, if any.
                  • +
                  • The jdbcUrl initialization parameter is used to specify the JDBC URL associated with the database. For example: jdbc:mysql://localhost:3306/dbname.
                  • +
                  • The minConns initialization parameter is used to specify the minimum number of connections to start the pool with.
                  • +
                  • The maxConns initialization parameter is used to specify the maximum number of connections to be dynamically created in the pool.
                  • +
                  • The maxConnTime initialization parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.
                  • +
                  • The maxCheckoutSeconds initialization parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.
                  • +
                  +

                  Please note that all parameters are required.

                  +

                  Please take a minute to uncomment the <servlet/> declaration and configure the Servlet's initialization parameters in this webapp's WEB-INF/web.xml. Once done, please restart the webapp and/or Tomcat. The examples will be functional upon restart.

                  +

                  Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.

                  +
                  +
                  +
                  +
                  + + diff --git a/simplepool-examples/servlet/jstl.jsp b/simplepool-examples/servlet/jstl.jsp index a895343..8cf9397 100644 --- a/simplepool-examples/servlet/jstl.jsp +++ b/simplepool-examples/servlet/jstl.jsp @@ -1,27 +1,27 @@ -<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> -<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> - - - SimplePool Servlet/JSTL Example +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> +<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> + + + SimplePool Servlet/JSTL Example - - - <%-- Execute the query using our DataSource --%> - + + + <%-- Execute the query using our DataSource --%> + SHOW TABLES - - + +

                  Tables

                  -
                    - - <%-- - Loop through the result set and - display the current column value - --%> +
                      + + <%-- + Loop through the result set and + display the current column value + --%>
                    • -
                      - -
                        + + +
                          \ No newline at end of file diff --git a/simplepool-examples/servlet/scriptlet.jsp b/simplepool-examples/servlet/scriptlet.jsp index fa83103..438ee2d 100644 --- a/simplepool-examples/servlet/scriptlet.jsp +++ b/simplepool-examples/servlet/scriptlet.jsp @@ -1,44 +1,44 @@ -<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %> - - - SimplePool Servlet Example +<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %> + + + SimplePool Servlet Example - - - <% + + + <% // Get a reference to our DataSource - DataSource ds = (DataSource) pageContext.findAttribute("ServletPoolDS"); - - // Get a connection from the pool - Connection conn = ds.getConnection(); - - // Create a new statement - Statement stmt = conn.createStatement(); - - // Execute the query - ResultSet rst = stmt.executeQuery("SHOW TABLES"); - %> - + DataSource ds = (DataSource) pageContext.findAttribute("ServletPoolDS"); + + // Get a connection from the pool + Connection conn = ds.getConnection(); + + // Create a new statement + Statement stmt = conn.createStatement(); + + // Execute the query + ResultSet rst = stmt.executeQuery("SHOW TABLES"); + %> +

                          Tables

                          -
                            - <% - // Loop through the result set and - // display the current column value - while (rst.next()) { - %> -
                          • <%= rst.getString(1) %>
                          • - <% - } - %> -
                              - - <% - // Close the result set, statement and connection - // and display the current column value - rst.close(); - stmt.close(); - conn.close(); - %> +
                                + <% + // Loop through the result set and + // display the current column value + while (rst.next()) { + %> +
                              • <%= rst.getString(1) %>
                              • + <% + } + %> +
                                  + + <% + // Close the result set, statement and connection + // and display the current column value + rst.close(); + stmt.close(); + conn.close(); + %> - + diff --git a/simplepool-examples/source.jsp b/simplepool-examples/source.jsp index 7c080eb..b13d783 100644 --- a/simplepool-examples/source.jsp +++ b/simplepool-examples/source.jsp @@ -1,25 +1,25 @@ -<%@page import="java.io.*"%> - - -
                                  -<%
                                  +<%@page import="java.io.*"%>
                                  +
                                  +
                                  +
                                  +<%
                                   	String file = request.getParameter("file"); 
                                   	if ((file != null) && (file.trim().length() > 0) && (file.indexOf( ".." ) == -1)) { 
                                   		InputStream is = pageContext.getServletContext().getResourceAsStream(file); 
                                  -		if (is != null) {
                                  -			InputStreamReader isr = new InputStreamReader(is);
                                  -			for (int ch = isr.read(); ch != -1; ch = isr.read()) {
                                  -				if (ch == '<') {
                                  -					out.print("<");
                                  -				} else if (ch == '\t') {
                                  -					out.print("  ");
                                  -				} else {
                                  -					out.print((char) ch);
                                  -				}
                                  -			}
                                  -		}       
                                  -	}
                                  -%>
                                  -
                                  + if (is != null) { + InputStreamReader isr = new InputStreamReader(is); + for (int ch = isr.read(); ch != -1; ch = isr.read()) { + if (ch == '<') { + out.print("<"); + } else if (ch == '\t') { + out.print(" "); + } else { + out.print((char) ch); + } + } + } + } +%> +
                                  diff --git a/src/net/java/dev/simplepool/SimplePool.java b/src/net/java/dev/simplepool/SimplePool.java index eae8267..ef96776 100644 --- a/src/net/java/dev/simplepool/SimplePool.java +++ b/src/net/java/dev/simplepool/SimplePool.java @@ -1,7 +1,7 @@ /* - * $Source$ - * $Revision$ - * $Date$ + * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePool.java,v $ + * $Revision: 1.5 $ + * $Date: 2004/03/17 23:35:36 $ * * Copyright (c) 2002, Marc A. Mnich (http://www.javaexchange.com/) * All rights reserved. @@ -33,7 +33,7 @@ import java.util.Date; * @author Marc A. Mnich * @author Russell Beattie * @author Erik C. Thauvin - * @version $Revision$, $Date$ + * @version $Revision: 1.5 $, $Date: 2004/03/17 23:35:36 $ * @since 1.0 */ public class SimplePool implements Runnable { diff --git a/src/net/java/dev/simplepool/SimplePoolConnection.java b/src/net/java/dev/simplepool/SimplePoolConnection.java index 8dada04..f62eff8 100644 --- a/src/net/java/dev/simplepool/SimplePoolConnection.java +++ b/src/net/java/dev/simplepool/SimplePoolConnection.java @@ -1,357 +1,357 @@ -/* - * $Source$ - * $Revision$ - * $Date$ - * - * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) - * All rights reserved. - * - * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of the authors nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.java.dev.simplepool; - -import java.sql.*; -import java.util.Map; - - -/** - * Basic implementation of {@link java.sql.Connection}. - * - * @author Russell Beattie - * @author Erik C. Thauvin - * @version $Revision$, $Date$ - * @since 1.0 - */ -public class SimplePoolConnection implements Connection { - - private Connection conn; - private SimplePool pool; - - /** - * Creates a new SimplePoolConnection object. - * - * @param pool The connection pool. - */ - public SimplePoolConnection(SimplePool pool) { - this.pool = pool; - conn = pool.getConnection(); - } - - /** - * See {@link java.sql.Connection#setAutoCommit(boolean)}. - */ - public void setAutoCommit(boolean autoCommit) - throws SQLException { - conn.setAutoCommit(autoCommit); - } - - /** - * See {@link java.sql.Connection#getAutoCommit}. - */ - public boolean getAutoCommit() - throws SQLException { - return conn.getAutoCommit(); - } - - /** - * See {@link java.sql.Connection#setCatalog(String)}. - */ - public void setCatalog(String catalog) - throws SQLException { - conn.setCatalog(catalog); - } - - /** - * See {@link java.sql.Connection#getCatalog()}. - */ - public String getCatalog() - throws SQLException { - return conn.getCatalog(); - } - - /** - * See {@link java.sql.Connection#isClosed}. - */ - public boolean isClosed() - throws SQLException { - return conn.isClosed(); - } - - /** - * See {@link java.sql.Connection#setHoldability(int)}. - */ - public void setHoldability(int holdability) - throws SQLException { - conn.setHoldability(holdability); - } - - /** - * See {@link java.sql.Connection#getHoldability}. - */ - public int getHoldability() - throws SQLException { - return conn.getHoldability(); - } - - /** - * See {@link java.sql.Connection#getMetaData}. - */ - public DatabaseMetaData getMetaData() - throws SQLException { - return conn.getMetaData(); - } - - /** - * See {@link java.sql.Connection#setReadOnly(boolean)}. - */ - public void setReadOnly(boolean readOnly) - throws SQLException { - conn.setReadOnly(readOnly); - } - - /** - * See {@link java.sql.Connection#isReadOnly}. - */ - public boolean isReadOnly() - throws SQLException { - return conn.isReadOnly(); - } - - /** - * See {@link java.sql.Connection#setSavepoint}. - */ - public Savepoint setSavepoint() - throws SQLException { - return conn.setSavepoint(); - } - - /** - * See {@link java.sql.Connection#setSavepoint(String)}. - */ - public Savepoint setSavepoint(String savepoint) - throws SQLException { - return conn.setSavepoint(savepoint); - } - - /** - * See {@link java.sql.Connection#setTransactionIsolation(int)}. - */ - public void setTransactionIsolation(int level) - throws SQLException { - conn.setTransactionIsolation(level); - } - - /** - * See {@link java.sql.Connection#getTransactionIsolation}. - */ - public int getTransactionIsolation() - throws SQLException { - return conn.getTransactionIsolation(); - } - - /** - * See {@link java.sql.Connection#setTypeMap(Map)}. - */ - public void setTypeMap(Map map) - throws SQLException { - conn.setTypeMap(map); - } - - /** - * See {@link java.sql.Connection#getTypeMap}. - */ - public Map getTypeMap() - throws SQLException { - return conn.getTypeMap(); - } - - /** - * See {@link java.sql.Connection#getWarnings}. - */ - public SQLWarning getWarnings() - throws SQLException { - return conn.getWarnings(); - } - - /** - * See {@link java.sql.Connection#clearWarnings}. - */ - public void clearWarnings() - throws SQLException { - conn.clearWarnings(); - } - - /** - * See {@link java.sql.Connection#close}. - */ - public void close() - throws SQLException { - pool.freeConnection(conn); - } - - /** - * See {@link java.sql.Connection#commit}. - */ - public void commit() - throws SQLException { - conn.commit(); - } - - /** - * See {@link java.sql.Connection#createStatement}. - */ - public Statement createStatement() - throws SQLException { - return conn.createStatement(); - } - - /** - * See {@link java.sql.Connection#createStatement(int, int)}. - */ - public Statement createStatement(int resultSetType, int resultSetConcurrency) - throws SQLException { - return conn.createStatement(resultSetType, resultSetConcurrency); - } - - /** - * See {@link java.sql.Connection#createStatement(int, int, int)}. - */ - public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); - } - - /** - * See {@link java.sql.Connection#nativeSQL(String)}. - */ - public String nativeSQL(String sql) - throws SQLException { - return conn.nativeSQL(sql); - } - - /** - * See {@link java.sql.Connection#prepareCall(String)}. - */ - public CallableStatement prepareCall(String sql) - throws SQLException { - return conn.prepareCall(sql); - } - - /** - * See {@link java.sql.Connection#prepareCall(String, int, int)}. - */ - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - return conn.prepareCall(sql, resultSetType, resultSetConcurrency); - } - - /** - * See {@link java.sql.Connection#prepareCall(String, int, int, int)}. - */ - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability) - throws SQLException { - return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - } - - /** - * See {@link java.sql.Connection#prepareStatement(String)}. - */ - public PreparedStatement prepareStatement(String sql) - throws SQLException { - return conn.prepareStatement(sql); - } - - /** - * See {@link java.sql.Connection#prepareStatement(String)}. - */ - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) - throws SQLException { - return conn.prepareStatement(sql); - } - - /** - * See {@link java.sql.Connection#prepareStatement(String, int, int)}. - */ - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - return conn.prepareStatement(sql, resultSetType, resultSetConcurrency); - } - - /** - * See {@link java.sql.Connection#prepareStatement(String, int, int, int)}. - */ - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability) - throws SQLException { - return conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - } - - /** - * See {@link java.sql.Connection#prepareStatement(String, int[])}. - */ - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) - throws SQLException { - return conn.prepareStatement(sql, columnIndexes); - } - - /** - * See {@link java.sql.Connection#prepareStatement(String, String[])}. - */ - public PreparedStatement prepareStatement(String sql, String[] columnNames) - throws SQLException { - return conn.prepareStatement(sql, columnNames); - } - - /** - * See {@link java.sql.Connection#releaseSavepoint(Savepoint)}. - */ - public void releaseSavepoint(Savepoint savepoint) - throws SQLException { - conn.releaseSavepoint(savepoint); - } - - /** - * See {@link java.sql.Connection#rollback}. - */ - public void rollback() - throws SQLException { - conn.rollback(); - } - - /** - * See {@link java.sql.Connection#rollback(Savepoint)}. - */ - public void rollback(Savepoint savepoint) - throws SQLException { - conn.rollback(savepoint); - } -} +/* + * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePoolConnection.java,v $ + * $Revision: 1.5 $ + * $Date: 2004/03/17 23:35:36 $ + * + * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) + * All rights reserved. + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.java.dev.simplepool; + +import java.sql.*; +import java.util.Map; + + +/** + * Basic implementation of {@link java.sql.Connection}. + * + * @author Russell Beattie + * @author Erik C. Thauvin + * @version $Revision: 1.5 $, $Date: 2004/03/17 23:35:36 $ + * @since 1.0 + */ +public class SimplePoolConnection implements Connection { + + private Connection conn; + private SimplePool pool; + + /** + * Creates a new SimplePoolConnection object. + * + * @param pool The connection pool. + */ + public SimplePoolConnection(SimplePool pool) { + this.pool = pool; + conn = pool.getConnection(); + } + + /** + * See {@link java.sql.Connection#setAutoCommit(boolean)}. + */ + public void setAutoCommit(boolean autoCommit) + throws SQLException { + conn.setAutoCommit(autoCommit); + } + + /** + * See {@link java.sql.Connection#getAutoCommit}. + */ + public boolean getAutoCommit() + throws SQLException { + return conn.getAutoCommit(); + } + + /** + * See {@link java.sql.Connection#setCatalog(String)}. + */ + public void setCatalog(String catalog) + throws SQLException { + conn.setCatalog(catalog); + } + + /** + * See {@link java.sql.Connection#getCatalog()}. + */ + public String getCatalog() + throws SQLException { + return conn.getCatalog(); + } + + /** + * See {@link java.sql.Connection#isClosed}. + */ + public boolean isClosed() + throws SQLException { + return conn.isClosed(); + } + + /** + * See {@link java.sql.Connection#setHoldability(int)}. + */ + public void setHoldability(int holdability) + throws SQLException { + conn.setHoldability(holdability); + } + + /** + * See {@link java.sql.Connection#getHoldability}. + */ + public int getHoldability() + throws SQLException { + return conn.getHoldability(); + } + + /** + * See {@link java.sql.Connection#getMetaData}. + */ + public DatabaseMetaData getMetaData() + throws SQLException { + return conn.getMetaData(); + } + + /** + * See {@link java.sql.Connection#setReadOnly(boolean)}. + */ + public void setReadOnly(boolean readOnly) + throws SQLException { + conn.setReadOnly(readOnly); + } + + /** + * See {@link java.sql.Connection#isReadOnly}. + */ + public boolean isReadOnly() + throws SQLException { + return conn.isReadOnly(); + } + + /** + * See {@link java.sql.Connection#setSavepoint}. + */ + public Savepoint setSavepoint() + throws SQLException { + return conn.setSavepoint(); + } + + /** + * See {@link java.sql.Connection#setSavepoint(String)}. + */ + public Savepoint setSavepoint(String savepoint) + throws SQLException { + return conn.setSavepoint(savepoint); + } + + /** + * See {@link java.sql.Connection#setTransactionIsolation(int)}. + */ + public void setTransactionIsolation(int level) + throws SQLException { + conn.setTransactionIsolation(level); + } + + /** + * See {@link java.sql.Connection#getTransactionIsolation}. + */ + public int getTransactionIsolation() + throws SQLException { + return conn.getTransactionIsolation(); + } + + /** + * See {@link java.sql.Connection#setTypeMap(Map)}. + */ + public void setTypeMap(Map map) + throws SQLException { + conn.setTypeMap(map); + } + + /** + * See {@link java.sql.Connection#getTypeMap}. + */ + public Map getTypeMap() + throws SQLException { + return conn.getTypeMap(); + } + + /** + * See {@link java.sql.Connection#getWarnings}. + */ + public SQLWarning getWarnings() + throws SQLException { + return conn.getWarnings(); + } + + /** + * See {@link java.sql.Connection#clearWarnings}. + */ + public void clearWarnings() + throws SQLException { + conn.clearWarnings(); + } + + /** + * See {@link java.sql.Connection#close}. + */ + public void close() + throws SQLException { + pool.freeConnection(conn); + } + + /** + * See {@link java.sql.Connection#commit}. + */ + public void commit() + throws SQLException { + conn.commit(); + } + + /** + * See {@link java.sql.Connection#createStatement}. + */ + public Statement createStatement() + throws SQLException { + return conn.createStatement(); + } + + /** + * See {@link java.sql.Connection#createStatement(int, int)}. + */ + public Statement createStatement(int resultSetType, int resultSetConcurrency) + throws SQLException { + return conn.createStatement(resultSetType, resultSetConcurrency); + } + + /** + * See {@link java.sql.Connection#createStatement(int, int, int)}. + */ + public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + } + + /** + * See {@link java.sql.Connection#nativeSQL(String)}. + */ + public String nativeSQL(String sql) + throws SQLException { + return conn.nativeSQL(sql); + } + + /** + * See {@link java.sql.Connection#prepareCall(String)}. + */ + public CallableStatement prepareCall(String sql) + throws SQLException { + return conn.prepareCall(sql); + } + + /** + * See {@link java.sql.Connection#prepareCall(String, int, int)}. + */ + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return conn.prepareCall(sql, resultSetType, resultSetConcurrency); + } + + /** + * See {@link java.sql.Connection#prepareCall(String, int, int, int)}. + */ + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) + throws SQLException { + return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } + + /** + * See {@link java.sql.Connection#prepareStatement(String)}. + */ + public PreparedStatement prepareStatement(String sql) + throws SQLException { + return conn.prepareStatement(sql); + } + + /** + * See {@link java.sql.Connection#prepareStatement(String)}. + */ + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) + throws SQLException { + return conn.prepareStatement(sql); + } + + /** + * See {@link java.sql.Connection#prepareStatement(String, int, int)}. + */ + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return conn.prepareStatement(sql, resultSetType, resultSetConcurrency); + } + + /** + * See {@link java.sql.Connection#prepareStatement(String, int, int, int)}. + */ + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) + throws SQLException { + return conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } + + /** + * See {@link java.sql.Connection#prepareStatement(String, int[])}. + */ + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) + throws SQLException { + return conn.prepareStatement(sql, columnIndexes); + } + + /** + * See {@link java.sql.Connection#prepareStatement(String, String[])}. + */ + public PreparedStatement prepareStatement(String sql, String[] columnNames) + throws SQLException { + return conn.prepareStatement(sql, columnNames); + } + + /** + * See {@link java.sql.Connection#releaseSavepoint(Savepoint)}. + */ + public void releaseSavepoint(Savepoint savepoint) + throws SQLException { + conn.releaseSavepoint(savepoint); + } + + /** + * See {@link java.sql.Connection#rollback}. + */ + public void rollback() + throws SQLException { + conn.rollback(); + } + + /** + * See {@link java.sql.Connection#rollback(Savepoint)}. + */ + public void rollback(Savepoint savepoint) + throws SQLException { + conn.rollback(savepoint); + } +} diff --git a/src/net/java/dev/simplepool/SimplePoolDataSource.java b/src/net/java/dev/simplepool/SimplePoolDataSource.java index e756646..39d2250 100644 --- a/src/net/java/dev/simplepool/SimplePoolDataSource.java +++ b/src/net/java/dev/simplepool/SimplePoolDataSource.java @@ -1,319 +1,319 @@ -/* - * $Source$ - * $Revision$ - * $Date$ - * - * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) - * All rights reserved. - * - * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of the authors nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.java.dev.simplepool; - -import javax.sql.DataSource; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; - -/** - * Basic implementation of {@link javax.sql.DataSource}. - * - * @author Russell Beattie - * @author Erik C. Thauvin - * @version $Revision$, $Date$ - * @since 1.0 - */ -public class SimplePoolDataSource implements DataSource { - - private PrintWriter logWriter = new PrintWriter(System.out); - private SimplePool pool = null; - - private String driver = ""; - private String jdbcUrl = ""; - private String user = ""; - private String password = ""; - private String minConns = ""; - private String maxConns = ""; - private String maxConnTime = ""; - private String maxCheckoutSeconds = ""; - - /** - * Initializes the connection pool. - * - * @throws Exception if the pool could not be intialized. - */ - protected void init() throws Exception { - - pool = new SimplePool(driver, jdbcUrl, user, password, - Integer.parseInt(minConns), Integer.parseInt(maxConns), - Double.parseDouble(maxConnTime), Integer.parseInt(maxCheckoutSeconds)); - - } - - /** - * See {@link javax.sql.DataSource#getConnection()}. - */ - public Connection getConnection() throws SQLException { - - if (pool == null) { - try { - init(); - } catch (Exception e) { - throw new SQLException("Error initializing Connection Broker."); - } - } - - return new SimplePoolConnection(pool); - - } - - /** - * See {@link javax.sql.DataSource#getConnection(String, String)}. - */ - public Connection getConnection(String username, String password) - throws SQLException { - - throw new SQLException("Not supported in this DataSource."); - - } - - /** - * See {@link javax.sql.DataSource#setLogWriter(PrintWriter)}. - */ - public void setLogWriter(PrintWriter out) throws SQLException { - logWriter = out; - } - - /** - * See {@link javax.sql.DataSource#getLogWriter}. - */ - public PrintWriter getLogWriter() { - return logWriter; - } - - /** - * See {@link javax.sql.DataSource#setLoginTimeout(int)}. - */ - public void setLoginTimeout(int seconds) throws SQLException { - } - - /** - * See {@link javax.sql.DataSource#getLoginTimeout}. - */ - public int getLoginTimeout() { - return 0; - } - - /** - * Closes the connection pool. - */ - public void close() { - pool.destroy(); - pool = null; - } - - /** - * Sets the JDBC driver. - * - * @param driver The JDBC driver. e.g. 'com.mysql.jdbc.Driver' - * - * @see #getDriver() - */ - public void setDriver(String driver) { - this.driver = driver; - } - - /** - * Gets the JDBC driver. - * - * @return The JDBC driver string. - * - * @see #setDriver(String) - */ - public String getDriver() { - return driver; - } - - /** - * Sets the JDBC connect string. - * - * @param jdbcUrl The JDBC connection URL string. e.g. 'jdbc:mysql://localhost:3306/dbname' - * - * @see #getJdbcUrl() - */ - public void setJdbcUrl(String jdbcUrl) { - this.jdbcUrl = jdbcUrl; - } - - /** - * Gets the JDBC connect string. - * - * @return The JDBC connection URL string. - * - * @see #setJdbcUrl(String) - */ - public String getJdbcUrl() { - return jdbcUrl; - } - - /** - * Sets the database login name. - * - * @param user The database login name. e.g. 'Scott' - * - * @see #getUser() - */ - public void setUser(String user) { - this.user = user; - } - - /** - * Gets the database login name. - * - * @return The login name string. - * - * @see #setUser(String) - */ - public String getUser() { - return user; - } - - /** - * Sets the database password. - * - * @param password The database password. e.g. 'Tiger' - * - * @see #getPassword() - */ - public void setPassword(String password) { - this.password = password; - } - - /** - * Gets the database password. - * - * @return The password string. - * - * @see #setPassword(String) - */ - public String getPassword() { - return password; - } - - /** - * Sets the minimum number of connections to start with. - * - * @param minConns The minimum number of connections. - * - * @see #getMinConns() - */ - public void setMinConns(String minConns) { - this.minConns = minConns; - } - - /** - * Gets the minimum number of connections to start with. - * - * @return The minimum number of connections string. - * - * @see #setMinConns(String) - */ - public String getMinConns() { - return minConns; - } - - /** - * Sets the maximum number of connections in dynamic pool. - * - * @param maxConns The maximum number of connections. - * - * @see #getMaxConns() - */ - public void setMaxConns(String maxConns) { - this.maxConns = maxConns; - } - - /** - * Gets the maximum number of connections in dynamic pool. - * - * @return The maximum number of connection string. - * - * @see #setMaxConns(String) - */ - public String getMaxConns() { - return maxConns; - } - - /** - * Sets the time in days between connection resets. - * - * @param maxConnTime The maximum connection time. - * - * @see #getMaxConnTime() - */ - public void setMaxConnTime(String maxConnTime) { - this.maxConnTime = maxConnTime; - } - - /** - * Gets the time in days between connection resets. - * - * @return The maximum connection time string. - * - * @see #setMaxConnTime(String) - */ - public String getMaxConnTime() { - return maxConnTime; - } - - /** - * Sets the max time a connection can be checked out before being recycled. - * - * @param maxCheckoutSeconds The maximum number of seconds to wait before recycling a connection. - * - * @see #getMaxCheckoutSeconds() - */ - public void setMaxCheckoutSeconds(String maxCheckoutSeconds) { - this.maxCheckoutSeconds = maxCheckoutSeconds; - } - - /** - * Gets the max time a connection can be checked out before being recycled. - * - * @return The maximum checkout time string. - * - * @see #setMaxCheckoutSeconds(String) - */ - public String getMaxCheckoutSeconds() { - return maxCheckoutSeconds; - } - +/* + * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePoolDataSource.java,v $ + * $Revision: 1.4 $ + * $Date: 2004/03/17 23:19:02 $ + * + * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) + * All rights reserved. + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.java.dev.simplepool; + +import javax.sql.DataSource; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; + +/** + * Basic implementation of {@link javax.sql.DataSource}. + * + * @author Russell Beattie + * @author Erik C. Thauvin + * @version $Revision: 1.4 $, $Date: 2004/03/17 23:19:02 $ + * @since 1.0 + */ +public class SimplePoolDataSource implements DataSource { + + private PrintWriter logWriter = new PrintWriter(System.out); + private SimplePool pool = null; + + private String driver = ""; + private String jdbcUrl = ""; + private String user = ""; + private String password = ""; + private String minConns = ""; + private String maxConns = ""; + private String maxConnTime = ""; + private String maxCheckoutSeconds = ""; + + /** + * Initializes the connection pool. + * + * @throws Exception if the pool could not be intialized. + */ + protected void init() throws Exception { + + pool = new SimplePool(driver, jdbcUrl, user, password, + Integer.parseInt(minConns), Integer.parseInt(maxConns), + Double.parseDouble(maxConnTime), Integer.parseInt(maxCheckoutSeconds)); + + } + + /** + * See {@link javax.sql.DataSource#getConnection()}. + */ + public Connection getConnection() throws SQLException { + + if (pool == null) { + try { + init(); + } catch (Exception e) { + throw new SQLException("Error initializing Connection Broker."); + } + } + + return new SimplePoolConnection(pool); + + } + + /** + * See {@link javax.sql.DataSource#getConnection(String, String)}. + */ + public Connection getConnection(String username, String password) + throws SQLException { + + throw new SQLException("Not supported in this DataSource."); + + } + + /** + * See {@link javax.sql.DataSource#setLogWriter(PrintWriter)}. + */ + public void setLogWriter(PrintWriter out) throws SQLException { + logWriter = out; + } + + /** + * See {@link javax.sql.DataSource#getLogWriter}. + */ + public PrintWriter getLogWriter() { + return logWriter; + } + + /** + * See {@link javax.sql.DataSource#setLoginTimeout(int)}. + */ + public void setLoginTimeout(int seconds) throws SQLException { + } + + /** + * See {@link javax.sql.DataSource#getLoginTimeout}. + */ + public int getLoginTimeout() { + return 0; + } + + /** + * Closes the connection pool. + */ + public void close() { + pool.destroy(); + pool = null; + } + + /** + * Sets the JDBC driver. + * + * @param driver The JDBC driver. e.g. 'com.mysql.jdbc.Driver' + * + * @see #getDriver() + */ + public void setDriver(String driver) { + this.driver = driver; + } + + /** + * Gets the JDBC driver. + * + * @return The JDBC driver string. + * + * @see #setDriver(String) + */ + public String getDriver() { + return driver; + } + + /** + * Sets the JDBC connect string. + * + * @param jdbcUrl The JDBC connection URL string. e.g. 'jdbc:mysql://localhost:3306/dbname' + * + * @see #getJdbcUrl() + */ + public void setJdbcUrl(String jdbcUrl) { + this.jdbcUrl = jdbcUrl; + } + + /** + * Gets the JDBC connect string. + * + * @return The JDBC connection URL string. + * + * @see #setJdbcUrl(String) + */ + public String getJdbcUrl() { + return jdbcUrl; + } + + /** + * Sets the database login name. + * + * @param user The database login name. e.g. 'Scott' + * + * @see #getUser() + */ + public void setUser(String user) { + this.user = user; + } + + /** + * Gets the database login name. + * + * @return The login name string. + * + * @see #setUser(String) + */ + public String getUser() { + return user; + } + + /** + * Sets the database password. + * + * @param password The database password. e.g. 'Tiger' + * + * @see #getPassword() + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * Gets the database password. + * + * @return The password string. + * + * @see #setPassword(String) + */ + public String getPassword() { + return password; + } + + /** + * Sets the minimum number of connections to start with. + * + * @param minConns The minimum number of connections. + * + * @see #getMinConns() + */ + public void setMinConns(String minConns) { + this.minConns = minConns; + } + + /** + * Gets the minimum number of connections to start with. + * + * @return The minimum number of connections string. + * + * @see #setMinConns(String) + */ + public String getMinConns() { + return minConns; + } + + /** + * Sets the maximum number of connections in dynamic pool. + * + * @param maxConns The maximum number of connections. + * + * @see #getMaxConns() + */ + public void setMaxConns(String maxConns) { + this.maxConns = maxConns; + } + + /** + * Gets the maximum number of connections in dynamic pool. + * + * @return The maximum number of connection string. + * + * @see #setMaxConns(String) + */ + public String getMaxConns() { + return maxConns; + } + + /** + * Sets the time in days between connection resets. + * + * @param maxConnTime The maximum connection time. + * + * @see #getMaxConnTime() + */ + public void setMaxConnTime(String maxConnTime) { + this.maxConnTime = maxConnTime; + } + + /** + * Gets the time in days between connection resets. + * + * @return The maximum connection time string. + * + * @see #setMaxConnTime(String) + */ + public String getMaxConnTime() { + return maxConnTime; + } + + /** + * Sets the max time a connection can be checked out before being recycled. + * + * @param maxCheckoutSeconds The maximum number of seconds to wait before recycling a connection. + * + * @see #getMaxCheckoutSeconds() + */ + public void setMaxCheckoutSeconds(String maxCheckoutSeconds) { + this.maxCheckoutSeconds = maxCheckoutSeconds; + } + + /** + * Gets the max time a connection can be checked out before being recycled. + * + * @return The maximum checkout time string. + * + * @see #setMaxCheckoutSeconds(String) + */ + public String getMaxCheckoutSeconds() { + return maxCheckoutSeconds; + } + } \ No newline at end of file diff --git a/src/net/java/dev/simplepool/SimplePoolDataSourceFactory.java b/src/net/java/dev/simplepool/SimplePoolDataSourceFactory.java index ce845f3..659df5e 100644 --- a/src/net/java/dev/simplepool/SimplePoolDataSourceFactory.java +++ b/src/net/java/dev/simplepool/SimplePoolDataSourceFactory.java @@ -1,141 +1,141 @@ -/* - * $Source$ - * $Revision$ - * $Date$ - * - * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) - * All rights reserved. - * - * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of the authors nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.java.dev.simplepool; - -import javax.naming.Context; -import javax.naming.Name; -import javax.naming.Reference; -import javax.naming.spi.ObjectFactory; -import java.util.Hashtable; - -/** - * JNDI object factory that creates an instance of {@link SimplePoolDataSource}. - * - * @author Russell Beattie - * @author Erik C. Thauvin - * @version $Revision$, $Date$ - * @since 1.0 - */ -public class SimplePoolDataSourceFactory implements ObjectFactory { - /** - * Creates a {@link SimplePoolDataSource} instance. - * - * @param obj The object containing location or reference information that is used in creating the - * DataSource. - * @param name The name of this object relative to ctx, or null if no name is specified. - * @param ctx The context relative to which the name parameter is specified, or null if - * name is relative to the default initial context. - * @param env The possibly null environment that is used in creating the DataSource. - * - * @return The DataSource; null if it cannot be created. - * - * @throws Exception if the factory encountered an exception while attempting to create the DataSource, - * and no other object factories are to be tried. - */ - public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) - throws Exception { - - Reference ref = (Reference) obj; - SimplePoolDataSource dataSource = new SimplePoolDataSource(); - - /* - driver: JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'
                                  - jdbcUrl: JDBC connect string. e.g. 'jdbc:oracle:thin:@203.92.21.109:1526:orcl'
                                  - user: Database login name. e.g. 'Scott'
                                  - password: Database password. e.g. 'Tiger'
                                  - minConns: Minimum number of connections to start with.
                                  - maxConns: Maximum number of connections in dynamic pool.
                                  - maxConnTime: Time in days between connection resets. (Reset does a basic cleanup)
                                  - maxCheckoutSeconds: Max time a connection can be checked out before being recycled. Zero value turns option - off, default is 60 seconds. - */ - - String driver = (String) ref.get("driver").getContent(); - - if (driver != null) { - dataSource.setDriver(driver); - } - - String user = (String) ref.get("user").getContent(); - - if (user != null) { - dataSource.setUser(user); - } - - String password = (String) ref.get("password").getContent(); - - if (password != null) { - dataSource.setPassword(password); - } - - String jdbcUrl = (String) ref.get("jdbcUrl").getContent(); - - if (jdbcUrl != null) { - dataSource.setJdbcUrl(jdbcUrl); - } - - String minConns = (String) ref.get("minConns").getContent(); - - if (minConns != null) { - dataSource.setMinConns(minConns); - } - - String maxConns = (String) ref.get("maxConns").getContent(); - - if (maxConns != null) { - dataSource.setMaxConns(maxConns); - } - - String maxConnTime = (String) ref.get("maxConnTime").getContent(); - - if (maxConnTime != null) { - dataSource.setMaxConnTime(maxConnTime); - } - - String maxCheckoutSeconds = (String) ref.get("maxCheckoutSeconds").getContent(); - - if (maxCheckoutSeconds != null) { - dataSource.setMaxCheckoutSeconds(maxCheckoutSeconds); - } - - dataSource.init(); - - return dataSource; - } +/* + * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePoolDataSourceFactory.java,v $ + * $Revision: 1.5 $ + * $Date: 2004/03/17 23:19:02 $ + * + * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) + * All rights reserved. + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.java.dev.simplepool; + +import javax.naming.Context; +import javax.naming.Name; +import javax.naming.Reference; +import javax.naming.spi.ObjectFactory; +import java.util.Hashtable; + +/** + * JNDI object factory that creates an instance of {@link SimplePoolDataSource}. + * + * @author Russell Beattie + * @author Erik C. Thauvin + * @version $Revision: 1.5 $, $Date: 2004/03/17 23:19:02 $ + * @since 1.0 + */ +public class SimplePoolDataSourceFactory implements ObjectFactory { + /** + * Creates a {@link SimplePoolDataSource} instance. + * + * @param obj The object containing location or reference information that is used in creating the + * DataSource. + * @param name The name of this object relative to ctx, or null if no name is specified. + * @param ctx The context relative to which the name parameter is specified, or null if + * name is relative to the default initial context. + * @param env The possibly null environment that is used in creating the DataSource. + * + * @return The DataSource; null if it cannot be created. + * + * @throws Exception if the factory encountered an exception while attempting to create the DataSource, + * and no other object factories are to be tried. + */ + public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) + throws Exception { + + Reference ref = (Reference) obj; + SimplePoolDataSource dataSource = new SimplePoolDataSource(); + + /* + driver: JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'
                                  + jdbcUrl: JDBC connect string. e.g. 'jdbc:oracle:thin:@203.92.21.109:1526:orcl'
                                  + user: Database login name. e.g. 'Scott'
                                  + password: Database password. e.g. 'Tiger'
                                  + minConns: Minimum number of connections to start with.
                                  + maxConns: Maximum number of connections in dynamic pool.
                                  + maxConnTime: Time in days between connection resets. (Reset does a basic cleanup)
                                  + maxCheckoutSeconds: Max time a connection can be checked out before being recycled. Zero value turns option + off, default is 60 seconds. + */ + + String driver = (String) ref.get("driver").getContent(); + + if (driver != null) { + dataSource.setDriver(driver); + } + + String user = (String) ref.get("user").getContent(); + + if (user != null) { + dataSource.setUser(user); + } + + String password = (String) ref.get("password").getContent(); + + if (password != null) { + dataSource.setPassword(password); + } + + String jdbcUrl = (String) ref.get("jdbcUrl").getContent(); + + if (jdbcUrl != null) { + dataSource.setJdbcUrl(jdbcUrl); + } + + String minConns = (String) ref.get("minConns").getContent(); + + if (minConns != null) { + dataSource.setMinConns(minConns); + } + + String maxConns = (String) ref.get("maxConns").getContent(); + + if (maxConns != null) { + dataSource.setMaxConns(maxConns); + } + + String maxConnTime = (String) ref.get("maxConnTime").getContent(); + + if (maxConnTime != null) { + dataSource.setMaxConnTime(maxConnTime); + } + + String maxCheckoutSeconds = (String) ref.get("maxCheckoutSeconds").getContent(); + + if (maxCheckoutSeconds != null) { + dataSource.setMaxCheckoutSeconds(maxCheckoutSeconds); + } + + dataSource.init(); + + return dataSource; + } } \ No newline at end of file diff --git a/src/net/java/dev/simplepool/SimplePoolServlet.java b/src/net/java/dev/simplepool/SimplePoolServlet.java index 098e629..7946ee4 100644 --- a/src/net/java/dev/simplepool/SimplePoolServlet.java +++ b/src/net/java/dev/simplepool/SimplePoolServlet.java @@ -1,141 +1,141 @@ -/* - * $Source$ - * $Revision$ - * $Date$ - * - * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) - * All rights reserved. - * - * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of the authors nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.java.dev.simplepool; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; - - -/** - * Creates a pool of database connection based on the specific intialization parameters. - * - * @author Russell Beattie - * @author Erik C. Thauvin - * @version $Revision$, $Date$ - * @since 1.0 - */ -public class SimplePoolServlet extends HttpServlet { - - private static final Log log = LogFactory.getLog(SimplePoolServlet.class); - private static SimplePoolDataSource dataSource; - - /** - * Closes the connection pool. - * - * @see javax.servlet.http.HttpServlet#destroy - */ - public void destroy() { - if (dataSource != null) { - dataSource.close(); - } - } - - /** - * Initializes the connection pool. - *

                                  - * The required intialization parameters are: - *

                                  - *

                                    - *
                                  • varName – Name of the variable used to hold a reference to the - * {@link SimplePoolDataSource}.
                                  • - *
                                  • driver – JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'
                                  • - *
                                  • jdbcUrl – JDBC connect string. e.g. 'jdbc:oracle:thin:@203.92.21.109:1526:orcl'
                                  • - *
                                  • user – Database login name. e.g. 'Scott'
                                  • - *
                                  • password – Database password. e.g. 'Tiger'
                                  • - *
                                  • minConns – Minimum number of connections to start with.
                                  • - *
                                  • maxConns – Maximum number of connections in dynamic pool.
                                  • - *
                                  • maxConnTime – Time in days between connection resets.
                                  • - *
                                  • maxCheckoutSeconds – Max time a connection can be checked out before being recycled.
                                  • - *
                                  - * - * @see javax.servlet.http.HttpServlet#init(ServletConfig) - */ - public void init(ServletConfig servletConfig) - throws ServletException { - log.info("Initializing " + servletConfig.getServletName() + " Servlet"); - - String varName = servletConfig.getInitParameter("varName"); - String driver = servletConfig.getInitParameter("driver"); - String jdbcUrl = servletConfig.getInitParameter("jdbcUrl"); - String user = servletConfig.getInitParameter("user"); - String password = servletConfig.getInitParameter("password"); - String minConns = servletConfig.getInitParameter("minConns"); - String maxConns = servletConfig.getInitParameter("maxConns"); - String maxConnTime = servletConfig.getInitParameter("maxConnTime"); - String maxCheckoutSeconds = servletConfig.getInitParameter("maxCheckoutSeconds"); - - if (isValid(varName) && isValid(driver) && isValid(jdbcUrl) && (user != null) && (password != null) - && isValid(minConns) && isValid(maxConns) && isValid(maxConnTime) && isValid(maxCheckoutSeconds)) { - dataSource = new SimplePoolDataSource(); - - dataSource.setDriver(driver); - dataSource.setJdbcUrl(jdbcUrl); - dataSource.setUser(user); - dataSource.setPassword(password); - dataSource.setMinConns(minConns); - dataSource.setMaxConns(maxConns); - dataSource.setMaxConnTime(maxConnTime); - dataSource.setMaxCheckoutSeconds(maxCheckoutSeconds); - - try { - dataSource.init(); - - servletConfig.getServletContext().setAttribute(varName, dataSource); - } catch (Exception e) { - log.error("An error occurred while starting the connection pool.", e); - throw new ServletException("Error starting the connection pool."); - } - } else { - log.error("One or more intialization parameter is invalid or missing."); - throw new ServletException("Invalid or missing initialization parameter."); - } - } - - private boolean isValid(String s) { - if ((s != null) && (s.length() > 0)) { - return true; - } - - return false; - } -} +/* + * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePoolServlet.java,v $ + * $Revision: 1.5 $ + * $Date: 2004/03/17 23:35:36 $ + * + * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) + * All rights reserved. + * + * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the authors nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.java.dev.simplepool; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; + + +/** + * Creates a pool of database connection based on the specific intialization parameters. + * + * @author Russell Beattie + * @author Erik C. Thauvin + * @version $Revision: 1.5 $, $Date: 2004/03/17 23:35:36 $ + * @since 1.0 + */ +public class SimplePoolServlet extends HttpServlet { + + private static final Log log = LogFactory.getLog(SimplePoolServlet.class); + private static SimplePoolDataSource dataSource; + + /** + * Closes the connection pool. + * + * @see javax.servlet.http.HttpServlet#destroy + */ + public void destroy() { + if (dataSource != null) { + dataSource.close(); + } + } + + /** + * Initializes the connection pool. + *

                                  + * The required intialization parameters are: + *

                                  + *

                                    + *
                                  • varName – Name of the variable used to hold a reference to the + * {@link SimplePoolDataSource}.
                                  • + *
                                  • driver – JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'
                                  • + *
                                  • jdbcUrl – JDBC connect string. e.g. 'jdbc:oracle:thin:@203.92.21.109:1526:orcl'
                                  • + *
                                  • user – Database login name. e.g. 'Scott'
                                  • + *
                                  • password – Database password. e.g. 'Tiger'
                                  • + *
                                  • minConns – Minimum number of connections to start with.
                                  • + *
                                  • maxConns – Maximum number of connections in dynamic pool.
                                  • + *
                                  • maxConnTime – Time in days between connection resets.
                                  • + *
                                  • maxCheckoutSeconds – Max time a connection can be checked out before being recycled.
                                  • + *
                                  + * + * @see javax.servlet.http.HttpServlet#init(ServletConfig) + */ + public void init(ServletConfig servletConfig) + throws ServletException { + log.info("Initializing " + servletConfig.getServletName() + " Servlet"); + + String varName = servletConfig.getInitParameter("varName"); + String driver = servletConfig.getInitParameter("driver"); + String jdbcUrl = servletConfig.getInitParameter("jdbcUrl"); + String user = servletConfig.getInitParameter("user"); + String password = servletConfig.getInitParameter("password"); + String minConns = servletConfig.getInitParameter("minConns"); + String maxConns = servletConfig.getInitParameter("maxConns"); + String maxConnTime = servletConfig.getInitParameter("maxConnTime"); + String maxCheckoutSeconds = servletConfig.getInitParameter("maxCheckoutSeconds"); + + if (isValid(varName) && isValid(driver) && isValid(jdbcUrl) && (user != null) && (password != null) + && isValid(minConns) && isValid(maxConns) && isValid(maxConnTime) && isValid(maxCheckoutSeconds)) { + dataSource = new SimplePoolDataSource(); + + dataSource.setDriver(driver); + dataSource.setJdbcUrl(jdbcUrl); + dataSource.setUser(user); + dataSource.setPassword(password); + dataSource.setMinConns(minConns); + dataSource.setMaxConns(maxConns); + dataSource.setMaxConnTime(maxConnTime); + dataSource.setMaxCheckoutSeconds(maxCheckoutSeconds); + + try { + dataSource.init(); + + servletConfig.getServletContext().setAttribute(varName, dataSource); + } catch (Exception e) { + log.error("An error occurred while starting the connection pool.", e); + throw new ServletException("Error starting the connection pool."); + } + } else { + log.error("One or more intialization parameter is invalid or missing."); + throw new ServletException("Invalid or missing initialization parameter."); + } + } + + private boolean isValid(String s) { + if ((s != null) && (s.length() > 0)) { + return true; + } + + return false; + } +} diff --git a/src/net/java/dev/simplepool/package.html b/src/net/java/dev/simplepool/package.html index e1c1d4f..7137e84 100644 --- a/src/net/java/dev/simplepool/package.html +++ b/src/net/java/dev/simplepool/package.html @@ -1,13 +1,13 @@ - - - - SimplePool API - - -This package contains a simple database connection pool implementation for web applications, specifically those using JSTL. -

                                  -The connection pool can be created, accessed and managed via JNDI or through the {@link net.java.dev.simplepool.SimplePoolServlet}. - -@since 1.0 - - + + + + SimplePool API + + +This package contains a simple database connection pool implementation for web applications, specifically those using JSTL. +

                                  +The connection pool can be created, accessed and managed via JNDI or through the {@link net.java.dev.simplepool.SimplePoolServlet}. + +@since 1.0 + +