com.j256.ormlite.stmt
Class StatementBuilder<T,ID>

java.lang.Object
  extended by com.j256.ormlite.stmt.StatementBuilder<T,ID>
Type Parameters:
T - The class that the code will be operating on.
ID - The class of the ID column associated with the class. The T class does not require an ID field. The class needs an ID parameter however so you can use Void or Object to satisfy the compiler.
Direct Known Subclasses:
DeleteBuilder, QueryBuilder, UpdateBuilder

public abstract class StatementBuilder<T,ID>
extends Object

Assists in building of SQL statements for a particular table in a particular database.

Author:
graywatson

Nested Class Summary
static class StatementBuilder.StatementInfo
          Class which wraps information about a statement including the arguments and the generated SQL statement string.
static class StatementBuilder.StatementType
          Types of statements that we are building.
 
Field Summary
protected  boolean addTableName
           
protected  Dao<T,ID> dao
           
protected  DatabaseType databaseType
           
protected  TableInfo<T,ID> tableInfo
           
protected  String tableName
           
protected  StatementBuilder.StatementType type
           
protected  Where<T,ID> where
           
 
Constructor Summary
StatementBuilder(DatabaseType databaseType, TableInfo<T,ID> tableInfo, Dao<T,ID> dao, StatementBuilder.StatementType type)
           
 
Method Summary
protected abstract  void appendStatementEnd(StringBuilder sb, List<ArgumentHolder> argList)
          Append the end of our statement string to the StringBuilder.
protected abstract  void appendStatementStart(StringBuilder sb, List<ArgumentHolder> argList)
          Append the start of our statement string to the StringBuilder.
protected  void appendStatementString(StringBuilder sb, List<ArgumentHolder> argList)
          Internal method to build a query while tracking various arguments.
protected  void appendWhereStatement(StringBuilder sb, List<ArgumentHolder> argList, boolean first)
          Append the WHERE part of the statement to the StringBuilder.
protected  String buildStatementString(List<ArgumentHolder> argList)
           
 void clear()
          Clear out all of the statement settings so we can reuse the builder.
protected  FieldType[] getResultFieldTypes()
          Get the result array from our statement after the appendStatementStart(StringBuilder, List) was called.
protected  MappedPreparedStmt<T,ID> prepareStatement(Long limit)
          Prepare our statement for the subclasses.
 StatementBuilder.StatementInfo prepareStatementInfo()
          Build and return all of the information about the prepared statement.
 String prepareStatementString()
          Build and return a string version of the query.
 void setWhere(Where<T,ID> where)
          Set the Where object on the query.
protected  boolean shouldPrependTableNameToColumns()
          Return true if we need to prepend table-name to columns.
protected  FieldType verifyColumnName(String columnName)
          Verify the columnName is valid and return its FieldType.
 Where<T,ID> where()
          Returns a Where object that should be used to add SQL where clauses to the statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableInfo

protected final TableInfo<T,ID> tableInfo

tableName

protected final String tableName

databaseType

protected final DatabaseType databaseType

dao

protected final Dao<T,ID> dao

type

protected StatementBuilder.StatementType type

addTableName

protected boolean addTableName

where

protected Where<T,ID> where
Constructor Detail

StatementBuilder

public StatementBuilder(DatabaseType databaseType,
                        TableInfo<T,ID> tableInfo,
                        Dao<T,ID> dao,
                        StatementBuilder.StatementType type)
Method Detail

where

public Where<T,ID> where()
Returns a Where object that should be used to add SQL where clauses to the statement. This will also reset the where object so you can use the same query builder with a different where statement.


setWhere

public void setWhere(Where<T,ID> where)
Set the Where object on the query. This allows someone to use the same Where object on multiple queries.


prepareStatement

protected MappedPreparedStmt<T,ID> prepareStatement(Long limit)
                                             throws SQLException
Prepare our statement for the subclasses.

Parameters:
limit - Limit for queries. Can be null if none.
Throws:
SQLException

prepareStatementString

public String prepareStatementString()
                              throws SQLException
Build and return a string version of the query. If you change the where or make other calls you will need to re-call this method to re-prepare the query for execution.

Throws:
SQLException

prepareStatementInfo

public StatementBuilder.StatementInfo prepareStatementInfo()
                                                    throws SQLException
Build and return all of the information about the prepared statement. See StatementBuilder.StatementInfo for more details.

Throws:
SQLException

clear

public void clear()
Clear out all of the statement settings so we can reuse the builder.


buildStatementString

protected String buildStatementString(List<ArgumentHolder> argList)
                               throws SQLException
Throws:
SQLException

appendStatementString

protected void appendStatementString(StringBuilder sb,
                                     List<ArgumentHolder> argList)
                              throws SQLException
Internal method to build a query while tracking various arguments. Users should use the prepareStatementString() method instead.

This needs to be protected because of (WARNING: DO NOT MAKE A JAVADOC LINK) InternalQueryBuilder (WARNING: DO NOT MAKE A JAVADOC LINK).

Throws:
SQLException

appendStatementStart

protected abstract void appendStatementStart(StringBuilder sb,
                                             List<ArgumentHolder> argList)
                                      throws SQLException
Append the start of our statement string to the StringBuilder.

Throws:
SQLException

appendWhereStatement

protected void appendWhereStatement(StringBuilder sb,
                                    List<ArgumentHolder> argList,
                                    boolean first)
                             throws SQLException
Append the WHERE part of the statement to the StringBuilder.

Throws:
SQLException

appendStatementEnd

protected abstract void appendStatementEnd(StringBuilder sb,
                                           List<ArgumentHolder> argList)
                                    throws SQLException
Append the end of our statement string to the StringBuilder.

Throws:
SQLException

shouldPrependTableNameToColumns

protected boolean shouldPrependTableNameToColumns()
Return true if we need to prepend table-name to columns.


getResultFieldTypes

protected FieldType[] getResultFieldTypes()
Get the result array from our statement after the appendStatementStart(StringBuilder, List) was called. This will be null except for the QueryBuilder.


verifyColumnName

protected FieldType verifyColumnName(String columnName)
Verify the columnName is valid and return its FieldType.

Throws:
IllegalArgumentException - if the column name is not valid.


This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.