Initial commit for Git.

This commit is contained in:
Erik C. Thauvin 2012-05-14 13:37:38 -07:00
parent 98b1521e20
commit 9595f70fd7
27 changed files with 1790 additions and 1780 deletions

View file

@ -1,8 +1,8 @@
*.ipr *.ipr
*.iml *.iml
*.iws *.iws
bin bin
dist dist
build build
classes classes
javadoc javadoc

10
.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
*.ipr
*.iml
*.iws
bin
dist
build
classes
javadoc
/CVS/
CVS

View file

@ -1,26 +1,26 @@
# Project # Project
proj.name=simplepool proj.name=simplepool
proj.version=1.0 proj.version=1.0
# Locations # Locations
path.build=build path.build=build
path.src=src path.src=src
path.dist=dist path.dist=dist
path.lib=lib path.lib=lib
path.javadoc=javadoc path.javadoc=javadoc
# Jar # Jar
jar.name=${proj.name} jar.name=${proj.name}
# Examples # Examples
ex.name=${proj.name}-examples-${proj.version} ex.name=${proj.name}-examples-${proj.version}
path.ex=${proj.name}-examples path.ex=${proj.name}-examples
# Release # Release
release.name=${proj.name}-${proj.version} release.name=${proj.name}-${proj.version}
# Javadoc # Javadoc
javadoc.title=SimplePool API javadoc.title=SimplePool API
javadoc.api.link=http://java.sun.com/j2se/1.4.2/docs/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.servlet.link=http://java.sun.com/products/servlet/2.3/javadoc/
javadoc.packages=net.java.dev.simplepool.* javadoc.packages=net.java.dev.simplepool.*

174
build.xml
View file

@ -1,88 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project name="simplepool" default="build" basedir="."> <project name="simplepool" default="build" basedir=".">
<property file="${basedir}/build.properties" /> <property file="${basedir}/build.properties" />
<property name="path.jar.build" value="${path.build}/${jar.name}"/> <property name="path.jar.build" value="${path.build}/${jar.name}"/>
<property name="path.ex.build" value="${path.build}/${ex.name}"/> <property name="path.ex.build" value="${path.build}/${ex.name}"/>
<property name="path.rel.build" value="${path.build}/${release.name}"/> <property name="path.rel.build" value="${path.build}/${release.name}"/>
<path id="path.source"> <path id="path.source">
<pathelement location="${path.src}" /> <pathelement location="${path.src}" />
</path> </path>
<path id="path.class"> <path id="path.class">
<fileset dir="${path.lib}"> <fileset dir="${path.lib}">
<include name="**/*.jar"/> <include name="**/*.jar"/>
</fileset> </fileset>
</path> </path>
<target name="init"> <target name="init">
<tstamp /> <tstamp />
<mkdir dir="${path.build}"/> <mkdir dir="${path.build}"/>
<mkdir dir="${path.dist}"/> <mkdir dir="${path.dist}"/>
<mkdir dir="${path.javadoc}"/> <mkdir dir="${path.javadoc}"/>
</target> </target>
<target name="compile" depends="init" description="Compiles sources"> <target name="compile" depends="init" description="Compiles sources">
<mkdir dir="${path.jar.build}" /> <mkdir dir="${path.jar.build}" />
<javac sourcepathref="path.source" classpathref="path.class" destdir="${path.jar.build}" debug="off" deprecation="on"> <javac sourcepathref="path.source" classpathref="path.class" destdir="${path.jar.build}" debug="off" deprecation="on">
<src refid="path.source" /> <src refid="path.source" />
</javac> </javac>
</target> </target>
<target name="build" depends="clean,compile,jar" description="Rebuilds project" /> <target name="build" depends="clean,compile,jar" description="Rebuilds project" />
<target name="jar" depends="compile" description="Builds the JAR"> <target name="jar" depends="compile" description="Builds the JAR">
<copy todir="${path.jar.build}"> <copy todir="${path.jar.build}">
<fileset dir="${path.src}" includes="*.properties" /> <fileset dir="${path.src}" includes="*.properties" />
</copy> </copy>
<jar destfile="${basedir}/${path.dist}/${jar.name}.jar" basedir="${path.jar.build}" excludes="**/.dependency-info/**" /> <jar destfile="${basedir}/${path.dist}/${jar.name}.jar" basedir="${path.jar.build}" excludes="**/.dependency-info/**" />
</target> </target>
<target name="examples" depends="build" description="Builds the Examples WAR"> <target name="examples" depends="build" description="Builds the Examples WAR">
<copy todir="${path.ex.build}"> <copy todir="${path.ex.build}">
<fileset dir="${path.ex}"/> <fileset dir="${path.ex}"/>
<filterset> <filterset>
<filter token="EX.NAME" value="${ex.name}"/> <filter token="EX.NAME" value="${ex.name}"/>
</filterset> </filterset>
</copy> </copy>
<copy file="${path.dist}/${jar.name}.jar" todir="${path.ex.build}/WEB-INF/lib/"/> <copy file="${path.dist}/${jar.name}.jar" todir="${path.ex.build}/WEB-INF/lib/"/>
<touch> <touch>
<fileset dir="${path.ex.build}"/> <fileset dir="${path.ex.build}"/>
</touch> </touch>
<jar jarfile="${path.dist}/${ex.name}.war" basedir="${path.ex.build}"/> <jar jarfile="${path.dist}/${ex.name}.war" basedir="${path.ex.build}"/>
</target> </target>
<target name="release" depends="build,javadoc" description="Builds the release archives"> <target name="release" depends="build,javadoc" description="Builds the release archives">
<mkdir dir="${path.rel.build}"/> <mkdir dir="${path.rel.build}"/>
<copy todir="${path.rel.build}"> <copy todir="${path.rel.build}">
<fileset file="${path.dist}/${jar.name}.jar"/> <fileset file="${path.dist}/${jar.name}.jar"/>
<fileset dir="${basedir}" includes="${path.javadoc}/**"/> <fileset dir="${basedir}" includes="${path.javadoc}/**"/>
</copy> </copy>
<touch> <touch>
<fileset dir="${path.rel.build}"/> <fileset dir="${path.rel.build}"/>
</touch> </touch>
<zip destfile="${path.dist}/${release.name}.zip" basedir="${path.build}" includes="${release.name}/**"/> <zip destfile="${path.dist}/${release.name}.zip" basedir="${path.build}" includes="${release.name}/**"/>
<tar tarfile="${path.dist}/${release.name}.tar.gz" compression="gzip"> <tar tarfile="${path.dist}/${release.name}.tar.gz" compression="gzip">
<tarfileset dir="${path.rel.build}" prefix="${release.name}" mode="644"/> <tarfileset dir="${path.rel.build}" prefix="${release.name}" mode="644"/>
</tar> </tar>
</target> </target>
<target name="src" description="Builds the source archive"> <target name="src" description="Builds the source archive">
<tar tarfile="${path.dist}/${release.name}-src.tar.gz" compression="gzip"> <tar tarfile="${path.dist}/${release.name}-src.tar.gz" compression="gzip">
<tarfileset dir="${basedir}" prefix="${release.name}"> <tarfileset dir="${basedir}" prefix="${release.name}">
<include name="${path.src}/**"/> <include name="${path.src}/**"/>
<include name="${path.ex}/**"/> <include name="${path.ex}/**"/>
<include name="${path.lib}/**"/> <include name="${path.lib}/**"/>
<include name="build.*"/> <include name="build.*"/>
</tarfileset> </tarfileset>
</tar> </tar>
</target> </target>
<target name="javadoc" depends="init" description="Builds the Javadoc"> <target name="javadoc" depends="init" description="Builds the Javadoc">
<delete quiet="true" includeEmptyDirs="true"> <delete quiet="true" includeEmptyDirs="true">
<fileset dir="${path.javadoc}" includes="*,*/**"/> <fileset dir="${path.javadoc}" includes="*,*/**"/>
</delete> </delete>
<javadoc sourcepath="${path.src}" destdir="${path.javadoc}" packagenames="${javadoc.packages}" windowtitle="${javadoc.title}" verbose="false" failonerror="true" additionalparam=""> <javadoc sourcepath="${path.src}" destdir="${path.javadoc}" packagenames="${javadoc.packages}" windowtitle="${javadoc.title}" verbose="false" failonerror="true" additionalparam="">
<link href="${javadoc.api.link}"/> <link href="${javadoc.api.link}"/>
<link href="${javadoc.servlet.link}"/> <link href="${javadoc.servlet.link}"/>
<classpath refid="path.class"/> <classpath refid="path.class"/>
</javadoc> </javadoc>
</target> </target>
<target name="clean" depends="init" description="Removes classses and javadoc"> <target name="clean" depends="init" description="Removes classses and javadoc">
<delete quiet="true" includeEmptyDirs="true"> <delete quiet="true" includeEmptyDirs="true">
<fileset dir="${path.build}" includes="*,*/**"/> <fileset dir="${path.build}" includes="*,*/**"/>
<fileset dir="${path.dist}" includes="*,*/**"/> <fileset dir="${path.dist}" includes="*,*/**"/>
<fileset dir="${path.javadoc}" includes="*,*/**"/> <fileset dir="${path.javadoc}" includes="*,*/**"/>
</delete> </delete>
</target> </target>
</project> </project>

View file

@ -1,107 +1,107 @@
<Server port="8005" shutdown="SHUTDOWN" debug="0"> <Server port="8005" shutdown="SHUTDOWN" debug="0">
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" debug="0"/> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" debug="0"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" debug="0"/> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" debug="0"/>
<GlobalNamingResources> <GlobalNamingResources>
<Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase"/> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase"/>
<ResourceParams name="UserDatabase"> <ResourceParams name="UserDatabase">
<parameter> <parameter>
<name>factory</name> <name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value> <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter> </parameter>
<parameter> <parameter>
<name>pathname</name> <name>pathname</name>
<value>conf/tomcat-users.xml</value> <value>conf/tomcat-users.xml</value>
</parameter> </parameter>
</ResourceParams> </ResourceParams>
<Resource name="jdbc/PooledDS" type="javax.sql.DataSource" auth="Container"/> <Resource name="jdbc/PooledDS" type="javax.sql.DataSource" auth="Container"/>
<ResourceParams name="jdbc/PooledDS"> <ResourceParams name="jdbc/PooledDS">
<parameter> <parameter>
<name>factory</name> <name>factory</name>
<value>net.java.dev.simplepool.SimplePoolDataSourceFactory</value> <value>net.java.dev.simplepool.SimplePoolDataSourceFactory</value>
</parameter> </parameter>
<parameter> <parameter>
<name>driver</name> <name>driver</name>
<value>com.mysql.jdbc.Driver</value> <value>com.mysql.jdbc.Driver</value>
</parameter> </parameter>
<parameter> <parameter>
<name>user</name> <name>user</name>
<value>dbuser</value> <value>dbuser</value>
</parameter> </parameter>
<parameter> <parameter>
<name>password</name> <name>password</name>
<value>test</value> <value>test</value>
</parameter> </parameter>
<parameter> <parameter>
<name>jdbcUrl</name> <name>jdbcUrl</name>
<value>jdbc:mysql://localhost:3306/dbname</value> <value>jdbc:mysql://localhost:3306/dbname</value>
</parameter> </parameter>
<parameter> <parameter>
<name>minConns</name> <name>minConns</name>
<value>8</value> <value>8</value>
</parameter> </parameter>
<parameter> <parameter>
<name>maxConns</name> <name>maxConns</name>
<value>30</value> <value>30</value>
</parameter> </parameter>
<parameter> <parameter>
<name>maxConnTime</name> <name>maxConnTime</name>
<value>1</value> <value>1</value>
</parameter> </parameter>
<parameter> <parameter>
<name>maxCheckoutSeconds</name> <name>maxCheckoutSeconds</name>
<value>60</value> <value>60</value>
</parameter> </parameter>
</ResourceParams> </ResourceParams>
</GlobalNamingResources> </GlobalNamingResources>
<Service name="Catalina"> <Service name="Catalina">
<Connector port="80" <Connector port="80"
maxThreads="150" maxThreads="150"
minSpareThreads="25" minSpareThreads="25"
maxSpareThreads="75" maxSpareThreads="75"
enableLookups="false" enableLookups="false"
redirectPort="8443" redirectPort="8443"
acceptCount="100" acceptCount="100"
debug="0" debug="0"
connectionTimeout="20000" connectionTimeout="20000"
proxyPort="80" proxyPort="80"
/> />
<Engine name="Catalina" defaultHost="www.waveblog.com" debug="0"> <Engine name="Catalina" defaultHost="www.waveblog.com" debug="0">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
debug="1" resourceName="UserDatabase"/> debug="1" resourceName="UserDatabase"/>
<Host name="localhost" <Host name="localhost"
debug="1" appBase="webapps" unpackWARs="true" autoDeploy="true" debug="1" appBase="webapps" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false"> xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="ROOT" debug="0" reloadable="true"> <Context path="" docBase="ROOT" debug="0" reloadable="true">
<ResourceLink name="jdbc/PooledDS" global="jdbc/PooledDS" type="javax.sql.DataSource" /> <ResourceLink name="jdbc/PooledDS" global="jdbc/PooledDS" type="javax.sql.DataSource" />
</Context> </Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" <Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="waveblog" suffix=".log" directory="logs" prefix="waveblog" suffix=".log"
pattern="combined" resolveHosts="false"/> pattern="combined" resolveHosts="false"/>
</Host> </Host>
</Engine> </Engine>
</Service> </Service>
</Server> </Server>

View file

@ -1,21 +1,21 @@
<% out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); %> <% out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); %>
<%@ page contentType="text/xml;charset=UTF-8"%> <%@ page contentType="text/xml;charset=UTF-8"%>
<%@ page session="false"%> <%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<sql:setDataSource dataSource="jdbc/PooledDS" /> <sql:setDataSource dataSource="jdbc/PooledDS" />
<sql:query var="page" maxRows="30"> <sql:query var="page" maxRows="30">
select * from entry select * from entry
</sql:query> </sql:query>
<document> <document>
<c:forEach var="row" items="${page.rows}" varStatus="counter"> <c:forEach var="row" items="${page.rows}" varStatus="counter">
<entry> <entry>
<count><c:out value="${counter.count}"/></count> <count><c:out value="${counter.count}"/></count>
<id><c:out value="${row.id}"/></id> <id><c:out value="${row.id}"/></id>
<title><c:out value="${row.name}"/></title> <title><c:out value="${row.name}"/></title>
</entry> </entry>
</c:forEach> </c:forEach>
</document> </document>

Binary file not shown.

View file

@ -1,52 +1,52 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC <!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"> "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app> <web-app>
<description>SimplePool Examples</description> <description>SimplePool Examples</description>
<!-- <!--
<servlet> <servlet>
<servlet-name>SimplePoolServlet</servlet-name> <servlet-name>SimplePoolServlet</servlet-name>
<servlet-class>net.java.dev.simplepool.SimplePoolServlet</servlet-class> <servlet-class>net.java.dev.simplepool.SimplePoolServlet</servlet-class>
<init-param> <init-param>
<param-name>varName</param-name> <param-name>varName</param-name>
<param-value>ServletPoolDS</param-value> <param-value>ServletPoolDS</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>driver</param-name> <param-name>driver</param-name>
<param-value>com.mysql.jdbc.Driver</param-value> <param-value>com.mysql.jdbc.Driver</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>user</param-name> <param-name>user</param-name>
<param-value>dbuser</param-value> <param-value>dbuser</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>password</param-name> <param-name>password</param-name>
<param-value>dbpassword</param-value> <param-value>dbpassword</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>jdbcUrl</param-name> <param-name>jdbcUrl</param-name>
<param-value>jdbc:mysql://localhost:3306/dbname</param-value> <param-value>jdbc:mysql://localhost:3306/dbname</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>minConns</param-name> <param-name>minConns</param-name>
<param-value>8</param-value> <param-value>8</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>maxConns</param-name> <param-name>maxConns</param-name>
<param-value>30</param-value> <param-value>30</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>maxConnTime</param-name> <param-name>maxConnTime</param-name>
<param-value>1</param-value> <param-value>1</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>maxCheckoutSeconds</param-name> <param-name>maxCheckoutSeconds</param-name>
<param-value>60</param-value> <param-value>60</param-value>
</init-param> </init-param>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>
</servlet> </servlet>
--> -->
</web-app> </web-app>

View file

@ -1,62 +1,62 @@
<Server port="8005" shutdown="SHUTDOWN"> <Server port="8005" shutdown="SHUTDOWN">
<Service name="Catalina"> <Service name="Catalina">
<Connector port="80" /> <Connector port="80" />
<Engine name="Catalina" defaultHost="localhost"> <Engine name="Catalina" defaultHost="localhost">
<Logger className="org.apache.catalina.logger.FileLogger" /> <Logger className="org.apache.catalina.logger.FileLogger" />
<Host name="localhost" appBase="webapps"> <Host name="localhost" appBase="webapps">
<!-- Define our application context --> <!-- Define our application context -->
<Context path="/@EX.NAME@" docBase="@EX.NAME@" <Context path="/@EX.NAME@" docBase="@EX.NAME@"
debug="5" reloadable="true" crossContext="true"> debug="5" reloadable="true" crossContext="true">
<!-- Define our JDNI DataSource --> <!-- Define our JDNI DataSource -->
<Resource name="jdbc/JNDIPoolDS" type="javax.sql.DataSource" auth="Container"/> <Resource name="jdbc/JNDIPoolDS" type="javax.sql.DataSource" auth="Container"/>
<!-- Configure our JNDI DataSource --> <!-- Configure our JNDI DataSource -->
<ResourceParams name="jdbc/JNDIPoolDS"> <ResourceParams name="jdbc/JNDIPoolDS">
<parameter> <parameter>
<name>factory</name> <name>factory</name>
<value>net.java.dev.simplepool.SimplePoolDataSourceFactory</value> <value>net.java.dev.simplepool.SimplePoolDataSourceFactory</value>
</parameter> </parameter>
<parameter> <parameter>
<name>driver</name> <name>driver</name>
<value>com.mysql.jdbc.Driver</value> <value>com.mysql.jdbc.Driver</value>
</parameter> </parameter>
<parameter> <parameter>
<name>user</name> <name>user</name>
<value>dbuser</value> <value>dbuser</value>
</parameter> </parameter>
<parameter> <parameter>
<name>password</name> <name>password</name>
<value>dbpassword</value> <value>dbpassword</value>
</parameter> </parameter>
<parameter> <parameter>
<name>jdbcUrl</name> <name>jdbcUrl</name>
<value>jdbc:mysql://localhost:3306/dbname</value> <value>jdbc:mysql://localhost:3306/dbname</value>
</parameter> </parameter>
<parameter> <parameter>
<name>minConns</name> <name>minConns</name>
<value>8</value> <value>8</value>
</parameter> </parameter>
<parameter> <parameter>
<name>maxConns</name> <name>maxConns</name>
<value>30</value> <value>30</value>
</parameter> </parameter>
<parameter> <parameter>
<name>maxConnTime</name> <name>maxConnTime</name>
<value>1</value> <value>1</value>
</parameter> </parameter>
<parameter> <parameter>
<name>maxCheckoutSeconds</name> <name>maxCheckoutSeconds</name>
<value>60</value> <value>60</value>
</parameter> </parameter>
</ResourceParams> </ResourceParams>
</Context> </Context>
</Host> </Host>
</Engine> </Engine>
</Service> </Service>
</Server> </Server>

View file

@ -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. 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.

View file

@ -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. */ 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. */

View file

@ -1,54 +1,54 @@
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
"http://style.tigris.org/tigris_transitional.dtd"> "http://style.tigris.org/tigris_transitional.dtd">
<html> <html>
<head> <head>
<style type="text/css"> <style type="text/css">
/* <![CDATA[ */ /* <![CDATA[ */
@import "includes/tigris.css"; @import "includes/tigris.css";
@import "includes/inst.css"; @import "includes/inst.css";
/* ]]> */ /* ]]> */
</style> </style>
<title>simplepool: Examples</title> <title>simplepool: Examples</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Style-Type" content="text/css" />
</head> </head>
<body marginwidth="0" marginheight="0" class="composite"> <body marginwidth="0" marginheight="0" class="composite">
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main"> <table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
<tr valign="top"> <tr valign="top">
<td> <td>
<div id="bodycol"> <div id="bodycol">
<div id="apphead"> <div id="apphead">
<h2><small>simplepool</small><br /> <h2><small>simplepool</small><br />
Examples</h2> Examples</h2>
</div> </div>
<p class="tasknav"><a href="https://simplepool.dev.java.net/">Project Home</a></p> <p class="tasknav"><a href="https://simplepool.dev.java.net/">Project Home</a></p>
<div id="examples" class="app"> <div id="examples" class="app">
<div class="axial"> <div class="axial">
<table border="0" cellspacing="2" cellpadding="3"> <table border="0" cellspacing="2" cellpadding="3">
<tr> <tr>
<th>Summary</th> <th>Summary</th>
<td>A simple database connection pool for webapps using JSTL.</td> <td>A simple database connection pool for webapps using JSTL.</td>
</tr> </tr>
<tr> <tr>
<th>Example 1</th> <th>Example 1</th>
<td><a href="jndi/index.jsp">JNDI DataSource Examples</a> </td> <td><a href="jndi/index.jsp">JNDI DataSource Examples</a> </td>
</tr> </tr>
<tr> <tr>
<th>Example 2</th> <th>Example 2</th>
<td><a href="servlet/index.jsp">Servlet DataSource Examples</a> </td> <td><a href="servlet/index.jsp">Servlet DataSource Examples</a> </td>
</tr> </tr>
</table> </table>
</div> </div>
<div class="h3" id="longdescription"> <div class="h3" id="longdescription">
<h3>Description</h3> <h3>Description</h3>
<p>SimplePool is a simple database connection pool implementation for web applications, specifically those using <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a>.</p> <p>SimplePool is a simple database connection pool implementation for web applications, specifically those using <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a>.</p>
<p>The connection pool can be created, accessed and managed via <a href="jndi">JNDI</a> or a provided <a href="servlet/">Servlet</a>.</p> <p>The connection pool can be created, accessed and managed via <a href="jndi">JNDI</a> or a provided <a href="servlet/">Servlet</a>.</p>
<p>The examples above have been tailored for use with <a href="http://jakarta.apache.org/tomcat/">Tomcat</a> and <a href="http://www.mysql.com/">MySQL</a>.</p> <p>The examples above have been tailored for use with <a href="http://jakarta.apache.org/tomcat/">Tomcat</a> and <a href="http://www.mysql.com/">MySQL</a>.</p>
</div> </div>
</div> </div>
</div> </div>
</td> </td>
</tr> </tr>
</table> </table>
</body> </body>
</html> </html>

View file

@ -1,84 +1,84 @@
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
"http://style.tigris.org/tigris_transitional.dtd"> "http://style.tigris.org/tigris_transitional.dtd">
<%@page import="javax.naming.*" %> <%@page import="javax.naming.*" %>
<html> <html>
<head> <head>
<style type="text/css"> <style type="text/css">
/* <![CDATA[ */ /* <![CDATA[ */
@import "../includes/tigris.css"; @import "../includes/tigris.css";
@import "../includes/inst.css"; @import "../includes/inst.css";
/* ]]> */ /* ]]> */
</style> </style>
<title>simplepool: JNDI DataSource Examples</title> <title>simplepool: JNDI DataSource Examples</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Style-Type" content="text/css" />
<script language="javascript" type="text/javascript"> <script language="javascript" type="text/javascript">
<% <%
boolean enabled = false; boolean enabled = false;
try { try {
enabled = (new InitialContext().lookup("java:comp/env/jdbc/JNDIPoolDS") != null); enabled = (new InitialContext().lookup("java:comp/env/jdbc/JNDIPoolDS") != null);
} catch (Exception ignore) { } } catch (Exception ignore) { }
%> %>
function RTFM() function RTFM()
{ {
alert("Please read the instructions to enable this example."); alert("Please read the instructions to enable this example.");
} }
</script> </script>
</head> </head>
<body marginwidth="0" marginheight="0" class="composite"> <body marginwidth="0" marginheight="0" class="composite">
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main"> <table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
<tr valign="top"> <tr valign="top">
<td> <td>
<div id="bodycol"> <div id="bodycol">
<div id="apphead"> <div id="apphead">
<h2><small>simplepool</small><br /> <h2><small>simplepool</small><br />
JNDI DataSource Examples</h2> JNDI DataSource Examples</h2>
</div> </div>
<p class="tasknav"><a href="../index.html">Examples Home</a></p> <p class="tasknav"><a href="../index.html">Examples Home</a></p>
<p><strong>Please read the instructions before trying to run the examples.</strong></p> <p><strong>Please read the instructions before trying to run the examples.</strong></p>
<div id="examples" class="app"> <div id="examples" class="app">
<div class="axial"> <div class="axial">
<table border="0" cellspacing="2" cellpadding="3"> <table border="0" cellspacing="2" cellpadding="3">
<tr> <tr>
<th>Summary</th> <th>Summary</th>
<td>A simple database connection pool example using JDNI.</td> <td>A simple database connection pool example using JDNI.</td>
</tr> </tr>
<tr> <tr>
<th>Example 1</th> <th>Example 1</th>
<td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=jndi/scriptlet.jsp">source</a>]</td> <td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=jndi/scriptlet.jsp">source</a>]</td>
</tr> </tr>
<tr> <tr>
<th>Example 2</th> <th>Example 2</th>
<td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=jndi/jstl.jsp">source</a>]</td> <td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=jndi/jstl.jsp">source</a>]</td>
</tr> </tr>
</table> </table>
</div> </div>
<div class="h3" id="instructions"> <div class="h3" id="instructions">
<h3>Instructions</h3> <h3>Instructions</h3>
<p>JNDI is used to create, access and manage the connection pool.</p> <p>JNDI is used to create, access and manage the connection pool.</p>
<p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p> <p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p>
<p class="alert">The JNDI DataSource is defined as naming resource in the current webapp context, as shown in this minimal <a href="../source.jsp?file=conf/server.xml">server configuration file</a>. </p> <p class="alert">The JNDI DataSource is defined as naming resource in the current webapp context, as shown in this minimal <a href="../source.jsp?file=conf/server.xml">server configuration file</a>. </p>
<p>The JNDI DataSource is configured using the following parameters:</p> <p>The JNDI DataSource is configured using the following parameters:</p>
<ul> <ul>
<li>The <span class="info">varName</span> parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li> <li>The <span class="info">varName</span> parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li>
<li>The <span class="info">driver</span> parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li> <li>The <span class="info">driver</span> parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li>
<li>The <span class="info">user</span> parameter is used to specify the database username, if any.</li> <li>The <span class="info">user</span> parameter is used to specify the database username, if any.</li>
<li>The <span class="info">password</span> parameter is used to specify the database password, if any.</li> <li>The <span class="info">password</span> parameter is used to specify the database password, if any.</li>
<li>The <span class="info">jdbcUrl</span> parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li> <li>The <span class="info">jdbcUrl</span> parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li>
<li>The <span class="info">minConns</span> parameter is used to specify the minimum number of connections to start the pool with.</li> <li>The <span class="info">minConns</span> parameter is used to specify the minimum number of connections to start the pool with.</li>
<li>The <span class="info">maxConns</span> parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li> <li>The <span class="info">maxConns</span> parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li>
<li>The <span class="info">maxConnTime</span> parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.</li> <li>The <span class="info">maxConnTime</span> parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.</li>
<li>The <span class="info">maxCheckoutSeconds</span> parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.</li> <li>The <span class="info">maxCheckoutSeconds</span> parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.</li>
</ul> </ul>
<p>Please note that <em>all parameters are required</em>.</p> <p>Please note that <em>all parameters are required</em>.</p>
<p class="alert">Please take a minute to incorporate the <a href="../source.jsp?file=conf/server.xml">JDNI DataSource example</a> in your <code>$CATALINE_HOME/conf/server.xml</code>. Once done, please restart Tomcat. The examples will be functional upon restart.</p> <p class="alert">Please take a minute to incorporate the <a href="../source.jsp?file=conf/server.xml">JDNI DataSource example</a> in your <code>$CATALINE_HOME/conf/server.xml</code>. Once done, please restart Tomcat. The examples will be functional upon restart.</p>
<p>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.</p> <p>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.</p>
</div> </div>
</div> </div>
</div> </div>
</td> </td>
</tr> </tr>
</table> </table>
</body> </body>
</html> </html>

View file

@ -1,27 +1,27 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<html> <html>
<head> <head>
<title>SimplePool JNDI/JSTL Example</title> <title>SimplePool JNDI/JSTL Example</title>
</head> </head>
<body> <body>
<%-- Execute the query using our JNDI DataSource --%> <%-- Execute the query using our JNDI DataSource --%>
<sql:query var="rs" dataSource="jdbc/JNDIPoolDS"> <sql:query var="rs" dataSource="jdbc/JNDIPoolDS">
SHOW TABLES SHOW TABLES
</sql:query> </sql:query>
<h3>Tables</h3> <h3>Tables</h3>
<ul> <ul>
<%-- <%--
Loop through the result set and Loop through the result set and
display the current column value display the current column value
--%> --%>
<c:forEach var="row" items="${rs.rowsByIndex}"> <c:forEach var="row" items="${rs.rowsByIndex}">
<li><c:out value="${row[0]}"/></li> <li><c:out value="${row[0]}"/></li>
</c:forEach> </c:forEach>
<ul> <ul>
</body> </body>
</html> </html>

View file

@ -1,45 +1,45 @@
<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %> <%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %>
<html> <html>
<head> <head>
<title>SimplePool JNDI Example</title> <title>SimplePool JNDI Example</title>
</head> </head>
<body> <body>
<% <%
// Get a new initial JNDI context // Get a new initial JNDI context
Context ctx = new InitialContext(); Context ctx = new InitialContext();
// Get a reference to our JNDI DataSource // Get a reference to our JNDI DataSource
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/JNDIPoolDS"); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/JNDIPoolDS");
// Get a connection from the pool // Get a connection from the pool
Connection conn = ds.getConnection(); Connection conn = ds.getConnection();
// Create a new statement // Create a new statement
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
// Execute the query // Execute the query
ResultSet rst = stmt.executeQuery("SHOW TABLES"); ResultSet rst = stmt.executeQuery("SHOW TABLES");
%> %>
<h3>Tables</h3> <h3>Tables</h3>
<ul> <ul>
<% <%
// Loop through the result set and // Loop through the result set and
// display the current column value // display the current column value
while (rst.next()) { while (rst.next()) {
%> %>
<li><%= rst.getString(1) %></li> <li><%= rst.getString(1) %></li>
<% <%
} }
%> %>
<ul> <ul>
<% <%
// Close the result set, statement and connection // Close the result set, statement and connection
rst.close(); rst.close();
stmt.close(); stmt.close();
conn.close(); conn.close();
%> %>
</body> </body>
</html> </html>

View file

@ -1,56 +1,56 @@
/* ========================================================================= * /* ========================================================================= *
* * * *
* The Apache Software License, Version 1.1 * * The Apache Software License, Version 1.1 *
* * * *
* Copyright (c) 1999, 2000 The Apache Software Foundation. * * Copyright (c) 1999, 2000 The Apache Software Foundation. *
* All rights reserved. * * All rights reserved. *
* * * *
* ========================================================================= * * ========================================================================= *
* * * *
* Redistribution and use in source and binary forms, with or without modi- * * Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: * * fication, are permitted provided that the following conditions are met: *
* * * *
* 1. Redistributions of source code must retain the above copyright notice, * * 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. * * this list of conditions and the following disclaimer. *
* * * *
* 2. Redistributions in binary form must reproduce the above copyright * * 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the * * notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. * * documentation and/or other materials provided with the distribution. *
* * * *
* 3. The end-user documentation included with the redistribution, if any, * * 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: * * must include the following acknowlegement: *
* * * *
* "This product includes software developed by the Apache Software * * "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." * * Foundation <http://www.apache.org/>." *
* * * *
* Alternately, this acknowlegement may appear in the software itself, if * * Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. * * and wherever such third-party acknowlegements normally appear. *
* * * *
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived * * Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written * * from this software without prior written permission. For written *
* permission, please contact <apache@apache.org>. * * permission, please contact <apache@apache.org>. *
* * * *
* 5. Products derived from this software may not be called "Apache" nor may * * 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" appear in their names without prior written permission of the *
* Apache Software Foundation. * * Apache Software Foundation. *
* * * *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. * * POSSIBILITY OF SUCH DAMAGE. *
* * * *
* ========================================================================= * * ========================================================================= *
* * * *
* This software consists of voluntary contributions made by many indivi- * * This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information * * duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. * * on the Apache Software Foundation, please see <http://www.apache.org/>. *
* * * *
* ========================================================================= */ * ========================================================================= */

View file

@ -1,38 +1,38 @@
/* /*
* $Source$ * $Source: /home/cvsroot/manywhere/simplepool/simplepool-examples/licenses/SimplePool\040License.txt,v $
* $Revision$ * $Revision: 1.1 $
* $Date$ * $Date: 2004/03/20 13:36:08 $
* *
* Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/)
* All rights reserved. * All rights reserved.
* *
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
* met: * met:
* *
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* *
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* Neither the name of the authors nor the names of its contributors may be * 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 * used to endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */

View file

@ -1,77 +1,77 @@
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
"http://style.tigris.org/tigris_transitional.dtd"> "http://style.tigris.org/tigris_transitional.dtd">
<%@page import="javax.naming.*" %> <%@page import="javax.naming.*" %>
<html> <html>
<head> <head>
<style type="text/css"> <style type="text/css">
/* <![CDATA[ */ /* <![CDATA[ */
@import "../includes/tigris.css"; @import "../includes/tigris.css";
@import "../includes/inst.css"; @import "../includes/inst.css";
/* ]]> */ /* ]]> */
</style> </style>
<title>simplepool: Servlet DataSource Examples</title> <title>simplepool: Servlet DataSource Examples</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Style-Type" content="text/css" />
<script language="javascript" type="text/javascript"> <script language="javascript" type="text/javascript">
<% boolean enabled = (pageContext.findAttribute("ServletPoolDS") != null); %> <% boolean enabled = (pageContext.findAttribute("ServletPoolDS") != null); %>
function RTFM() function RTFM()
{ {
alert("Please read the instructions to enable this example."); alert("Please read the instructions to enable this example.");
} }
</script> </script>
</head> </head>
<body marginwidth="0" marginheight="0" class="composite"> <body marginwidth="0" marginheight="0" class="composite">
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main"> <table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
<tr valign="top"> <tr valign="top">
<td> <td>
<div id="bodycol"> <div id="bodycol">
<div id="apphead"> <div id="apphead">
<h2><small>simplepool</small><br /> <h2><small>simplepool</small><br />
Servlet DataSource Examples</h2> Servlet DataSource Examples</h2>
</div> </div>
<p class="tasknav"><a href="../index.html">Examples Home</a></p> <p class="tasknav"><a href="../index.html">Examples Home</a></p>
<p><strong>Please read the instructions before trying to run the examples.</strong></p> <p><strong>Please read the instructions before trying to run the examples.</strong></p>
<div id="examples" class="app"> <div id="examples" class="app">
<div class="axial"> <div class="axial">
<table border="0" cellspacing="2" cellpadding="3"> <table border="0" cellspacing="2" cellpadding="3">
<tr> <tr>
<th>Summary</th> <th>Summary</th>
<td>A simple database connection pool example using the SimplePool Servlet.</td> <td>A simple database connection pool example using the SimplePool Servlet.</td>
</tr> </tr>
<tr> <tr>
<th>Example 1</th> <th>Example 1</th>
<td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=servlet/scriptlet.jsp">source</a>]</td> <td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=servlet/scriptlet.jsp">source</a>]</td>
</tr> </tr>
<tr> <tr>
<th>Example 2</th> <th>Example 2</th>
<td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=servlet/jstl.jsp">source</a>]</td> <td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=servlet/jstl.jsp">source</a>]</td>
</tr> </tr>
</table> </table>
</div> </div>
<div class="h3" id="instructions"> <div class="h3" id="instructions">
<h3>Instructions</h3> <h3>Instructions</h3>
<p>The SimplePoolServlet is used to create, access and manage the connection pool.</p> <p>The SimplePoolServlet is used to create, access and manage the connection pool.</p>
<p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p> <p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p>
<p>The SimplePoolServlet is configured using a set of required initialization parameters, as show in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code> under the <code>&lt;servlet/&gt;</code> section:</p> <p>The SimplePoolServlet is configured using a set of required initialization parameters, as show in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code> under the <code>&lt;servlet/&gt;</code> section:</p>
<ul> <ul>
<li>The <code class="info">varName</code> initialization parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li> <li>The <code class="info">varName</code> initialization parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li>
<li>The <code class="info">driver</code> initialization parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li> <li>The <code class="info">driver</code> initialization parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li>
<li>The <span class="info">user</span> initialization parameter is used to specify the database username, if any.</li> <li>The <span class="info">user</span> initialization parameter is used to specify the database username, if any.</li>
<li>The <code class="info">password</code> initialization parameter is used to specify the database password, if any.</li> <li>The <code class="info">password</code> initialization parameter is used to specify the database password, if any.</li>
<li>The <code class="info">jdbcUrl</code> initialization parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li> <li>The <code class="info">jdbcUrl</code> initialization parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li>
<li>The <code class="info">minConns</code> initialization parameter is used to specify the minimum number of connections to start the pool with.</li> <li>The <code class="info">minConns</code> initialization parameter is used to specify the minimum number of connections to start the pool with.</li>
<li>The <code class="info">maxConns</code> initialization parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li> <li>The <code class="info">maxConns</code> initialization parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li>
<li>The <code class="info">maxConnTime</code> 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.</li> <li>The <code class="info">maxConnTime</code> 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.</li>
<li>The <code class="info">maxCheckoutSeconds</code> 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.</li> <li>The <code class="info">maxCheckoutSeconds</code> 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.</li>
</ul> </ul>
<p>Please note that <em>all parameters are required</em>.</p> <p>Please note that <em>all parameters are required</em>.</p>
<p class="alert">Please take a minute to uncomment the <code>&lt;servlet/&gt;</code> declaration and configure the Servlet's initialization parameters in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code>. Once done, please restart the webapp and/or Tomcat. The examples will be functional upon restart.</p> <p class="alert">Please take a minute to uncomment the <code>&lt;servlet/&gt;</code> declaration and configure the Servlet's initialization parameters in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code>. Once done, please restart the webapp and/or Tomcat. The examples will be functional upon restart.</p>
<p>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.</p> <p>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.</p>
</div> </div>
</div> </div>
</div> </div>
</td> </td>
</tr> </tr>
</table> </table>
</body> </body>
</html> </html>

View file

@ -1,27 +1,27 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<html> <html>
<head> <head>
<title>SimplePool Servlet/JSTL Example</title> <title>SimplePool Servlet/JSTL Example</title>
</head> </head>
<body> <body>
<%-- Execute the query using our DataSource --%> <%-- Execute the query using our DataSource --%>
<sql:query var="rs" dataSource="${ServletPoolDS}"> <sql:query var="rs" dataSource="${ServletPoolDS}">
SHOW TABLES SHOW TABLES
</sql:query> </sql:query>
<h3>Tables</h3> <h3>Tables</h3>
<ul> <ul>
<%-- <%--
Loop through the result set and Loop through the result set and
display the current column value display the current column value
--%> --%>
<c:forEach var="row" items="${rs.rowsByIndex}"> <c:forEach var="row" items="${rs.rowsByIndex}">
<li><c:out value="${row[0]}"/></li> <li><c:out value="${row[0]}"/></li>
</c:forEach> </c:forEach>
<ul> <ul>
</body> </body>
</html> </html>

View file

@ -1,44 +1,44 @@
<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %> <%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %>
<html> <html>
<head> <head>
<title>SimplePool Servlet Example</title> <title>SimplePool Servlet Example</title>
</head> </head>
<body> <body>
<% <%
// Get a reference to our DataSource // Get a reference to our DataSource
DataSource ds = (DataSource) pageContext.findAttribute("ServletPoolDS"); DataSource ds = (DataSource) pageContext.findAttribute("ServletPoolDS");
// Get a connection from the pool // Get a connection from the pool
Connection conn = ds.getConnection(); Connection conn = ds.getConnection();
// Create a new statement // Create a new statement
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
// Execute the query // Execute the query
ResultSet rst = stmt.executeQuery("SHOW TABLES"); ResultSet rst = stmt.executeQuery("SHOW TABLES");
%> %>
<h3>Tables</h3> <h3>Tables</h3>
<ul> <ul>
<% <%
// Loop through the result set and // Loop through the result set and
// display the current column value // display the current column value
while (rst.next()) { while (rst.next()) {
%> %>
<li><%= rst.getString(1) %></li> <li><%= rst.getString(1) %></li>
<% <%
} }
%> %>
<ul> <ul>
<% <%
// Close the result set, statement and connection // Close the result set, statement and connection
// and display the current column value // and display the current column value
rst.close(); rst.close();
stmt.close(); stmt.close();
conn.close(); conn.close();
%> %>
</body> </body>
</html> </html>

View file

@ -1,25 +1,25 @@
<%@page import="java.io.*"%> <%@page import="java.io.*"%>
<html> <html>
<body> <body>
<pre> <pre>
<% <%
String file = request.getParameter("file"); String file = request.getParameter("file");
if ((file != null) && (file.trim().length() > 0) && (file.indexOf( ".." ) == -1)) { if ((file != null) && (file.trim().length() > 0) && (file.indexOf( ".." ) == -1)) {
InputStream is = pageContext.getServletContext().getResourceAsStream(file); InputStream is = pageContext.getServletContext().getResourceAsStream(file);
if (is != null) { if (is != null) {
InputStreamReader isr = new InputStreamReader(is); InputStreamReader isr = new InputStreamReader(is);
for (int ch = isr.read(); ch != -1; ch = isr.read()) { for (int ch = isr.read(); ch != -1; ch = isr.read()) {
if (ch == '<') { if (ch == '<') {
out.print("&lt;"); out.print("&lt;");
} else if (ch == '\t') { } else if (ch == '\t') {
out.print(" "); out.print(" ");
} else { } else {
out.print((char) ch); out.print((char) ch);
} }
} }
} }
} }
%> %>
</pre> </pre>
</body> </body>
</html> </html>

View file

@ -1,7 +1,7 @@
/* /*
* $Source$ * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePool.java,v $
* $Revision$ * $Revision: 1.5 $
* $Date$ * $Date: 2004/03/17 23:35:36 $
* *
* Copyright (c) 2002, Marc A. Mnich (http://www.javaexchange.com/) * Copyright (c) 2002, Marc A. Mnich (http://www.javaexchange.com/)
* All rights reserved. * All rights reserved.
@ -33,7 +33,7 @@ import java.util.Date;
* @author <a href="http://www.javaexchange.com/">Marc A. Mnich</a> * @author <a href="http://www.javaexchange.com/">Marc A. Mnich</a>
* @author <a href="http://www.russellbeattie.com/">Russell Beattie</a> * @author <a href="http://www.russellbeattie.com/">Russell Beattie</a>
* @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a> * @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a>
* @version $Revision$, $Date$ * @version $Revision: 1.5 $, $Date: 2004/03/17 23:35:36 $
* @since 1.0 * @since 1.0
*/ */
public class SimplePool implements Runnable { public class SimplePool implements Runnable {

View file

@ -1,357 +1,357 @@
/* /*
* $Source$ * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePoolConnection.java,v $
* $Revision$ * $Revision: 1.5 $
* $Date$ * $Date: 2004/03/17 23:35:36 $
* *
* Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/)
* All rights reserved. * All rights reserved.
* *
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
* met: * met:
* *
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* *
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* Neither the name of the authors nor the names of its contributors may be * 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 * used to endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.java.dev.simplepool; package net.java.dev.simplepool;
import java.sql.*; import java.sql.*;
import java.util.Map; import java.util.Map;
/** /**
* Basic implementation of {@link java.sql.Connection}. * Basic implementation of {@link java.sql.Connection}.
* *
* @author <a href="http://www.russellbeattie.com/">Russell Beattie</a> * @author <a href="http://www.russellbeattie.com/">Russell Beattie</a>
* @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a> * @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a>
* @version $Revision$, $Date$ * @version $Revision: 1.5 $, $Date: 2004/03/17 23:35:36 $
* @since 1.0 * @since 1.0
*/ */
public class SimplePoolConnection implements Connection { public class SimplePoolConnection implements Connection {
private Connection conn; private Connection conn;
private SimplePool pool; private SimplePool pool;
/** /**
* Creates a new SimplePoolConnection object. * Creates a new SimplePoolConnection object.
* *
* @param pool The connection pool. * @param pool The connection pool.
*/ */
public SimplePoolConnection(SimplePool pool) { public SimplePoolConnection(SimplePool pool) {
this.pool = pool; this.pool = pool;
conn = pool.getConnection(); conn = pool.getConnection();
} }
/** /**
* See {@link java.sql.Connection#setAutoCommit(boolean)}. * See {@link java.sql.Connection#setAutoCommit(boolean)}.
*/ */
public void setAutoCommit(boolean autoCommit) public void setAutoCommit(boolean autoCommit)
throws SQLException { throws SQLException {
conn.setAutoCommit(autoCommit); conn.setAutoCommit(autoCommit);
} }
/** /**
* See {@link java.sql.Connection#getAutoCommit}. * See {@link java.sql.Connection#getAutoCommit}.
*/ */
public boolean getAutoCommit() public boolean getAutoCommit()
throws SQLException { throws SQLException {
return conn.getAutoCommit(); return conn.getAutoCommit();
} }
/** /**
* See {@link java.sql.Connection#setCatalog(String)}. * See {@link java.sql.Connection#setCatalog(String)}.
*/ */
public void setCatalog(String catalog) public void setCatalog(String catalog)
throws SQLException { throws SQLException {
conn.setCatalog(catalog); conn.setCatalog(catalog);
} }
/** /**
* See {@link java.sql.Connection#getCatalog()}. * See {@link java.sql.Connection#getCatalog()}.
*/ */
public String getCatalog() public String getCatalog()
throws SQLException { throws SQLException {
return conn.getCatalog(); return conn.getCatalog();
} }
/** /**
* See {@link java.sql.Connection#isClosed}. * See {@link java.sql.Connection#isClosed}.
*/ */
public boolean isClosed() public boolean isClosed()
throws SQLException { throws SQLException {
return conn.isClosed(); return conn.isClosed();
} }
/** /**
* See {@link java.sql.Connection#setHoldability(int)}. * See {@link java.sql.Connection#setHoldability(int)}.
*/ */
public void setHoldability(int holdability) public void setHoldability(int holdability)
throws SQLException { throws SQLException {
conn.setHoldability(holdability); conn.setHoldability(holdability);
} }
/** /**
* See {@link java.sql.Connection#getHoldability}. * See {@link java.sql.Connection#getHoldability}.
*/ */
public int getHoldability() public int getHoldability()
throws SQLException { throws SQLException {
return conn.getHoldability(); return conn.getHoldability();
} }
/** /**
* See {@link java.sql.Connection#getMetaData}. * See {@link java.sql.Connection#getMetaData}.
*/ */
public DatabaseMetaData getMetaData() public DatabaseMetaData getMetaData()
throws SQLException { throws SQLException {
return conn.getMetaData(); return conn.getMetaData();
} }
/** /**
* See {@link java.sql.Connection#setReadOnly(boolean)}. * See {@link java.sql.Connection#setReadOnly(boolean)}.
*/ */
public void setReadOnly(boolean readOnly) public void setReadOnly(boolean readOnly)
throws SQLException { throws SQLException {
conn.setReadOnly(readOnly); conn.setReadOnly(readOnly);
} }
/** /**
* See {@link java.sql.Connection#isReadOnly}. * See {@link java.sql.Connection#isReadOnly}.
*/ */
public boolean isReadOnly() public boolean isReadOnly()
throws SQLException { throws SQLException {
return conn.isReadOnly(); return conn.isReadOnly();
} }
/** /**
* See {@link java.sql.Connection#setSavepoint}. * See {@link java.sql.Connection#setSavepoint}.
*/ */
public Savepoint setSavepoint() public Savepoint setSavepoint()
throws SQLException { throws SQLException {
return conn.setSavepoint(); return conn.setSavepoint();
} }
/** /**
* See {@link java.sql.Connection#setSavepoint(String)}. * See {@link java.sql.Connection#setSavepoint(String)}.
*/ */
public Savepoint setSavepoint(String savepoint) public Savepoint setSavepoint(String savepoint)
throws SQLException { throws SQLException {
return conn.setSavepoint(savepoint); return conn.setSavepoint(savepoint);
} }
/** /**
* See {@link java.sql.Connection#setTransactionIsolation(int)}. * See {@link java.sql.Connection#setTransactionIsolation(int)}.
*/ */
public void setTransactionIsolation(int level) public void setTransactionIsolation(int level)
throws SQLException { throws SQLException {
conn.setTransactionIsolation(level); conn.setTransactionIsolation(level);
} }
/** /**
* See {@link java.sql.Connection#getTransactionIsolation}. * See {@link java.sql.Connection#getTransactionIsolation}.
*/ */
public int getTransactionIsolation() public int getTransactionIsolation()
throws SQLException { throws SQLException {
return conn.getTransactionIsolation(); return conn.getTransactionIsolation();
} }
/** /**
* See {@link java.sql.Connection#setTypeMap(Map)}. * See {@link java.sql.Connection#setTypeMap(Map)}.
*/ */
public void setTypeMap(Map map) public void setTypeMap(Map map)
throws SQLException { throws SQLException {
conn.setTypeMap(map); conn.setTypeMap(map);
} }
/** /**
* See {@link java.sql.Connection#getTypeMap}. * See {@link java.sql.Connection#getTypeMap}.
*/ */
public Map getTypeMap() public Map getTypeMap()
throws SQLException { throws SQLException {
return conn.getTypeMap(); return conn.getTypeMap();
} }
/** /**
* See {@link java.sql.Connection#getWarnings}. * See {@link java.sql.Connection#getWarnings}.
*/ */
public SQLWarning getWarnings() public SQLWarning getWarnings()
throws SQLException { throws SQLException {
return conn.getWarnings(); return conn.getWarnings();
} }
/** /**
* See {@link java.sql.Connection#clearWarnings}. * See {@link java.sql.Connection#clearWarnings}.
*/ */
public void clearWarnings() public void clearWarnings()
throws SQLException { throws SQLException {
conn.clearWarnings(); conn.clearWarnings();
} }
/** /**
* See {@link java.sql.Connection#close}. * See {@link java.sql.Connection#close}.
*/ */
public void close() public void close()
throws SQLException { throws SQLException {
pool.freeConnection(conn); pool.freeConnection(conn);
} }
/** /**
* See {@link java.sql.Connection#commit}. * See {@link java.sql.Connection#commit}.
*/ */
public void commit() public void commit()
throws SQLException { throws SQLException {
conn.commit(); conn.commit();
} }
/** /**
* See {@link java.sql.Connection#createStatement}. * See {@link java.sql.Connection#createStatement}.
*/ */
public Statement createStatement() public Statement createStatement()
throws SQLException { throws SQLException {
return conn.createStatement(); return conn.createStatement();
} }
/** /**
* See {@link java.sql.Connection#createStatement(int, int)}. * See {@link java.sql.Connection#createStatement(int, int)}.
*/ */
public Statement createStatement(int resultSetType, int resultSetConcurrency) public Statement createStatement(int resultSetType, int resultSetConcurrency)
throws SQLException { throws SQLException {
return conn.createStatement(resultSetType, resultSetConcurrency); return conn.createStatement(resultSetType, resultSetConcurrency);
} }
/** /**
* See {@link java.sql.Connection#createStatement(int, int, int)}. * See {@link java.sql.Connection#createStatement(int, int, int)}.
*/ */
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException { throws SQLException {
return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
} }
/** /**
* See {@link java.sql.Connection#nativeSQL(String)}. * See {@link java.sql.Connection#nativeSQL(String)}.
*/ */
public String nativeSQL(String sql) public String nativeSQL(String sql)
throws SQLException { throws SQLException {
return conn.nativeSQL(sql); return conn.nativeSQL(sql);
} }
/** /**
* See {@link java.sql.Connection#prepareCall(String)}. * See {@link java.sql.Connection#prepareCall(String)}.
*/ */
public CallableStatement prepareCall(String sql) public CallableStatement prepareCall(String sql)
throws SQLException { throws SQLException {
return conn.prepareCall(sql); return conn.prepareCall(sql);
} }
/** /**
* See {@link java.sql.Connection#prepareCall(String, int, int)}. * See {@link java.sql.Connection#prepareCall(String, int, int)}.
*/ */
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException { throws SQLException {
return conn.prepareCall(sql, resultSetType, resultSetConcurrency); return conn.prepareCall(sql, resultSetType, resultSetConcurrency);
} }
/** /**
* See {@link java.sql.Connection#prepareCall(String, int, int, int)}. * See {@link java.sql.Connection#prepareCall(String, int, int, int)}.
*/ */
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) int resultSetHoldability)
throws SQLException { throws SQLException {
return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
} }
/** /**
* See {@link java.sql.Connection#prepareStatement(String)}. * See {@link java.sql.Connection#prepareStatement(String)}.
*/ */
public PreparedStatement prepareStatement(String sql) public PreparedStatement prepareStatement(String sql)
throws SQLException { throws SQLException {
return conn.prepareStatement(sql); return conn.prepareStatement(sql);
} }
/** /**
* See {@link java.sql.Connection#prepareStatement(String)}. * See {@link java.sql.Connection#prepareStatement(String)}.
*/ */
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException { throws SQLException {
return conn.prepareStatement(sql); return conn.prepareStatement(sql);
} }
/** /**
* See {@link java.sql.Connection#prepareStatement(String, int, int)}. * See {@link java.sql.Connection#prepareStatement(String, int, int)}.
*/ */
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException { throws SQLException {
return conn.prepareStatement(sql, resultSetType, resultSetConcurrency); return conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
} }
/** /**
* See {@link java.sql.Connection#prepareStatement(String, int, int, int)}. * See {@link java.sql.Connection#prepareStatement(String, int, int, int)}.
*/ */
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) int resultSetHoldability)
throws SQLException { throws SQLException {
return conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); return conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
} }
/** /**
* See {@link java.sql.Connection#prepareStatement(String, int[])}. * See {@link java.sql.Connection#prepareStatement(String, int[])}.
*/ */
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
throws SQLException { throws SQLException {
return conn.prepareStatement(sql, columnIndexes); return conn.prepareStatement(sql, columnIndexes);
} }
/** /**
* See {@link java.sql.Connection#prepareStatement(String, String[])}. * See {@link java.sql.Connection#prepareStatement(String, String[])}.
*/ */
public PreparedStatement prepareStatement(String sql, String[] columnNames) public PreparedStatement prepareStatement(String sql, String[] columnNames)
throws SQLException { throws SQLException {
return conn.prepareStatement(sql, columnNames); return conn.prepareStatement(sql, columnNames);
} }
/** /**
* See {@link java.sql.Connection#releaseSavepoint(Savepoint)}. * See {@link java.sql.Connection#releaseSavepoint(Savepoint)}.
*/ */
public void releaseSavepoint(Savepoint savepoint) public void releaseSavepoint(Savepoint savepoint)
throws SQLException { throws SQLException {
conn.releaseSavepoint(savepoint); conn.releaseSavepoint(savepoint);
} }
/** /**
* See {@link java.sql.Connection#rollback}. * See {@link java.sql.Connection#rollback}.
*/ */
public void rollback() public void rollback()
throws SQLException { throws SQLException {
conn.rollback(); conn.rollback();
} }
/** /**
* See {@link java.sql.Connection#rollback(Savepoint)}. * See {@link java.sql.Connection#rollback(Savepoint)}.
*/ */
public void rollback(Savepoint savepoint) public void rollback(Savepoint savepoint)
throws SQLException { throws SQLException {
conn.rollback(savepoint); conn.rollback(savepoint);
} }
} }

View file

@ -1,319 +1,319 @@
/* /*
* $Source$ * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePoolDataSource.java,v $
* $Revision$ * $Revision: 1.4 $
* $Date$ * $Date: 2004/03/17 23:19:02 $
* *
* Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/)
* All rights reserved. * All rights reserved.
* *
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
* met: * met:
* *
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* *
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* Neither the name of the authors nor the names of its contributors may be * 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 * used to endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.java.dev.simplepool; package net.java.dev.simplepool;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* Basic implementation of {@link javax.sql.DataSource}. * Basic implementation of {@link javax.sql.DataSource}.
* *
* @author <a href="http://www.russellbeattie.com/">Russell Beattie</a> * @author <a href="http://www.russellbeattie.com/">Russell Beattie</a>
* @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a> * @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a>
* @version $Revision$, $Date$ * @version $Revision: 1.4 $, $Date: 2004/03/17 23:19:02 $
* @since 1.0 * @since 1.0
*/ */
public class SimplePoolDataSource implements DataSource { public class SimplePoolDataSource implements DataSource {
private PrintWriter logWriter = new PrintWriter(System.out); private PrintWriter logWriter = new PrintWriter(System.out);
private SimplePool pool = null; private SimplePool pool = null;
private String driver = ""; private String driver = "";
private String jdbcUrl = ""; private String jdbcUrl = "";
private String user = ""; private String user = "";
private String password = ""; private String password = "";
private String minConns = ""; private String minConns = "";
private String maxConns = ""; private String maxConns = "";
private String maxConnTime = ""; private String maxConnTime = "";
private String maxCheckoutSeconds = ""; private String maxCheckoutSeconds = "";
/** /**
* Initializes the connection pool. * Initializes the connection pool.
* *
* @throws Exception if the pool could not be intialized. * @throws Exception if the pool could not be intialized.
*/ */
protected void init() throws Exception { protected void init() throws Exception {
pool = new SimplePool(driver, jdbcUrl, user, password, pool = new SimplePool(driver, jdbcUrl, user, password,
Integer.parseInt(minConns), Integer.parseInt(maxConns), Integer.parseInt(minConns), Integer.parseInt(maxConns),
Double.parseDouble(maxConnTime), Integer.parseInt(maxCheckoutSeconds)); Double.parseDouble(maxConnTime), Integer.parseInt(maxCheckoutSeconds));
} }
/** /**
* See {@link javax.sql.DataSource#getConnection()}. * See {@link javax.sql.DataSource#getConnection()}.
*/ */
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
if (pool == null) { if (pool == null) {
try { try {
init(); init();
} catch (Exception e) { } catch (Exception e) {
throw new SQLException("Error initializing Connection Broker."); throw new SQLException("Error initializing Connection Broker.");
} }
} }
return new SimplePoolConnection(pool); return new SimplePoolConnection(pool);
} }
/** /**
* See {@link javax.sql.DataSource#getConnection(String, String)}. * See {@link javax.sql.DataSource#getConnection(String, String)}.
*/ */
public Connection getConnection(String username, String password) public Connection getConnection(String username, String password)
throws SQLException { throws SQLException {
throw new SQLException("Not supported in this DataSource."); throw new SQLException("Not supported in this DataSource.");
} }
/** /**
* See {@link javax.sql.DataSource#setLogWriter(PrintWriter)}. * See {@link javax.sql.DataSource#setLogWriter(PrintWriter)}.
*/ */
public void setLogWriter(PrintWriter out) throws SQLException { public void setLogWriter(PrintWriter out) throws SQLException {
logWriter = out; logWriter = out;
} }
/** /**
* See {@link javax.sql.DataSource#getLogWriter}. * See {@link javax.sql.DataSource#getLogWriter}.
*/ */
public PrintWriter getLogWriter() { public PrintWriter getLogWriter() {
return logWriter; return logWriter;
} }
/** /**
* See {@link javax.sql.DataSource#setLoginTimeout(int)}. * See {@link javax.sql.DataSource#setLoginTimeout(int)}.
*/ */
public void setLoginTimeout(int seconds) throws SQLException { public void setLoginTimeout(int seconds) throws SQLException {
} }
/** /**
* See {@link javax.sql.DataSource#getLoginTimeout}. * See {@link javax.sql.DataSource#getLoginTimeout}.
*/ */
public int getLoginTimeout() { public int getLoginTimeout() {
return 0; return 0;
} }
/** /**
* Closes the connection pool. * Closes the connection pool.
*/ */
public void close() { public void close() {
pool.destroy(); pool.destroy();
pool = null; pool = null;
} }
/** /**
* Sets the JDBC driver. * Sets the JDBC driver.
* *
* @param driver The JDBC driver. e.g. 'com.mysql.jdbc.Driver' * @param driver The JDBC driver. e.g. 'com.mysql.jdbc.Driver'
* *
* @see #getDriver() * @see #getDriver()
*/ */
public void setDriver(String driver) { public void setDriver(String driver) {
this.driver = driver; this.driver = driver;
} }
/** /**
* Gets the JDBC driver. * Gets the JDBC driver.
* *
* @return The JDBC driver string. * @return The JDBC driver string.
* *
* @see #setDriver(String) * @see #setDriver(String)
*/ */
public String getDriver() { public String getDriver() {
return driver; return driver;
} }
/** /**
* Sets the JDBC connect string. * Sets the JDBC connect string.
* *
* @param jdbcUrl The JDBC connection URL string. e.g. 'jdbc:mysql://localhost:3306/dbname' * @param jdbcUrl The JDBC connection URL string. e.g. 'jdbc:mysql://localhost:3306/dbname'
* *
* @see #getJdbcUrl() * @see #getJdbcUrl()
*/ */
public void setJdbcUrl(String jdbcUrl) { public void setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl; this.jdbcUrl = jdbcUrl;
} }
/** /**
* Gets the JDBC connect string. * Gets the JDBC connect string.
* *
* @return The JDBC connection URL string. * @return The JDBC connection URL string.
* *
* @see #setJdbcUrl(String) * @see #setJdbcUrl(String)
*/ */
public String getJdbcUrl() { public String getJdbcUrl() {
return jdbcUrl; return jdbcUrl;
} }
/** /**
* Sets the database login name. * Sets the database login name.
* *
* @param user The database login name. e.g. 'Scott' * @param user The database login name. e.g. 'Scott'
* *
* @see #getUser() * @see #getUser()
*/ */
public void setUser(String user) { public void setUser(String user) {
this.user = user; this.user = user;
} }
/** /**
* Gets the database login name. * Gets the database login name.
* *
* @return The login name string. * @return The login name string.
* *
* @see #setUser(String) * @see #setUser(String)
*/ */
public String getUser() { public String getUser() {
return user; return user;
} }
/** /**
* Sets the database password. * Sets the database password.
* *
* @param password The database password. e.g. 'Tiger' * @param password The database password. e.g. 'Tiger'
* *
* @see #getPassword() * @see #getPassword()
*/ */
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
/** /**
* Gets the database password. * Gets the database password.
* *
* @return The password string. * @return The password string.
* *
* @see #setPassword(String) * @see #setPassword(String)
*/ */
public String getPassword() { public String getPassword() {
return password; return password;
} }
/** /**
* Sets the minimum number of connections to start with. * Sets the minimum number of connections to start with.
* *
* @param minConns The minimum number of connections. * @param minConns The minimum number of connections.
* *
* @see #getMinConns() * @see #getMinConns()
*/ */
public void setMinConns(String minConns) { public void setMinConns(String minConns) {
this.minConns = minConns; this.minConns = minConns;
} }
/** /**
* Gets the minimum number of connections to start with. * Gets the minimum number of connections to start with.
* *
* @return The minimum number of connections string. * @return The minimum number of connections string.
* *
* @see #setMinConns(String) * @see #setMinConns(String)
*/ */
public String getMinConns() { public String getMinConns() {
return minConns; return minConns;
} }
/** /**
* Sets the maximum number of connections in dynamic pool. * Sets the maximum number of connections in dynamic pool.
* *
* @param maxConns The maximum number of connections. * @param maxConns The maximum number of connections.
* *
* @see #getMaxConns() * @see #getMaxConns()
*/ */
public void setMaxConns(String maxConns) { public void setMaxConns(String maxConns) {
this.maxConns = maxConns; this.maxConns = maxConns;
} }
/** /**
* Gets the maximum number of connections in dynamic pool. * Gets the maximum number of connections in dynamic pool.
* *
* @return The maximum number of connection string. * @return The maximum number of connection string.
* *
* @see #setMaxConns(String) * @see #setMaxConns(String)
*/ */
public String getMaxConns() { public String getMaxConns() {
return maxConns; return maxConns;
} }
/** /**
* Sets the time in days between connection resets. * Sets the time in days between connection resets.
* *
* @param maxConnTime The maximum connection time. * @param maxConnTime The maximum connection time.
* *
* @see #getMaxConnTime() * @see #getMaxConnTime()
*/ */
public void setMaxConnTime(String maxConnTime) { public void setMaxConnTime(String maxConnTime) {
this.maxConnTime = maxConnTime; this.maxConnTime = maxConnTime;
} }
/** /**
* Gets the time in days between connection resets. * Gets the time in days between connection resets.
* *
* @return The maximum connection time string. * @return The maximum connection time string.
* *
* @see #setMaxConnTime(String) * @see #setMaxConnTime(String)
*/ */
public String getMaxConnTime() { public String getMaxConnTime() {
return maxConnTime; return maxConnTime;
} }
/** /**
* Sets the max time a connection can be checked out before being recycled. * 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. * @param maxCheckoutSeconds The maximum number of seconds to wait before recycling a connection.
* *
* @see #getMaxCheckoutSeconds() * @see #getMaxCheckoutSeconds()
*/ */
public void setMaxCheckoutSeconds(String maxCheckoutSeconds) { public void setMaxCheckoutSeconds(String maxCheckoutSeconds) {
this.maxCheckoutSeconds = maxCheckoutSeconds; this.maxCheckoutSeconds = maxCheckoutSeconds;
} }
/** /**
* Gets the max time a connection can be checked out before being recycled. * Gets the max time a connection can be checked out before being recycled.
* *
* @return The maximum checkout time string. * @return The maximum checkout time string.
* *
* @see #setMaxCheckoutSeconds(String) * @see #setMaxCheckoutSeconds(String)
*/ */
public String getMaxCheckoutSeconds() { public String getMaxCheckoutSeconds() {
return maxCheckoutSeconds; return maxCheckoutSeconds;
} }
} }

View file

@ -1,141 +1,141 @@
/* /*
* $Source$ * $Source: /home/cvsroot/manywhere/simplepool/src/net/java/dev/simplepool/SimplePoolDataSourceFactory.java,v $
* $Revision$ * $Revision: 1.5 $
* $Date$ * $Date: 2004/03/17 23:19:02 $
* *
* Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/) * Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/)
* All rights reserved. * All rights reserved.
* *
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/) * Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
* met: * met:
* *
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* *
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* Neither the name of the authors nor the names of its contributors may be * 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 * used to endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.java.dev.simplepool; package net.java.dev.simplepool;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.Name; import javax.naming.Name;
import javax.naming.Reference; import javax.naming.Reference;
import javax.naming.spi.ObjectFactory; import javax.naming.spi.ObjectFactory;
import java.util.Hashtable; import java.util.Hashtable;
/** /**
* JNDI object factory that creates an instance of {@link SimplePoolDataSource}. * JNDI object factory that creates an instance of {@link SimplePoolDataSource}.
* *
* @author <a href="http://www.russellbeattie.com/">Russell Beattie</a> * @author <a href="http://www.russellbeattie.com/">Russell Beattie</a>
* @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a> * @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a>
* @version $Revision$, $Date$ * @version $Revision: 1.5 $, $Date: 2004/03/17 23:19:02 $
* @since 1.0 * @since 1.0
*/ */
public class SimplePoolDataSourceFactory implements ObjectFactory { public class SimplePoolDataSourceFactory implements ObjectFactory {
/** /**
* Creates a {@link SimplePoolDataSource} instance. * Creates a {@link SimplePoolDataSource} instance.
* *
* @param obj The object containing location or reference information that is used in creating the * @param obj The object containing location or reference information that is used in creating the
* <code>DataSource</code>. * <code>DataSource</code>.
* @param name The name of this object relative to <code>ctx</code>, or null if no name is specified. * @param name The name of this object relative to <code>ctx</code>, or null if no name is specified.
* @param ctx The context relative to which the <code>name</code> parameter is specified, or null if * @param ctx The context relative to which the <code>name</code> parameter is specified, or null if
* <code>name</code> is relative to the default initial context. * <code>name</code> is relative to the default initial context.
* @param env The possibly null environment that is used in creating the <code>DataSource</code>. * @param env The possibly null environment that is used in creating the <code>DataSource</code>.
* *
* @return The <code>DataSource</code>; null if it cannot be created. * @return The <code>DataSource</code>; null if it cannot be created.
* *
* @throws Exception if the factory encountered an exception while attempting to create the <code>DataSource</code>, * @throws Exception if the factory encountered an exception while attempting to create the <code>DataSource</code>,
* and no other object factories are to be tried. * and no other object factories are to be tried.
*/ */
public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env)
throws Exception { throws Exception {
Reference ref = (Reference) obj; Reference ref = (Reference) obj;
SimplePoolDataSource dataSource = new SimplePoolDataSource(); SimplePoolDataSource dataSource = new SimplePoolDataSource();
/* /*
driver: JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'<br> driver: JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'<br>
jdbcUrl: JDBC connect string. e.g. 'jdbc:oracle:thin:@203.92.21.109:1526:orcl'<br> jdbcUrl: JDBC connect string. e.g. 'jdbc:oracle:thin:@203.92.21.109:1526:orcl'<br>
user: Database login name. e.g. 'Scott'<br> user: Database login name. e.g. 'Scott'<br>
password: Database password. e.g. 'Tiger'<br> password: Database password. e.g. 'Tiger'<br>
minConns: Minimum number of connections to start with.<br> minConns: Minimum number of connections to start with.<br>
maxConns: Maximum number of connections in dynamic pool.<br> maxConns: Maximum number of connections in dynamic pool.<br>
maxConnTime: Time in days between connection resets. (Reset does a basic cleanup)<br> maxConnTime: Time in days between connection resets. (Reset does a basic cleanup)<br>
maxCheckoutSeconds: Max time a connection can be checked out before being recycled. Zero value turns option maxCheckoutSeconds: Max time a connection can be checked out before being recycled. Zero value turns option
off, default is 60 seconds. off, default is 60 seconds.
*/ */
String driver = (String) ref.get("driver").getContent(); String driver = (String) ref.get("driver").getContent();
if (driver != null) { if (driver != null) {
dataSource.setDriver(driver); dataSource.setDriver(driver);
} }
String user = (String) ref.get("user").getContent(); String user = (String) ref.get("user").getContent();
if (user != null) { if (user != null) {
dataSource.setUser(user); dataSource.setUser(user);
} }
String password = (String) ref.get("password").getContent(); String password = (String) ref.get("password").getContent();
if (password != null) { if (password != null) {
dataSource.setPassword(password); dataSource.setPassword(password);
} }
String jdbcUrl = (String) ref.get("jdbcUrl").getContent(); String jdbcUrl = (String) ref.get("jdbcUrl").getContent();
if (jdbcUrl != null) { if (jdbcUrl != null) {
dataSource.setJdbcUrl(jdbcUrl); dataSource.setJdbcUrl(jdbcUrl);
} }
String minConns = (String) ref.get("minConns").getContent(); String minConns = (String) ref.get("minConns").getContent();
if (minConns != null) { if (minConns != null) {
dataSource.setMinConns(minConns); dataSource.setMinConns(minConns);
} }
String maxConns = (String) ref.get("maxConns").getContent(); String maxConns = (String) ref.get("maxConns").getContent();
if (maxConns != null) { if (maxConns != null) {
dataSource.setMaxConns(maxConns); dataSource.setMaxConns(maxConns);
} }
String maxConnTime = (String) ref.get("maxConnTime").getContent(); String maxConnTime = (String) ref.get("maxConnTime").getContent();
if (maxConnTime != null) { if (maxConnTime != null) {
dataSource.setMaxConnTime(maxConnTime); dataSource.setMaxConnTime(maxConnTime);
} }
String maxCheckoutSeconds = (String) ref.get("maxCheckoutSeconds").getContent(); String maxCheckoutSeconds = (String) ref.get("maxCheckoutSeconds").getContent();
if (maxCheckoutSeconds != null) { if (maxCheckoutSeconds != null) {
dataSource.setMaxCheckoutSeconds(maxCheckoutSeconds); dataSource.setMaxCheckoutSeconds(maxCheckoutSeconds);
} }
dataSource.init(); dataSource.init();
return dataSource; return dataSource;
} }
} }

View file

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

View file

@ -1,13 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html> <html>
<head> <head>
<title>SimplePool API</title> <title>SimplePool API</title>
</head> </head>
<body> <body>
This package contains a simple database connection pool implementation for web applications, specifically those using JSTL. This package contains a simple database connection pool implementation for web applications, specifically those using JSTL.
<p/> <p/>
The connection pool can be created, accessed and managed via JNDI or through the {@link net.java.dev.simplepool.SimplePoolServlet}. The connection pool can be created, accessed and managed via JNDI or through the {@link net.java.dev.simplepool.SimplePoolServlet}.
@since 1.0 @since 1.0
</body> </body>
</html> </html>