org.melati.poem
Class PreparedStatementFactory

Package class diagram package PreparedStatementFactory
java.lang.Object
  extended by org.melati.poem.util.CachedIndexFactory
      extended by org.melati.poem.PreparedStatementFactory
All Implemented Interfaces:
IndexFactory

public class PreparedStatementFactory
extends CachedIndexFactory

Maintains a cache of PreparedStatements for an SQL statement string.

The cached contents are discarded if the database structure has changed since the cache was created.

Execution of the statement in a transaction reflects uncommitted changes in that transaction.

The supertype dictates that connections can be indentified by index, but this is slightly complicated and the additional methods rely on transactions instead.


Constructor Summary
PreparedStatementFactory(Database database, String sql)
          Constructor.
 
Method Summary
 Object get(int index)
          Get either from cache or, failing that, really get it.
 PreparedStatement preparedStatement()
           
 PreparedStatement preparedStatement(PoemTransaction transaction)
          Get a new or cached PreparedStatement.
protected  Object reallyGet(int index)
          Obtain a fresh PreparedStatement for a connection identified by an index.
 ResultSet resultSet()
           
protected  ResultSet resultSet(SessionToken token)
           
protected  ResultSet resultSet(SessionToken token, PreparedStatement statement)
           
 String toString()
          
 
Methods inherited from class org.melati.poem.util.CachedIndexFactory
invalidate, invalidate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PreparedStatementFactory

public PreparedStatementFactory(Database database,
                                String sql)
Constructor.

Parameters:
database - the db we are working with
sql - the SQL statement
Method Detail

reallyGet

protected Object reallyGet(int index)
Obtain a fresh PreparedStatement for a connection identified by an index.

The index is zero for the commited connection and the transaction index plus 1 for current transactions.

Specified by:
reallyGet in class CachedIndexFactory
Parameters:
index - of the item, possibly a troid
Returns:
the cached Object

get

public Object get(int index)
Get either from cache or, failing that, really get it.

Specified by:
get in interface IndexFactory
Overrides:
get in class CachedIndexFactory
Parameters:
index - the index
Returns:
the object
See Also:
CachedIndexFactory.get(int)

preparedStatement

public PreparedStatement preparedStatement(PoemTransaction transaction)
Get a new or cached PreparedStatement.

Parameters:
transaction - the PoemTransaction, can be null
Returns:
a new or cached PreparedStatement

preparedStatement

public final PreparedStatement preparedStatement()
Returns:
a new or cached PreparedStatement for the current PoemThread's transaction.

resultSet

protected ResultSet resultSet(SessionToken token,
                              PreparedStatement statement)

resultSet

protected final ResultSet resultSet(SessionToken token)

resultSet

public final ResultSet resultSet()
Returns:
the ResultSet from the PreparedStatement of the PoemThread

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2000-2010 PanEris. All Rights Reserved.