Top Description Inners Fields Constructors Methods
org.hsqldb

public final Class StatementManager

extends Object
Class Inheritance
Imports
org.hsqldb.HsqlNameManager.HsqlName, org.hsqldb.lib.HashSet, .LongKeyHashMap, .ObjectComparator, org.hsqldb.result.Result, .ResultMetaData

This class manages the reuse of Statement objects for prepared statements for a Session instance.

A compiled statement is registered by a session to be managed.

The sql statement text distinguishes different compiled statements and acts as lookup key when a session initially looks for an existing instance of the compiled sql statement.

The unique compiled statement id for the sql statement is used to access the statement.

Changes to database structure via DDL statements, will result in all registered Statement objects to become invalidated. This is done by comparing the schema change and compile timestamps. When a session subsequently attempts to use an invalidated Statement via its id, it will recompiles the Statement using its sql statement still held by this class. failure to recompile invalidates and removes the Statement.

This class keeps count of the number of time each registered compiled statement is linked to a session. It unregisters a compiled statement when it is not in use.

Modified by fredt@users from the original by campbell-burnet@users to simplify, support multiple identical prepared statements per session, and avoid memory leaks. Changed implementation to a session object for optimised access.

Authors
Campbell Burnet (campbell-burnet@users dot sourceforge.net), Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.2
Version
2.7.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private LongKeyHashMap<StatementManager.StatementWrapper>
csidMap

Map: Statement id (int) maps to: wrapper for Statement object.

private Database
database

The Database for which this is managing Statement objects.

private long
next_cs_id

Monotonically increasing counter used to assign unique ids to Statement objects.

private Session
session

The Session for which this is managing Statement objects

private HashSet<StatementManager.StatementWrapper>
statementSet

Set of wrappers for Statement object.

Constructor Summary

AccessConstructor and Description
pack-priv
StatementManager(Session
the session instance for which this object is to manage Statement objects.
session
)

Constructs a new instance of StatementManager.

Method Summary

Modifier and TypeMethod and Description
pack-priv Statement

Returns:

Statement
compile
(Result
the Result holding the SQL
cmd
)

Compiles an SQL statement and returns a Statement Object

pack-priv void
freeStatement(long
the Statement identifier
csid
)

Removes a link between a PreparedStatement and a Statement.

public Statement

Returns:

the requested Statement object
getStatement
(long
the identifier of the requested Statement object
csid
)

Used by JDBC for a previously prepared statement.

private Statement
public Statement

Returns:

the requested Statement object
getStatement
(Statement
the old expired statement
statement
)

Recompiles an existing statement.

private long

Returns:

the next Statement identifier in the sequence.
nextID
()

Retrieves the next Statement identifier in the sequence.

private Statement

Returns:

the new Statement object
recompileStatement
(Statement
the old expired statement
cs
)

Returns an up-to-date Statement using the SQL and settings of the original.

private long

Returns:

The statement id assigned to the Statement object
registerStatement
(StatementManager.StatementWrapper
the wrapper for the Statement to add
wrapper
)

Registers a Statement to be managed.

private void
removeStatement(long
the Statement identifier
csid
)

Removes an invalidated Statement.

pack-priv void
reset()

Clears all internal data structures, removing any references to Statements.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

csidMapback to summary
private LongKeyHashMap<StatementManager.StatementWrapper> csidMap

Map: Statement id (int) maps to: wrapper for Statement object.

databaseback to summary
private Database database

The Database for which this is managing Statement objects.

next_cs_idback to summary
private long next_cs_id

Monotonically increasing counter used to assign unique ids to Statement objects.

sessionback to summary
private Session session

The Session for which this is managing Statement objects

statementSetback to summary
private HashSet<StatementManager.StatementWrapper> statementSet

Set of wrappers for Statement object.

Constructor Detail

StatementManagerback to summary
pack-priv StatementManager(Session session)

Constructs a new instance of StatementManager.

Parameters
session:Session

the session instance for which this object is to manage Statement objects.

Method Detail

compileback to summary
pack-priv Statement compile(Result cmd)

Compiles an SQL statement and returns a Statement Object

Parameters
cmd:Result

the Result holding the SQL

Returns:Statement

Statement

freeStatementback to summary
pack-priv void freeStatement(long csid)

Removes a link between a PreparedStatement and a Statement. If the statement is not linked with any other PreparedStatement, it is removed from management.

Parameters
csid:long

the Statement identifier

getStatementback to summary
public Statement getStatement(long csid)

Used by JDBC for a previously prepared statement. Returns an existing Statement object with the given statement identifier. Returns null if the Statement object has expired and cannot be recompiled

Parameters
csid:long

the identifier of the requested Statement object

Returns:Statement

the requested Statement object

getStatementback to summary
private Statement getStatement(StatementManager.StatementWrapper sw)
getStatementback to summary
public Statement getStatement(Statement statement)

Recompiles an existing statement. Used by transaction manager for all statements, prepared or not prepred.

Parameters
statement:Statement

the old expired statement

Returns:Statement

the requested Statement object

nextIDback to summary
private long nextID()

Retrieves the next Statement identifier in the sequence.

Returns:long

the next Statement identifier in the sequence.

recompileStatementback to summary
private Statement recompileStatement(Statement cs)

Returns an up-to-date Statement using the SQL and settings of the original. Returns null if the SQL cannot be compiled.

Parameters
cs:Statement

the old expired statement

Returns:Statement

the new Statement object

registerStatementback to summary
private long registerStatement(StatementManager.StatementWrapper wrapper)

Registers a Statement to be managed.

Parameters
wrapper:StatementManager.StatementWrapper

the wrapper for the Statement to add

Returns:long

The statement id assigned to the Statement object

removeStatementback to summary
private void removeStatement(long csid)

Removes an invalidated Statement.

Parameters
csid:long

the Statement identifier

resetback to summary
pack-priv void reset()

Clears all internal data structures, removing any references to Statements.

org.hsqldb back to summary

private Class StatementManager.StatementComparator

extends Object
implements ObjectComparator<StatementManager.StatementWrapper>
Class Inheritance
All Implemented Interfaces
org.hsqldb.lib.ObjectComparator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
public int
public long
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

StatementComparatorback to summary
private StatementComparator()

Method Detail

equalsback to summary
public boolean equals(StatementManager.StatementWrapper s1, StatementManager.StatementWrapper s2)

Implements org.hsqldb.lib.ObjectComparator.equals.

hashCodeback to summary
public int hashCode(StatementManager.StatementWrapper a)

Implements org.hsqldb.lib.ObjectComparator.hashCode.

longKeyback to summary
public long longKey(StatementManager.StatementWrapper a)

Implements org.hsqldb.lib.ObjectComparator.longKey.

org.hsqldb back to summary

private Class StatementManager.StatementWrapper

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv ResultMetaData
pack-priv int
pack-priv HsqlNameManager.HsqlName
pack-priv String
pack-priv Statement
pack-priv long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cursorPropsback to summary
pack-priv int cursorProps
generatedMetaDataback to summary
pack-priv ResultMetaData generatedMetaData
generatedTypeback to summary
pack-priv int generatedType
schemaNameback to summary
pack-priv HsqlNameManager.HsqlName schemaName
sqlback to summary
pack-priv String sql
statementback to summary
pack-priv Statement statement
usageCountback to summary
pack-priv long usageCount

Constructor Detail

StatementWrapperback to summary
private StatementWrapper()