winstone.jndi.resourceFactories
Class WinstoneDataSource

java.lang.Object
  extended by winstone.jndi.resourceFactories.WinstoneDataSource
All Implemented Interfaces:
java.lang.Runnable, java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

public class WinstoneDataSource
extends java.lang.Object
implements javax.sql.DataSource, java.lang.Runnable

Implements a JDBC 2.0 pooling datasource. This is meant to act as a wrapper around a JDBC 1.0 driver, just providing the pool management functions. Supports keep alives, and check-connection-before-get options, as well as normal reclaimable pool management options like maxIdle, maxConnections and startConnections. Additionally it supports poll-retry on full, which means the getConnection call will block and retry after a certain period when the pool is maxed out (good for high load conditions). This class was originally drawn from the generator-runtime servlet framework and modified to make it more JDBC-API only compliant.

Version:
$Id: WinstoneDataSource.java,v 1.8 2006/11/07 01:30:39 rickknowles Exp $
Author:
Rick Knowles

Field Summary
static WinstoneResourceBundle DS_RESOURCES
           
 
Constructor Summary
WinstoneDataSource(java.lang.String name, java.util.Map args, java.lang.ClassLoader loader)
          Main constructor.
 
Method Summary
 void destroy()
          Close this pool - probably because we will want to re-init the pool
protected  void executeKeepAlive(java.sql.Connection connection)
           
protected  void executeKeepAliveOnUnused()
          Executes keep alive for each of the connections in the supplied pool
 java.sql.Connection getConnection()
           
protected  java.sql.Connection getConnection(int retriesAllowed)
          Get a read-write connection - preferably from the pool, but fresh if needed
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Gets a connection with a specific username/password.
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 java.util.logging.Logger getParentLogger()
           
 boolean isWrapperFor(java.lang.Class<?> iface)
           
protected  void killPooledConnections(java.util.List pool, int maxIdleCount)
          Iterates through a list and kills off unused connections until we reach the minimum idle count for that pool.
protected  java.sql.Connection makeNewRealConnection(java.util.List pool)
          This makes a new rw connection.
 void run()
          Clean up and keep-alive thread.
 void setLoginTimeout(int timeout)
           
 void setLogWriter(java.io.PrintWriter writer)
           
 java.lang.String toString()
           
<T> T
unwrap(java.lang.Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DS_RESOURCES

public static final WinstoneResourceBundle DS_RESOURCES
Constructor Detail

WinstoneDataSource

public WinstoneDataSource(java.lang.String name,
                          java.util.Map args,
                          java.lang.ClassLoader loader)
Main constructor. Basically just calls the init method

Method Detail

destroy

public void destroy()
Close this pool - probably because we will want to re-init the pool


getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Gets a connection with a specific username/password. These are not pooled.

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

protected java.sql.Connection getConnection(int retriesAllowed)
                                     throws java.sql.SQLException
Get a read-write connection - preferably from the pool, but fresh if needed

Throws:
java.sql.SQLException

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource

getLogWriter

public java.io.PrintWriter getLogWriter()
Specified by:
getLogWriter in interface javax.sql.CommonDataSource

setLoginTimeout

public void setLoginTimeout(int timeout)
Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource

setLogWriter

public void setLogWriter(java.io.PrintWriter writer)
Specified by:
setLogWriter in interface javax.sql.CommonDataSource

run

public void run()
Clean up and keep-alive thread. Note - this needs a lot more attention to the semaphore use during keepAlive etc

Specified by:
run in interface java.lang.Runnable

executeKeepAliveOnUnused

protected void executeKeepAliveOnUnused()
Executes keep alive for each of the connections in the supplied pool


executeKeepAlive

protected void executeKeepAlive(java.sql.Connection connection)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

makeNewRealConnection

protected java.sql.Connection makeNewRealConnection(java.util.List pool)
                                             throws java.sql.SQLException
This makes a new rw connection. It assumes that the synchronization has taken place in the calling code, so is unsafe for use outside this class.

Throws:
java.sql.SQLException

killPooledConnections

protected void killPooledConnections(java.util.List pool,
                                     int maxIdleCount)
Iterates through a list and kills off unused connections until we reach the minimum idle count for that pool.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

getParentLogger

public java.util.logging.Logger getParentLogger()
                                         throws java.sql.SQLFeatureNotSupportedException
Throws:
java.sql.SQLFeatureNotSupportedException


Copyright © 2013. All Rights Reserved.