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
protected static long checkDelay
          check delay
protected  java.lang.Thread checkTimeoutThread
          running thread
protected  ConnectionPool connectionPool
          connection pool
protected  int count
          statements count
protected static int maxStatements
          max number of statements
protected  boolean running
          true if running
protected  HashMultiMap statementsMap
          map queries -> statements
protected static long timeout
          after this timeout, statements are recycled even if not closed
 
Constructor Summary
protected PreparedStatementPool(ConnectionPool connectionPool)
          builds a new pool
 
Method Summary
 void clear()
          close all statements
protected  void dropConnection(java.sql.Connection connection)
           
protected  void finalize()
          clear statements on exit
 PooledPreparedStatement getPreparedStatement(java.lang.String query)
          gets a PooledPreparedStatement associated with this query
protected  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

protected ConnectionPool connectionPool
connection pool


count

protected int count
statements count


statementsMap

protected HashMultiMap statementsMap
map queries -> statements


checkTimeoutThread

protected java.lang.Thread checkTimeoutThread
running thread


running

protected boolean running
true if running


checkDelay

protected static final long checkDelay
check delay

See Also:
Constant Field Values

timeout

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

See Also:
Constant Field Values

maxStatements

protected static final int maxStatements
max number of statements

See Also:
Constant Field Values
Constructor Detail

PreparedStatementPool

protected PreparedStatementPool(ConnectionPool connectionPool)
builds a new pool

Parameters:
connectionPool - connection pool
Method Detail

getPreparedStatement

public PooledPreparedStatement getPreparedStatement(java.lang.String query)
                                             throws java.sql.SQLException
gets 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

protected void dropConnection(java.sql.Connection connection)

finalize

protected void finalize()
clear statements on exit

Overrides:
finalize in class java.lang.Object

getUsageStats

protected int[] getUsageStats()
debug - get usage statistics

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


~ooOoo~