velosurf.sql
Class PreparedStatementPool

java.lang.Object
  extended by velosurf.sql.PreparedStatementPool
All Implemented Interfaces:
java.lang.Runnable, Pool

public class PreparedStatementPool
extends java.lang.Object
implements java.lang.Runnable, Pool

This class is a pool of PooledPreparedStatements.

Author:
Claude Brisson

Field Summary
private static long checkDelay
          check delay.
private  java.lang.Thread checkTimeoutThread
          running thread.
private  ConnectionPool connectionPool
          connection pool.
private  int count
          statements count.
private static int maxStatements
          max number of statements.
private  boolean running
          true if running.
private  HashMultiMap statementsMap
          map queries -> statements.
private static long timeout
          after this timeout, statements are recycled even if not closed.
 
Constructor Summary
protected PreparedStatementPool(ConnectionPool connectionPool)
          build a new pool.
 
Method Summary
 void clear()
          close all statements.
private  void dropConnection(java.sql.Connection connection)
           
protected  void finalize()
          clear statements on exit.
 PooledPreparedStatement getPreparedStatement(java.lang.String query)
          get a PooledPreparedStatement associated with this query.
 int[] getUsageStats()
          debug - get usage statistics.
 void run()
          cycle through statements to check and recycle them.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionPool

private ConnectionPool connectionPool
connection pool.


count

private int count
statements count.


statementsMap

private HashMultiMap statementsMap
map queries -> statements.


checkTimeoutThread

private java.lang.Thread checkTimeoutThread
running thread.


running

private boolean running
true if running.


checkDelay

private static final long checkDelay
check delay.

See Also:
Constant Field Values

timeout

private static final long timeout
after this timeout, statements are recycled even if not closed.

See Also:
Constant Field Values

maxStatements

private static final int maxStatements
max number of statements.

See Also:
Constant Field Values
Constructor Detail

PreparedStatementPool

protected PreparedStatementPool(ConnectionPool connectionPool)
build a new pool.

Parameters:
connectionPool - connection pool
Method Detail

getPreparedStatement

public PooledPreparedStatement getPreparedStatement(java.lang.String query)
                                             throws java.sql.SQLException
get a PooledPreparedStatement associated with this query.

Parameters:
query - an SQL query
Returns:
a valid statement
Throws:
java.sql.SQLException - thrown by the database engine

run

public void run()
cycle through statements to check and recycle them.

Specified by:
run in interface java.lang.Runnable

clear

public void clear()
close all statements.


dropConnection

private void dropConnection(java.sql.Connection connection)

finalize

protected void finalize()
clear statements on exit.

Overrides:
finalize in class java.lang.Object

getUsageStats

public int[] getUsageStats()
debug - get usage statistics.

Returns:
an int array : [nb of statements in use , total nb of statements]


~ooOoo~