org.tentackle.db
Class PreparedStatementWrapper

java.lang.Object
  extended by org.tentackle.db.StatementWrapper
      extended by org.tentackle.db.PreparedStatementWrapper

public class PreparedStatementWrapper
extends StatementWrapper

A wrapper for prepared statements.
Will catch and report SQLExceptions and keep track of being used only once after Db.getPreparedStatement(int).

Author:
harald

Field Summary
 
Fields inherited from class org.tentackle.db.StatementWrapper
con, ready, stmt
 
Constructor Summary
PreparedStatementWrapper(ManagedConnection con, PreparedStatement stmt)
          Creates a wrapper for a prepared statement.
 
Method Summary
 ResultSetWrapper executeQuery()
          Executes the query.
 ResultSetWrapper executeQuery(boolean withinTx)
          Executes the query.
 int executeUpdate()
          Executes the update.
 int getColumnOffset()
          Gets the column offset.
 PreparedStatement getStatement()
          Gets the wrapped prepared statement.
 void setBigDecimal(int p, BigDecimal d)
          Sets the designated parameter to the given java.math.BigDecimal value.
 void setBinary(int p, Binary b)
          Sets the designated parameter to the given Binary value.
 void setBMoney(int p, BMoney m)
          Sets the designated parameter to a BMoney value.
A BMoney will not be stored as a single field but as two fields: a double representing the value an int representing the scale This is due to most DBMS can't store arbitrary scaled decimals in a single column, i.e.
 void setBoolean(int p, boolean b)
          Sets the designated parameter to the given Java boolean value.
 void setBoolean(int p, Boolean b)
          Sets the designated parameter to the given Java Boolean value.
 void setByte(int p, byte b)
          Sets the designated parameter to the given Java byte value.
 void setByte(int p, Byte b)
          Sets the designated parameter to the given Java Byte value.
 void setChar(int p, char c)
          Sets the designated parameter to the given Java char value.
 void setCharacter(int p, Character c)
          Sets the designated parameter to the given Java Character value.
 void setCharacter(int p, Character c, boolean mapNull)
          Sets the designated parameter to the given Java Character value.
 void setColumnOffset(int columnOffset)
          Sets the column offset.
 void setDate(int p, Date d)
          Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.
 void setDate(int p, Date d, boolean mapNull)
          Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.
 void setDMoney(int p, DMoney m)
          Sets the designated parameter to a DMoney value.
A DMoney will not be stored as a single field but as two fields: a BigDecimal with a scale of 0 representing the value an int representing the scale This is due to most DBMS can't store arbitrary scaled decimals in a single column, i.e.
 void setDouble(int p, double d)
          Sets the designated parameter to the given Java double value.
 void setDouble(int p, Double d)
          Sets the designated parameter to the given Java Double value.
 void setFloat(int p, float f)
          Sets the designated parameter to the given Java float value.
 void setFloat(int p, Float f)
          Sets the designated parameter to the given Java Float value.
 void setInt(int p, int i)
          Sets the designated parameter to the given Java int value.
 void setInteger(int p, Integer i)
          Sets the designated parameter to the given Java Integer value.
 void setLong(int p, long l)
          Sets the designated parameter to the given Java long value.
 void setLong(int p, Long l)
          Sets the designated parameter to the given Java Long value.
 void setNull(int pos, int type)
          Sets the designated parameter to SQL NULL.
 void setShort(int p, short s)
          Sets the designated parameter to the given Java short value.
 void setShort(int p, Short s)
          Sets the designated parameter to the given Java Short value.
 void setString(int p, String s)
          Sets the designated parameter to the given Java String value.
 void setString(int p, String s, boolean mapNull)
          Sets the designated parameter to the given Java String value.
 void setTime(int p, Time t)
          Sets the designated parameter to the given java.sql.Time value.
 void setTimestamp(int p, Timestamp ts)
          Sets the designated parameter to the given java.sql.Timestamp value.
 void setTimestamp(int p, Timestamp ts, boolean mapNull)
          Sets the designated parameter to the given java.sql.Timestamp value.
 
Methods inherited from class org.tentackle.db.StatementWrapper
close, detachDb, executeQuery, executeQuery, executeUpdate, getConnection, getDb, getFetchDirection, getFetchSize, getMaxRows, isClosed, isMarkedReady, markReady, setFetchDirection, setFetchSize, setMaxRows, toString, unmarkReady
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PreparedStatementWrapper

public PreparedStatementWrapper(ManagedConnection con,
                                PreparedStatement stmt)
Creates a wrapper for a prepared statement.

Parameters:
con -
stmt -
Method Detail

getStatement

public PreparedStatement getStatement()
Gets the wrapped prepared statement.

Overrides:
getStatement in class StatementWrapper
Returns:
the prepared statement, null if closed

setColumnOffset

public void setColumnOffset(int columnOffset)
Sets the column offset. Useful for eager loading or joining in general.

Parameters:
columnOffset - (default is 0)

getColumnOffset

public int getColumnOffset()
Gets the column offset.

Returns:
the current columnOffset

executeUpdate

public int executeUpdate()
Executes the update.

Returns:
the row count

executeQuery

public ResultSetWrapper executeQuery(boolean withinTx)
Executes the query.

Parameters:
withinTx - is true if start a transaction for this query.
Returns:
the result set as a ResultSetWrapper

executeQuery

public ResultSetWrapper executeQuery()
Executes the query.

Returns:
the result set as a ResultSetWrapper

setNull

public void setNull(int pos,
                    int type)
Sets the designated parameter to SQL NULL.

Parameters:
pos - the first parameter is 1, the second is 2, ...
type - the SQL type code defined in java.sql.Types

setString

public void setString(int p,
                      String s,
                      boolean mapNull)
Sets the designated parameter to the given Java String value. The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's size relative to the driver's limits on VARCHAR values) when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
s - the parameter value
mapNull - true if null values should be mapped to the empty string, else SQL NULL

setString

public void setString(int p,
                      String s)
Sets the designated parameter to the given Java String value. The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's size relative to the driver's limits on VARCHAR values) when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
s - the parameter value, null if the value should be set to SQL NULL

setBoolean

public void setBoolean(int p,
                       boolean b)
Sets the designated parameter to the given Java boolean value. The driver converts this to an SQL BIT or BOOLEAN value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
b - the parameter value

setBoolean

public void setBoolean(int p,
                       Boolean b)
Sets the designated parameter to the given Java Boolean value. The driver converts this to an SQL BIT or BOOLEAN value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
b - the parameter value, null if the value should be set to SQL NULL

setByte

public void setByte(int p,
                    byte b)
Sets the designated parameter to the given Java byte value. The driver converts this to an SQL TINYINT value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
b - the parameter value

setByte

public void setByte(int p,
                    Byte b)
Sets the designated parameter to the given Java Byte value. The driver converts this to an SQL TINYINT value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
b - the parameter value, null if the value should be set to SQL NULL

setChar

public void setChar(int p,
                    char c)
Sets the designated parameter to the given Java char value. The driver converts this to an SQL VARCHAR when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
c - the parameter value

setCharacter

public void setCharacter(int p,
                         Character c,
                         boolean mapNull)
Sets the designated parameter to the given Java Character value. The driver converts this to an SQL VARCHAR when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
c - the parameter value, null if the value should be set to SQL NULL
mapNull - true if null values should be mapped to BLANK, else SQL NULL

setCharacter

public void setCharacter(int p,
                         Character c)
Sets the designated parameter to the given Java Character value. The driver converts this to an SQL VARCHAR when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
c - the parameter value, null if the value should be set to SQL NULL

setShort

public void setShort(int p,
                     short s)
Sets the designated parameter to the given Java short value. The driver converts this to an SQL SMALLINT value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
s - the parameter value

setShort

public void setShort(int p,
                     Short s)
Sets the designated parameter to the given Java Short value. The driver converts this to an SQL SMALLINT value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
s - the parameter value, null if the value should be set to SQL NULL

setInt

public void setInt(int p,
                   int i)
Sets the designated parameter to the given Java int value. The driver converts this to an SQL INTEGER value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
i - the parameter value

setInteger

public void setInteger(int p,
                       Integer i)
Sets the designated parameter to the given Java Integer value. The driver converts this to an SQL INTEGER value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
i - the parameter value, null if the value should be set to SQL NULL

setLong

public void setLong(int p,
                    long l)
Sets the designated parameter to the given Java long value. The driver converts this to an SQL BIGINT value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
l - the parameter value

setLong

public void setLong(int p,
                    Long l)
Sets the designated parameter to the given Java Long value. The driver converts this to an SQL BIGINT value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
l - the parameter value, null if the value should be set to SQL NULL

setFloat

public void setFloat(int p,
                     float f)
Sets the designated parameter to the given Java float value. The driver converts this to an SQL REAL value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
f - the parameter value

setFloat

public void setFloat(int p,
                     Float f)
Sets the designated parameter to the given Java Float value. The driver converts this to an SQL REAL value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
f - the parameter value, null if the value should be set to SQL NULL

setDouble

public void setDouble(int p,
                      double d)
Sets the designated parameter to the given Java double value. The driver converts this to an SQL DOUBLE value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
d - the parameter value

setDouble

public void setDouble(int p,
                      Double d)
Sets the designated parameter to the given Java Double value. The driver converts this to an SQL DOUBLE value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
d - the parameter value, null if the value should be set to SQL NULL

setBigDecimal

public void setBigDecimal(int p,
                          BigDecimal d)
Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to an SQL NUMERIC value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
d - the parameter value, null if the value should be set to SQL NULL

setBMoney

public void setBMoney(int p,
                      BMoney m)
Sets the designated parameter to a BMoney value.
A BMoney will not be stored as a single field but as two fields:
  1. a double representing the value
  2. an int representing the scale
This is due to most DBMS can't store arbitrary scaled decimals in a single column, i.e. all values in the column must have the same scale.

Parameters:
p - the sql position
m - the money value, null to set SQL NULL
See Also:
setDMoney(int, org.tentackle.util.DMoney)

setDMoney

public void setDMoney(int p,
                      DMoney m)
Sets the designated parameter to a DMoney value.
A DMoney will not be stored as a single field but as two fields:
  1. a BigDecimal with a scale of 0 representing the value
  2. an int representing the scale
This is due to most DBMS can't store arbitrary scaled decimals in a single column, i.e. all values in the column must have the same scale.

Parameters:
p - the sql position
m - the money value, null to set SQL NULL
See Also:
setBMoney(int, org.tentackle.util.BMoney)

setDate

public void setDate(int p,
                    Date d,
                    boolean mapNull)
Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application. The driver converts this to an SQL DATE value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
d - the parameter value
mapNull - to map null values to 1.1.1970 (epochal time zero), else SQL NULL

setDate

public void setDate(int p,
                    Date d)
Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application. The driver converts this to an SQL DATE value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
d - the parameter value, null if the value should be set to SQL NULL

setTimestamp

public void setTimestamp(int p,
                         Timestamp ts,
                         boolean mapNull)
Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an SQL TIMESTAMP value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
ts - the parameter value
mapNull - to map null values to 1.1.1970 00:00:00.000 (epochal time zero), else SQL NULL

setTimestamp

public void setTimestamp(int p,
                         Timestamp ts)
Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an SQL TIMESTAMP value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
ts - the parameter value, null if the value should be set to SQL NULL

setTime

public void setTime(int p,
                    Time t)
Sets the designated parameter to the given java.sql.Time value. The driver converts this to an SQL TIME value when it sends it to the database.

Parameters:
p - the first parameter is 1, the second is 2, ...
t - the parameter value, null if the value should be set to SQL NULL

setBinary

public void setBinary(int p,
                      Binary b)
Sets the designated parameter to the given Binary value. will The driver converts this to an SQL BLOB value when it sends it to the database. The implementation translates the Binary into an Inputstream and invokes PreparedStatement.setBinaryStream(int, java.io.InputStream, int).

Parameters:
p - the first parameter is 1, the second is 2, ...
b - the parameter value, null if the value should be set to SQL NULL


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de