com.healthmarketscience.sqlbuilder
Class QueryPreparer.PlaceHolder

java.lang.Object
  extended by com.healthmarketscience.common.util.AppendeeObject
      extended by com.healthmarketscience.sqlbuilder.SqlObject
          extended by com.healthmarketscience.sqlbuilder.QueryPreparer.PlaceHolder
All Implemented Interfaces:
Appendee
Direct Known Subclasses:
QueryPreparer.MultiPlaceHolder, QueryPreparer.StaticPlaceHolder
Enclosing class:
QueryPreparer

public static class QueryPreparer.PlaceHolder
extends SqlObject

A SqlObject which outputs a '?', and records the current index at the time the appendTo method is called. This enables the user to set parameters correctly in a PreparedStatement where the position is not known at query creation time. Note: a PlaceHolder may not be used in more than one place in the query. For this functionality, use QueryPreparer.MultiPlaceHolder.


Field Summary
 
Fields inherited from class com.healthmarketscience.sqlbuilder.SqlObject
ALL_SYMBOL, NULL_VALUE, QUESTION_MARK
 
Constructor Summary
QueryPreparer.PlaceHolder(QueryPreparer outer)
           
 
Method Summary
protected  void addIndex(int index)
           
 void appendTo(AppendableExt app)
           
protected  void collectSchemaObjects(ValidationContext vContext)
          Used during Query.validate() calls to collect the dbschema objects referenced in a query.
 int getIndex()
          Returns the 1-based index of this PlaceHolder in the query.
 List<Integer> getIndexes()
           
 boolean isInQuery()
          Returns true if this PlaceHolder was used in the query, false otherwise.
 void setBoolean(boolean value, PreparedStatement ps)
          Calls setBoolean on the given PreparedStatement with the given value for the position of this PlaceHolder.
 void setBoolean(Boolean value, PreparedStatement ps)
          Calls setBoolean on the given PreparedStatement with the given value for the position of this PlaceHolder.
 void setInt(Integer value, PreparedStatement ps)
          Calls setInt on the given PreparedStatement with the given value for the position of this PlaceHolder.
 void setInt(int value, PreparedStatement ps)
          Calls setInt on the given PreparedStatement with the given value for the position of this PlaceHolder.
 void setLong(long value, PreparedStatement ps)
          Calls setLong on the given PreparedStatement with the given value for the position of this PlaceHolder.
 void setLong(Long value, PreparedStatement ps)
          Calls setLong on the given PreparedStatement with the given value for the position of this PlaceHolder.
protected  void setNonNullObject(Object value, int sqlType, PreparedStatement ps)
          Calls setObject on the given PreparedStatement with the given value and the given sql type for the position of this PlaceHolder.
protected  void setNonNullString(String value, PreparedStatement ps)
          Calls setString on the given PreparedStatement with the given value for the position of this PlaceHolder.
 void setNull(int sqlType, PreparedStatement ps)
          Calls setNull on the given PreparedStatement with the given sql type for the position of this PlaceHolder.
 void setObject(Object value, int sqlType, PreparedStatement ps)
          Calls setObject on the given PreparedStatement with the given value and the given sql type for the position of this PlaceHolder.
 void setObject(Object value, PreparedStatement ps)
          Calls setObject on the given PreparedStatement with the given value for the position of this PlaceHolder.
 void setString(String value, PreparedStatement ps)
          Calls setString on the given PreparedStatement with the given value for the position of this PlaceHolder.
 
Methods inherited from class com.healthmarketscience.sqlbuilder.SqlObject
doValidate, toString
 
Methods inherited from class com.healthmarketscience.common.util.AppendeeObject
toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryPreparer.PlaceHolder

public QueryPreparer.PlaceHolder(QueryPreparer outer)
Method Detail

isInQuery

public boolean isInQuery()
Returns true if this PlaceHolder was used in the query, false otherwise.


getIndex

public int getIndex()
Returns the 1-based index of this PlaceHolder in the query.

Returns:
1-based index of this PlaceHolder if the query has been generated, otherwise

getIndexes

public List<Integer> getIndexes()

addIndex

protected void addIndex(int index)

setNull

public void setNull(int sqlType,
                    PreparedStatement ps)
             throws SQLException
Calls setNull on the given PreparedStatement with the given sql type for the position of this PlaceHolder.

Throws:
SQLException

setInt

public void setInt(int value,
                   PreparedStatement ps)
            throws SQLException
Calls setInt on the given PreparedStatement with the given value for the position of this PlaceHolder.

Throws:
SQLException

setInt

public void setInt(Integer value,
                   PreparedStatement ps)
            throws SQLException
Calls setInt on the given PreparedStatement with the given value for the position of this PlaceHolder. If given value is null, calls setNull with the sql type INTEGER.

Throws:
SQLException

setLong

public void setLong(long value,
                    PreparedStatement ps)
             throws SQLException
Calls setLong on the given PreparedStatement with the given value for the position of this PlaceHolder.

Throws:
SQLException

setLong

public void setLong(Long value,
                    PreparedStatement ps)
             throws SQLException
Calls setLong on the given PreparedStatement with the given value for the position of this PlaceHolder. If given value is null, calls setNull with the sql type BIGINT.

Throws:
SQLException

setBoolean

public void setBoolean(boolean value,
                       PreparedStatement ps)
                throws SQLException
Calls setBoolean on the given PreparedStatement with the given value for the position of this PlaceHolder.

Throws:
SQLException

setBoolean

public void setBoolean(Boolean value,
                       PreparedStatement ps)
                throws SQLException
Calls setBoolean on the given PreparedStatement with the given value for the position of this PlaceHolder. If given value is null, calls setNull with the sql type BOOLEAN.

Throws:
SQLException

setNonNullString

protected void setNonNullString(String value,
                                PreparedStatement ps)
                         throws SQLException
Calls setString on the given PreparedStatement with the given value for the position of this PlaceHolder.

Throws:
SQLException

setString

public void setString(String value,
                      PreparedStatement ps)
               throws SQLException
Calls setString on the given PreparedStatement with the given value for the position of this PlaceHolder.

Throws:
SQLException

setObject

public void setObject(Object value,
                      PreparedStatement ps)
               throws SQLException
Calls setObject on the given PreparedStatement with the given value for the position of this PlaceHolder. Note, calling this method with a null value may or may not work, depending on the JDBC driver. The only reliable (across all JDBC drivers) way to set a null object is to call setObject(Object,int,PreparedStatement) with the correct SQL type.

Throws:
SQLException

setNonNullObject

protected void setNonNullObject(Object value,
                                int sqlType,
                                PreparedStatement ps)
                         throws SQLException
Calls setObject on the given PreparedStatement with the given value and the given sql type for the position of this PlaceHolder.

Throws:
SQLException

setObject

public void setObject(Object value,
                      int sqlType,
                      PreparedStatement ps)
               throws SQLException
Calls setObject on the given PreparedStatement with the given value and the given sql type for the position of this PlaceHolder.

Throws:
SQLException

collectSchemaObjects

protected void collectSchemaObjects(ValidationContext vContext)
Description copied from class: SqlObject
Used during Query.validate() calls to collect the dbschema objects referenced in a query. Any subclass of this class should add all referenced tables and columns to the appropriate collections.

Specified by:
collectSchemaObjects in class SqlObject
Parameters:
vContext - handle to the current validation context

appendTo

public final void appendTo(AppendableExt app)
                    throws IOException
Specified by:
appendTo in interface Appendee
Overrides:
appendTo in class AppendeeObject
Throws:
IOException


Copyright © 2006-2008 Health Market Science. All Rights Reserved.