FileDocCategorySizeDatePackage
StatementPool.javaAPI DocExample2219Mon Mar 31 23:10:16 BST 2003org.dasein.persist

StatementPool

public class StatementPool extends Object
Implements the pooling algorithm for statement pooling under this library. This algorithm is currently simplistic in the extreme. Specifically, all statements must be non-scrollable and non-updatable and they are stored in a hash based on the actual SQL.
Last
modified $Datte$
version
$Revision$
author
George Reese

Fields Summary
private HashMap
statements
The actual pool of statements hased by their SQL.
Constructors Summary
public StatementPool()
Constructs a new statement pool.


              
      
        super();
    
Methods Summary
public booleancontains(java.lang.String sql)
Checks to see if a pooled statement is available that matches the specified SQL.

param
sql the SQL to match
return
true if there is a pooled version of the statement

        Stack stack;

        if( !statements.containsKey(sql) ) {
            return false;
        }
        stack = (Stack)statements.get(sql);
        return !stack.empty();
    
public java.sql.PreparedStatementpop(java.lang.String sql)
Grabs a statement matching the specified SQL from the pool.

param
sql the SQL for which a statement is desired
return
the pooled statement matching the SQL

        Stack stack = (Stack)statements.get(sql);

        return (PreparedStatement)stack.pop();
    
public voidpush(java.lang.String sql, java.sql.PreparedStatement stmt)
Returns the statement with the specified SQL to the pool.

param
sql the SQL of the statement
param
stmt the statement to return to the pool

        Stack stack;
        
        if( statements.containsKey(sql) ) {
            stack = (Stack)statements.get(sql);
        }
        else {
            stack = new Stack();
            statements.put(sql, stack);
        }
        stack.push(stmt);