velosurf.sql
Class PreparedStatementPool

java.lang.Object
  |
  +--velosurf.sql.PreparedStatementPool
All Implemented Interfaces:
Pool, java.lang.Runnable

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  java.lang.Thread mCheckTimeoutThread
          running thread
protected  int mCount
          statements count
protected  DBConnection mDBConnection
          database connection
protected  boolean mRunning
          true if running
protected  java.lang.Object mSemaphore
          semaphore
protected  HashMultiMap mStatementsMap
          map queries -> statements
protected static long sCheckDelay
          check delay
protected static int sMaxStatements
          max number of statements
protected static long sTimeout
          after this timeout, statements are recycled even if not closed
 
Constructor Summary
protected PreparedStatementPool(DBConnection inDBConnection)
          builds a new pool
 
Method Summary
 void clear()
          close all statements
protected  void finalize()
          clear statements on exit
protected  PooledPreparedStatement getPreparedStatement(java.lang.String inQuery)
          gets a PooledPreparedStatement associated with this query
protected  PooledPreparedStatement getTransactionPreparedStatement(java.lang.String inQuery)
          get a statement that is going to be used in transactions
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, registerNatives, toString, wait, wait, wait
 

Field Detail

mDBConnection

protected DBConnection mDBConnection
database connection

mCount

protected int mCount
statements count

mStatementsMap

protected HashMultiMap mStatementsMap
map queries -> statements

mCheckTimeoutThread

protected java.lang.Thread mCheckTimeoutThread
running thread

mRunning

protected boolean mRunning
true if running

mSemaphore

protected java.lang.Object mSemaphore
semaphore

sCheckDelay

protected static long sCheckDelay
check delay

sTimeout

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

sMaxStatements

protected static int sMaxStatements
max number of statements
Constructor Detail

PreparedStatementPool

protected PreparedStatementPool(DBConnection inDBConnection)
builds a new pool
Parameters:
inDBConnection - database connection
Method Detail

getPreparedStatement

protected PooledPreparedStatement getPreparedStatement(java.lang.String inQuery)
                                                throws java.sql.SQLException
gets a PooledPreparedStatement associated with this query
Parameters:
inQuery - an SQL query
Returns:
a valid statement
Throws:
java.sql.SQLException - thrown by the database engine

getTransactionPreparedStatement

protected PooledPreparedStatement getTransactionPreparedStatement(java.lang.String inQuery)
                                                           throws java.sql.SQLException
get a statement that is going to be used in transactions
Parameters:
inQuery - an SQL query
Returns:
a valid PooledPreparedStatement
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

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