org.objectweb.telosys.dal.dao
Class QueryContext

java.lang.Object
  extended byorg.objectweb.telosys.common.TelosysObject
      extended byorg.objectweb.telosys.dal.dao.QueryContext

public class QueryContext
extends TelosysObject

The context of a query ( contains the PreparedStatement and the ResultSet of the query )
This is an internal framework class, designed to be used by the StandardDAO and all its descendents


Field Summary
static boolean RETURN_GENERATED_KEYS
           
 
Constructor Summary
QueryContext(java.sql.Connection con, java.lang.String sSql)
          Constructs a new query context for the given SQL request
( get a PreparedStatement )
QueryContext(java.sql.Connection con, java.lang.String sSql, boolean bReturnGeneratedKeys)
          Constructs a new query context for the given SQL request
( get a PreparedStatement )
 
Method Summary
protected  void close()
          Close the PreparedStatement AND the ResultSet
Doesn't throw Exception (just trace the error)
protected  java.lang.Long executeInsertKeyGen()
          Executes an INSERT with KEY GENERATION ( Autoincrement Key )
protected  java.sql.ResultSet executeQuery()
          Call the "executeQuery" method of the current PreparedStatement
protected  int executeUpdate()
          Call the "executeUpdate" method of the current PreparedStatement
 java.math.BigDecimal getResultBigDecimal(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.sql.Blob getResultBlob(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 byte[] getResultBlobAsByteArray(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 boolean getResultBoolean(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 boolean getResultBooleanFromInt(int iPosition, int iTrueValue)
          Returns the value of the designated column in the current row of the ResultSet
For a boolean stored as an integer value in the table
 boolean getResultBooleanFromString(int iPosition, java.lang.String sTrueValue)
          Returns the value of the designated column in the current row of the ResultSet
For a boolean stored as an String value in the table
 java.lang.Boolean getResultBooleanObject(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 byte getResultByte(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.lang.Byte getResultByteObject(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 byte[] getResultBytes(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.sql.Clob getResultClob(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.util.Date getResultDate(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
Returns a java.util.Date instance created with the java.sql.Date returned by the ResultSet
 java.sql.Date getResultDateSql(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
Returns the java.sql.Date returned by the ResultSet
 double getResultDouble(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.lang.Double getResultDoubleObject(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 float getResultFloat(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.lang.Float getResultFloatObject(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 int getResultInt(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.lang.Integer getResultIntObject(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 long getResultLong(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.lang.Long getResultLongObject(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 short getResultShort(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.lang.Short getResultShortObject(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.lang.String getResultString(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.sql.Time getResultTime(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.util.Date getResultTimeAsDate(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
For a TIME value in the table, returned as java.util.Date
 java.sql.Timestamp getResultTimestamp(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
 java.util.Date getResultTimestampAsDate(int iPosition)
          Returns the value of the designated column in the current row of the ResultSet
For a TIMESTAMP value in the table, returned as java.util.Date
protected  boolean nextResult()
          Moves the cursor down one row from its current position in the ResultSet
Calls the "next" method of the current ResultSet
 void setParamBigDecimal(int i, java.math.BigDecimal value)
          Set a parameter in the PreparedStatement
 void setParamBlob(int i, java.sql.Blob param)
          Set a parameter in the PreparedStatement
 void setParamBlob(int i, byte[] bytes)
          Set a parameter in the PreparedStatement
 void setParamBoolean(int i, boolean bValue)
          Set a parameter in the PreparedStatement
 void setParamBoolean(int i, java.lang.Boolean obj)
          Set a parameter in the PreparedStatement
 void setParamBooleanAsInt(int i, boolean bValue, int iTrueValue, int iFalseValue)
          Set a parameter in the PreparedStatement
For a boolean stored as an integer value in the table
 void setParamBooleanAsString(int i, boolean bValue, java.lang.String sTrueValue, java.lang.String sFalseValue)
          Set a parameter in the PreparedStatement
For a boolean stored as an String value in the table
 void setParamByte(int i, byte value)
          Set a parameter in the PreparedStatement
 void setParamByte(int i, java.lang.Byte obj)
          Set a parameter in the PreparedStatement
 void setParamBytes(int i, byte[] bytes)
          Set a parameter in the PreparedStatement
 void setParamClob(int i, java.sql.Clob param)
          Set a parameter in the PreparedStatement
 void setParamDate(int i, java.util.Date dateValue)
          Set a parameter in the PreparedStatement
Converts the given java.util.Date to java.sql.Date and set it as Date parameter
 void setParamDouble(int i, double dValue)
          Set a parameter in the PreparedStatement
 void setParamDouble(int i, java.lang.Double obj)
          Set a parameter in the PreparedStatement
 void setParamFloat(int i, float fValue)
          Set a parameter in the PreparedStatement
 void setParamFloat(int i, java.lang.Float obj)
          Set a parameter in the PreparedStatement
 void setParamInt(int i, int iValue)
          Set a parameter in the PreparedStatement
 void setParamInt(int i, java.lang.Integer obj)
          Set a parameter in the PreparedStatement
 void setParamLong(int i, long value)
          Set a parameter in the PreparedStatement
 void setParamLong(int i, java.lang.Long obj)
          Set a parameter in the PreparedStatement
 void setParamShort(int i, short value)
          Set a parameter in the PreparedStatement
 void setParamShort(int i, java.lang.Short obj)
          Set a parameter in the PreparedStatement
 void setParamString(int i, java.lang.String sValue)
          Set a parameter in the PreparedStatement
 void setParamTime(int i, java.util.Date dateValue)
          Set a parameter in the PreparedStatement
Converts the given java.util.Date to java.sql.Time and set it as Time parameter
 void setParamTime(int i, java.sql.Time time)
          Set a parameter in the PreparedStatement
 void setParamTimestamp(int i, java.util.Date dateValue)
          Set a parameter in the PreparedStatement
Converts the given java.util.Date to java.sql.Timestamp and set it as Timestamp parameter
 void setParamTimestamp(int i, java.sql.Timestamp timestamp)
          Set a parameter in the PreparedStatement
 
Methods inherited from class org.objectweb.telosys.common.TelosysObject
error, error, error, getFlagTrace, info, setFlagTrace, trace, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RETURN_GENERATED_KEYS

public static final boolean RETURN_GENERATED_KEYS
See Also:
Constant Field Values
Constructor Detail

QueryContext

public QueryContext(java.sql.Connection con,
                    java.lang.String sSql)
             throws java.sql.SQLException
Constructs a new query context for the given SQL request
( get a PreparedStatement )

Parameters:
con -
sSql -
Throws:
java.sql.SQLException

QueryContext

public QueryContext(java.sql.Connection con,
                    java.lang.String sSql,
                    boolean bReturnGeneratedKeys)
             throws java.sql.SQLException
Constructs a new query context for the given SQL request
( get a PreparedStatement )

Parameters:
con -
sSql -
bReturnGeneratedKeys - use RETURN_GENERATED_KEYS to return the generate key (useful for insertKeyGen)
Throws:
java.sql.SQLException
Method Detail

executeUpdate

protected int executeUpdate()
                     throws java.sql.SQLException
Call the "executeUpdate" method of the current PreparedStatement

Returns:
Throws:
java.sql.SQLException

executeQuery

protected java.sql.ResultSet executeQuery()
                                   throws java.sql.SQLException
Call the "executeQuery" method of the current PreparedStatement

Returns:
Throws:
java.sql.SQLException

executeInsertKeyGen

protected java.lang.Long executeInsertKeyGen()
                                      throws java.sql.SQLException
Executes an INSERT with KEY GENERATION ( Autoincrement Key )

Returns:
Throws:
java.sql.SQLException

close

protected void close()
Close the PreparedStatement AND the ResultSet
Doesn't throw Exception (just trace the error)


setParamInt

public void setParamInt(int i,
                        int iValue)
                 throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
iValue -
Throws:
TelosysException

setParamInt

public void setParamInt(int i,
                        java.lang.Integer obj)
                 throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
obj -
Throws:
TelosysException

setParamByte

public void setParamByte(int i,
                         byte value)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
value -
Throws:
TelosysException

setParamByte

public void setParamByte(int i,
                         java.lang.Byte obj)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
obj -
Throws:
TelosysException

setParamShort

public void setParamShort(int i,
                          short value)
                   throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
value -
Throws:
TelosysException

setParamShort

public void setParamShort(int i,
                          java.lang.Short obj)
                   throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
obj -
Throws:
TelosysException

setParamLong

public void setParamLong(int i,
                         long value)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
value -
Throws:
TelosysException

setParamLong

public void setParamLong(int i,
                         java.lang.Long obj)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
obj -
Throws:
TelosysException

setParamFloat

public void setParamFloat(int i,
                          float fValue)
                   throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
fValue -
Throws:
TelosysException

setParamFloat

public void setParamFloat(int i,
                          java.lang.Float obj)
                   throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
obj -
Throws:
TelosysException

setParamDouble

public void setParamDouble(int i,
                           double dValue)
                    throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
dValue -
Throws:
TelosysException

setParamDouble

public void setParamDouble(int i,
                           java.lang.Double obj)
                    throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
obj -
Throws:
TelosysException

setParamBigDecimal

public void setParamBigDecimal(int i,
                               java.math.BigDecimal value)
                        throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
value -
Throws:
TelosysException

setParamString

public void setParamString(int i,
                           java.lang.String sValue)
                    throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
sValue -
Throws:
TelosysException

setParamDate

public void setParamDate(int i,
                         java.util.Date dateValue)
                  throws TelosysException
Set a parameter in the PreparedStatement
Converts the given java.util.Date to java.sql.Date and set it as Date parameter

Parameters:
i -
dateValue -
Throws:
TelosysException

setParamTimestamp

public void setParamTimestamp(int i,
                              java.util.Date dateValue)
                       throws TelosysException
Set a parameter in the PreparedStatement
Converts the given java.util.Date to java.sql.Timestamp and set it as Timestamp parameter

Parameters:
i -
dateValue -
Throws:
TelosysException

setParamTimestamp

public void setParamTimestamp(int i,
                              java.sql.Timestamp timestamp)
                       throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
timestamp -
Throws:
TelosysException

setParamTime

public void setParamTime(int i,
                         java.util.Date dateValue)
                  throws TelosysException
Set a parameter in the PreparedStatement
Converts the given java.util.Date to java.sql.Time and set it as Time parameter

Parameters:
i -
dateValue -
Throws:
TelosysException

setParamTime

public void setParamTime(int i,
                         java.sql.Time time)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
time -
Throws:
TelosysException

setParamBytes

public void setParamBytes(int i,
                          byte[] bytes)
                   throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
bytes -
Throws:
TelosysException

setParamBoolean

public void setParamBoolean(int i,
                            boolean bValue)
                     throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
bValue -
Throws:
TelosysException

setParamBoolean

public void setParamBoolean(int i,
                            java.lang.Boolean obj)
                     throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
obj -
Throws:
TelosysException

setParamBooleanAsString

public void setParamBooleanAsString(int i,
                                    boolean bValue,
                                    java.lang.String sTrueValue,
                                    java.lang.String sFalseValue)
                             throws TelosysException
Set a parameter in the PreparedStatement
For a boolean stored as an String value in the table

Parameters:
i -
bValue - the boolean value
sTrueValue - the String value to use if the boolean is TRUE ( e.g. "1" or "T" )
sFalseValue - the String value to use if the boolean is FALSE ( e.g. "0" or "F" )
Throws:
TelosysException

setParamBooleanAsInt

public void setParamBooleanAsInt(int i,
                                 boolean bValue,
                                 int iTrueValue,
                                 int iFalseValue)
                          throws TelosysException
Set a parameter in the PreparedStatement
For a boolean stored as an integer value in the table

Parameters:
i -
bValue - the boolean value
iTrueValue - the integer value to use if the boolean is TRUE ( e.g. 1 )
iFalseValue - the integer value to use if the boolean is FALSE ( e.g. 0 )
Throws:
TelosysException

setParamClob

public void setParamClob(int i,
                         java.sql.Clob param)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
param - the CLOB object
Throws:
TelosysException

setParamBlob

public void setParamBlob(int i,
                         byte[] bytes)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
bytes - the BLOB content (binary : array of bytes)
Throws:
TelosysException

setParamBlob

public void setParamBlob(int i,
                         java.sql.Blob param)
                  throws TelosysException
Set a parameter in the PreparedStatement

Parameters:
i -
param - the BLOB object
Throws:
TelosysException

getResultString

public java.lang.String getResultString(int iPosition)
                                 throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultInt

public int getResultInt(int iPosition)
                 throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultIntObject

public java.lang.Integer getResultIntObject(int iPosition)
                                     throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultByte

public byte getResultByte(int iPosition)
                   throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultByteObject

public java.lang.Byte getResultByteObject(int iPosition)
                                   throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultShort

public short getResultShort(int iPosition)
                     throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultShortObject

public java.lang.Short getResultShortObject(int iPosition)
                                     throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultLong

public long getResultLong(int iPosition)
                   throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultLongObject

public java.lang.Long getResultLongObject(int iPosition)
                                   throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultFloat

public float getResultFloat(int iPosition)
                     throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultFloatObject

public java.lang.Float getResultFloatObject(int iPosition)
                                     throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultDouble

public double getResultDouble(int iPosition)
                       throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultDoubleObject

public java.lang.Double getResultDoubleObject(int iPosition)
                                       throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultBigDecimal

public java.math.BigDecimal getResultBigDecimal(int iPosition)
                                         throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultDate

public java.util.Date getResultDate(int iPosition)
                             throws TelosysException
Returns the value of the designated column in the current row of the ResultSet
Returns a java.util.Date instance created with the java.sql.Date returned by the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultDateSql

public java.sql.Date getResultDateSql(int iPosition)
                               throws TelosysException
Returns the value of the designated column in the current row of the ResultSet
Returns the java.sql.Date returned by the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultTime

public java.sql.Time getResultTime(int iPosition)
                            throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultTimeAsDate

public java.util.Date getResultTimeAsDate(int iPosition)
                                   throws TelosysException
Returns the value of the designated column in the current row of the ResultSet
For a TIME value in the table, returned as java.util.Date

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultTimestamp

public java.sql.Timestamp getResultTimestamp(int iPosition)
                                      throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultTimestampAsDate

public java.util.Date getResultTimestampAsDate(int iPosition)
                                        throws TelosysException
Returns the value of the designated column in the current row of the ResultSet
For a TIMESTAMP value in the table, returned as java.util.Date

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultBytes

public byte[] getResultBytes(int iPosition)
                      throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultBoolean

public boolean getResultBoolean(int iPosition)
                         throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultBooleanObject

public java.lang.Boolean getResultBooleanObject(int iPosition)
                                         throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultBooleanFromInt

public boolean getResultBooleanFromInt(int iPosition,
                                       int iTrueValue)
                                throws TelosysException
Returns the value of the designated column in the current row of the ResultSet
For a boolean stored as an integer value in the table

Parameters:
iPosition -
iTrueValue - the integer value thar means "TRUE" ( e.g. 1 )
Returns:
true if the ResultSet value equals the iTrueValue parameter, else false
Throws:
TelosysException

getResultBooleanFromString

public boolean getResultBooleanFromString(int iPosition,
                                          java.lang.String sTrueValue)
                                   throws TelosysException
Returns the value of the designated column in the current row of the ResultSet
For a boolean stored as an String value in the table

Parameters:
iPosition -
sTrueValue - the String value thar means "TRUE" ( e.g. "1" or "T" or "true" )
Returns:
true if the ResultSet value equals the sTrueValue parameter, else false
Throws:
TelosysException

getResultClob

public java.sql.Clob getResultClob(int iPosition)
                            throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

getResultBlobAsByteArray

public byte[] getResultBlobAsByteArray(int iPosition)
                                throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
the binary content of the BLOB ( can be null )
Throws:
TelosysException

getResultBlob

public java.sql.Blob getResultBlob(int iPosition)
                            throws TelosysException
Returns the value of the designated column in the current row of the ResultSet

Parameters:
iPosition -
Returns:
Throws:
TelosysException

nextResult

protected boolean nextResult()
                      throws TelosysException
Moves the cursor down one row from its current position in the ResultSet
Calls the "next" method of the current ResultSet

Returns:
Throws:
TelosysException