com.fatwire.cs.core.db
Class PreparedStmt

java.lang.Object
  extended by com.fatwire.cs.core.db.PreparedStmt
All Implemented Interfaces:
java.lang.Cloneable

public final class PreparedStmt
extends java.lang.Object
implements java.lang.Cloneable

This class is a thin abstraction over the JDBC PreparedStatement functionality.

It is constructed with SQL and a list of affected tables. Then, each placeholder is identified - see PreparedStmt.setElement(int, java.lang.String, java.lang.String).

Once all elements have been set, the object is complete (see PreparedStmt.isComplete().)

A StatementParam object is created using PreparedStmt.newParam(), and the parameter is then populated with the prepared statement variables which are passed to the statement when executed.


Constructor Summary
PreparedStmt(java.lang.String sStmt, java.util.List tables)
          Constructs a new PreparedStmt using basic SQL construct that is used to build a prepared statement and tables used in it (in the form clause).
 
Method Summary
 java.lang.Object clone()
          Deep copy
 java.lang.String columnNameAt(int pos)
          Returns column name at given placeholder position
 int getFetchDirection()
          Returns the configured fetch direction
 int getFetchSize()
          Returns the fetch size that will be used while executing this statement.
 int getLimit()
          Returns the max number of rows configured.
 int getPositionsCount()
          Returns the number of placeholders in this prepared statement.
 java.lang.String getStatement()
          Returns the SQL statement used for preparing the prepared statement.
 java.util.List getTables()
          Returns table names as a part of this prepared statement.
 java.util.List getTypes()
          Returns list of 'types' (Integer representation of sql types) in the order in which they appear in the prepared statement.
 boolean isComplete()
          Indicates if this instance is completely formed (bound with data).
 StatementParam newParam()
          Creates an exemplar instance of Parameter container.
 void setElement(int pos, int type)
          Sets type information at position pos.
 void setElement(int pos, java.lang.String sTableName, java.lang.String sFieldName)
          Sets type information at position pos.
 void setFetchDirection(int fetchDirection)
          Sets the JDBC fetch direction to be used for result execution The value defaults to ResultSet.FETCH_FORWARD
 void setFetchSize(int fetchSize)
          Sets the fetch size to to be used for execution of this statement
 void setLimit(int limit)
          Sets the maximum number of rows for execution of this statement.
 java.lang.String tableNameAt(int pos)
          Returns tablename specified at a given position
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreparedStmt

public PreparedStmt(java.lang.String sStmt,
                    java.util.List tables)
Constructs a new PreparedStmt using basic SQL construct that is used to build a prepared statement and tables used in it (in the form clause).

Parameters:
sStmt -
tables -
Method Detail

setElement

public void setElement(int pos,
                       java.lang.String sTableName,
                       java.lang.String sFieldName)
Sets type information at position pos. The system figures out appropriate native datatype that is required at this position by lookingup the metadata from table sTableName.

Parameters:
pos - 0 based index of the placeholder position
sTableName - Name of the table where sFieldName can be found. The table must exist in the same database, accessible by the user. This table is usually a part of the SQL statement itself.
sFieldName - name of the field whose datatype will be used for the placeholder with index pos.

setElement

public void setElement(int pos,
                       int type)
Sets type information at position pos. type indidates the actual JDBC type that should be used for the placeholder.

Parameters:
pos - 0 based index of the placeholder position
type - one of constants in Types
See Also:
Types

getStatement

public java.lang.String getStatement()
Returns the SQL statement used for preparing the prepared statement. This statement typically contains '?' characters which are considered placeholders for runtime data.

Returns:
SQL statement construct upon which this PreparedStatement is based.

getPositionsCount

public int getPositionsCount()
Returns the number of placeholders in this prepared statement.

Returns:
Number of placeholders as discovered in the SQL statement

getTypes

public java.util.List getTypes()
Returns list of 'types' (Integer representation of sql types) in the order in which they appear in the prepared statement. If type is not resolved for a position a 'null' value is included.

Returns:
List of Integer objects representing sql type for placeholders.

tableNameAt

public java.lang.String tableNameAt(int pos)
Returns tablename specified at a given position

Parameters:
pos - index of the placeholder (0 based)
Returns:
tablename at pos, can be null

columnNameAt

public java.lang.String columnNameAt(int pos)
Returns column name at given placeholder position

Parameters:
pos - index of the placeholder (0 based)
Returns:
column name at pos, can be null

getTables

public java.util.List getTables()
Returns table names as a part of this prepared statement.

Returns:
List of table names.

newParam

public StatementParam newParam()
Creates an exemplar instance of Parameter container.

Returns:
new (empty) instance of StatementParam.

isComplete

public boolean isComplete()
Indicates if this instance is completely formed (bound with data).

Returns:
true if all placeholders have been assigned values, false otherwise.

setFetchSize

public void setFetchSize(int fetchSize)
Sets the fetch size to to be used for execution of this statement

Parameters:
fetchSize - desired fetch size, ignored if fetchSize < 0

getFetchSize

public int getFetchSize()
Returns the fetch size that will be used while executing this statement.

Returns:
fetchSize fetch size specified. -1 when not specified.

setFetchDirection

public void setFetchDirection(int fetchDirection)
Sets the JDBC fetch direction to be used for result execution The value defaults to ResultSet.FETCH_FORWARD

Parameters:
fetchDirection - new fetch direction must be ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE or ResultSet.FETCH_UNKNOWN. Other values ignored

getFetchDirection

public int getFetchDirection()
Returns the configured fetch direction

Returns:
ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE or ResultSet.FETCH_UNKNOWN

getLimit

public int getLimit()
Returns the max number of rows configured.

Returns:
maximum number of rows configured for this statement, -1 if not configured.

setLimit

public void setLimit(int limit)
Sets the maximum number of rows for execution of this statement.

Parameters:
limit - maximum number of rows to be returned (negative values are ignored at the execution time)

clone

public java.lang.Object clone()
Deep copy

Overrides:
clone in class java.lang.Object
Returns:
Deep copy of the original.