velosurf.sql
Class PooledStatement

java.lang.Object
  extended by velosurf.sql.Pooled
      extended by velosurf.sql.PooledStatement
All Implemented Interfaces:
ReadOnlyMap

public class PooledStatement
extends Pooled
implements ReadOnlyMap

this class encapsulates a jdbc Statement

Author:
Claude Brisson

Field Summary
protected  java.util.List columnNames
          column names in natural order
protected  ConnectionWrapper connection
          database connection
protected  java.lang.String query
          SQL query
protected  java.sql.ResultSet resultSet
          result set
protected  java.sql.Statement statement
          wrapped statement
 
Fields inherited from class velosurf.sql.Pooled
inUse, tagTime, useOver, valid
 
Constructor Summary
protected PooledStatement(ConnectionWrapper connection, java.sql.Statement statement)
          builds a new PooledStatement
 
Method Summary
 void close()
          close thos statement
 java.lang.Object evaluate(java.lang.String query)
          evaluates the SQL query as a scalar
 java.lang.Object fetch(java.lang.String query)
          fetch a single row
 java.lang.Object fetch(java.lang.String query, Entity resultEntity)
          fetch a single row, specyfing the entity it belongs to
 java.lang.Object get(java.lang.Object key)
          get specified column as an object
 ConnectionWrapper getConnection()
          get statement's Connection
 long getLastInsertID()
          gets the last insert id
 java.util.Set keySet()
           
 void notifyOver()
          notify this statement is no more used and can be recycled
 RowIterator query(java.lang.String query)
          gets the resultset for this statement
 RowIterator query(java.lang.String query, Entity resultEntity)
          gets the resultset for this statement, specifying the entity the results belong to
 int update(java.lang.String query)
          issues the update contained in the query
 
Methods inherited from class velosurf.sql.Pooled
getTagTime, isInUse, isValid, notifyInUse, resetTagTime, setInvalid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

query

protected java.lang.String query
SQL query


connection

protected ConnectionWrapper connection
database connection


resultSet

protected java.sql.ResultSet resultSet
result set


columnNames

protected java.util.List columnNames
column names in natural order


statement

protected java.sql.Statement statement
wrapped statement

Constructor Detail

PooledStatement

protected PooledStatement(ConnectionWrapper connection,
                          java.sql.Statement statement)
builds a new PooledStatement

Parameters:
connection - database connection
statement - wrapped Statement
Method Detail

query

public RowIterator query(java.lang.String query)
                  throws java.sql.SQLException
gets the resultset for this statement

Parameters:
query - SQL query
Returns:
resulting RowIterator
Throws:
java.sql.SQLException - thrown by the database engine

query

public RowIterator query(java.lang.String query,
                         Entity resultEntity)
                  throws java.sql.SQLException
gets the resultset for this statement, specifying the entity the results belong to

Parameters:
query - SQL query
resultEntity - entity
Returns:
the resulting RowIterator
Throws:
java.sql.SQLException - thrown by the database engine

fetch

public java.lang.Object fetch(java.lang.String query)
                       throws java.sql.SQLException
fetch a single row

Parameters:
query - SQL query
Returns:
fetched row
Throws:
java.sql.SQLException - thrown by the database engine

fetch

public java.lang.Object fetch(java.lang.String query,
                              Entity resultEntity)
                       throws java.sql.SQLException
fetch a single row, specyfing the entity it belongs to

Parameters:
query - SQL query
resultEntity - entity
Returns:
the fetched Instance
Throws:
java.sql.SQLException - thrown by the database engine

get

public java.lang.Object get(java.lang.Object key)
                     throws java.sql.SQLException
get specified column as an object

Specified by:
get in interface ReadOnlyMap
Parameters:
key - column
Returns:
object value
Throws:
java.sql.SQLException - thrown by the database engine

keySet

public java.util.Set keySet()
                     throws java.sql.SQLException
Specified by:
keySet in interface ReadOnlyMap
Throws:
java.sql.SQLException

evaluate

public java.lang.Object evaluate(java.lang.String query)
                          throws java.sql.SQLException
evaluates the SQL query as a scalar

Parameters:
query - SQL query
Returns:
found scalar
Throws:
java.sql.SQLException - thrown by the database engine

update

public int update(java.lang.String query)
           throws java.sql.SQLException
issues the update contained in the query

Parameters:
query - SQL query
Returns:
number of affected rows
Throws:
java.sql.SQLException - thrown by the database engine

close

public void close()
           throws java.sql.SQLException
close thos statement

Specified by:
close in class Pooled
Throws:
java.sql.SQLException - thrown by the database engine

notifyOver

public void notifyOver()
notify this statement is no more used and can be recycled

Overrides:
notifyOver in class Pooled

getLastInsertID

public long getLastInsertID()
                     throws java.sql.SQLException
gets the last insert id

Returns:
last insert id
Throws:
java.sql.SQLException - thrown by the database engine

getConnection

public ConnectionWrapper getConnection()
get statement's Connection

Specified by:
getConnection in class Pooled
Returns:
the Connection object (usually a ConnectionWrapper object)


~ooOoo~