com.cometway.jdbc
Class JDBCConnectionPool

java.lang.Object
  extended by com.cometway.jdbc.JDBCConnectionPool

public class JDBCConnectionPool
extends java.lang.Object

The JDBCConnectionPool manages pooled JDBCConnnections for the JDBCConnectionDriver.


Field Summary
protected  ReporterInterface reporter
           
protected static long uniqueIndex
           
 
Constructor Summary
JDBCConnectionPool(java.lang.String jdbcURL, java.lang.String username, java.lang.String password, ReporterInterface reporter)
          Creates a JDBCConnectionPool using the given jdbcURL, username, password, and reporter.
JDBCConnectionPool(java.lang.String jdbcURL, java.lang.String username, java.lang.String password, ReporterInterface reporter, boolean connectionTesting, int poolSize)
          Creates a JDBCConnectionPool using the given jdbcURL, username, password, reporter, validation, and pool size.
JDBCConnectionPool(java.lang.String jdbcURL, java.lang.String username, java.lang.String password, ReporterInterface reporter, int poolSize)
          Creates a JDBCConnectionPool using the given jdbcURL, username, password, reporter and pool size.
 
Method Summary
 void closeConnections()
          Removes each connection from the connection pool and stops the WatchDog thread.
 void debug(java.lang.String message)
          Prints a debug message tagged with this JDBCConnectionPool's identity to the output stream.
 void error(java.lang.String message)
          Prints an error message tagged with this JDBCConnectionPool's identity to the error stream.
 void error(java.lang.String message, java.lang.Exception e)
          Prints an error message tagged with this JDBCConnectionPool's identity followed by a stack trace of the passed Exception to the error stream.
 JDBCConnection getConnection()
          Attempts to lease a connection from the pool.
 void println(java.lang.String message)
          Prints a message tagged with this JDBCConnectionPool's identity to the output stream.
 void removeConnection(JDBCConnection c)
          Removes the specified connection from the connection pool.
 void returnConnection(JDBCConnection conn)
          Marks the specified connection as no longer in use so that it can be returned by subsequent calls to getConnection().
 void setReporter(ReporterInterface reporter)
          Sets the reporter for this JDBCConnectionPool.
 int size()
          Returns the Pool's current size
 java.lang.String toString()
          Returns this connection as a String.
 void warning(java.lang.String message)
          Prints a warning message tagged with this JDBCConnectionPool's identity to the error stream.
 void warning(java.lang.String message, java.lang.Exception e)
          Prints an warning message tagged with this JDBCConnectionPool's identity followed by a stack trace of the passed Exception to error stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uniqueIndex

protected static long uniqueIndex

reporter

protected ReporterInterface reporter
Constructor Detail

JDBCConnectionPool

public JDBCConnectionPool(java.lang.String jdbcURL,
                          java.lang.String username,
                          java.lang.String password,
                          ReporterInterface reporter)
                   throws java.sql.SQLException,
                          java.lang.InterruptedException
Creates a JDBCConnectionPool using the given jdbcURL, username, password, and reporter. The pool's size is set to the default size and no validation is used to make sure the JDBCConnections are valid.

Throws:
java.sql.SQLException
java.lang.InterruptedException

JDBCConnectionPool

public JDBCConnectionPool(java.lang.String jdbcURL,
                          java.lang.String username,
                          java.lang.String password,
                          ReporterInterface reporter,
                          int poolSize)
                   throws java.sql.SQLException,
                          java.lang.InterruptedException
Creates a JDBCConnectionPool using the given jdbcURL, username, password, reporter and pool size. No validation is used to make sure the JDBCConnections are valid.

Throws:
java.sql.SQLException
java.lang.InterruptedException

JDBCConnectionPool

public JDBCConnectionPool(java.lang.String jdbcURL,
                          java.lang.String username,
                          java.lang.String password,
                          ReporterInterface reporter,
                          boolean connectionTesting,
                          int poolSize)
                   throws java.sql.SQLException,
                          java.lang.InterruptedException
Creates a JDBCConnectionPool using the given jdbcURL, username, password, reporter, validation, and pool size. If connectionTesting is set to true, JDBCConnections are validated before returned by getConnection().

Throws:
java.sql.SQLException
java.lang.InterruptedException
Method Detail

size

public int size()
Returns the Pool's current size


closeConnections

public void closeConnections()
Removes each connection from the connection pool and stops the WatchDog thread.


removeConnection

public void removeConnection(JDBCConnection c)
Removes the specified connection from the connection pool. This can be called by a caller when the JDBCConnection is no longer connected to the database and the connection should NOT be added back into the pool.


getConnection

public JDBCConnection getConnection()
                             throws java.sql.SQLException,
                                    java.lang.InterruptedException
Attempts to lease a connection from the pool. This method will block until a valid connection is returned.

Throws:
java.sql.SQLException
java.lang.InterruptedException

returnConnection

public void returnConnection(JDBCConnection conn)
Marks the specified connection as no longer in use so that it can be returned by subsequent calls to getConnection().


toString

public java.lang.String toString()
Returns this connection as a String.

Overrides:
toString in class java.lang.Object

debug

public void debug(java.lang.String message)
Prints a debug message tagged with this JDBCConnectionPool's identity to the output stream.


warning

public void warning(java.lang.String message)
Prints a warning message tagged with this JDBCConnectionPool's identity to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


warning

public void warning(java.lang.String message,
                    java.lang.Exception e)
Prints an warning message tagged with this JDBCConnectionPool's identity followed by a stack trace of the passed Exception to error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


error

public void error(java.lang.String message)
Prints an error message tagged with this JDBCConnectionPool's identity to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


error

public void error(java.lang.String message,
                  java.lang.Exception e)
Prints an error message tagged with this JDBCConnectionPool's identity followed by a stack trace of the passed Exception to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


println

public void println(java.lang.String message)
Prints a message tagged with this JDBCConnectionPool's identity to the output stream.


setReporter

public void setReporter(ReporterInterface reporter)
Sets the reporter for this JDBCConnectionPool.