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.public abstract class StatementBuilder<T,ID> extends Object
Modifier and Type | Class and Description |
---|---|
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.
|
protected static class |
StatementBuilder.WhereOperation
Enum which defines which type of where operation we are appending.
|
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
StatementBuilder(DatabaseType databaseType,
TableInfo<T,ID> tableInfo,
Dao<T,ID> dao,
StatementBuilder.StatementType type) |
Modifier and Type | Method and Description |
---|---|
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 boolean |
appendWhereStatement(StringBuilder sb,
List<ArgumentHolder> argList,
StatementBuilder.WhereOperation operation)
Append the WHERE part of the statement to the StringBuilder.
|
protected String |
buildStatementString(List<ArgumentHolder> argList) |
protected FieldType[] |
getResultFieldTypes()
Get the result array from our statement after the
appendStatementStart(StringBuilder, List) was called. |
protected String |
getTableName() |
protected MappedPreparedStmt<T,ID> |
prepareStatement(Long limit,
boolean cacheStore)
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 |
reset()
Clear out all of the statement settings so we can reuse the builder.
|
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()
Creates and returns a new
Where object for this QueryBulder that can be used to add WHERE clauses to the
SQL statement. |
protected final String tableName
protected final DatabaseType databaseType
protected StatementBuilder.StatementType type
protected boolean addTableName
public StatementBuilder(DatabaseType databaseType, TableInfo<T,ID> tableInfo, Dao<T,ID> dao, StatementBuilder.StatementType type)
public Where<T,ID> where()
Where
object for this QueryBulder that can be used to add WHERE clauses to the
SQL statement. Only one Where
object can be associated with a QueryBuilder at a time and calling this
method again creates a new Where
object and resets the where information for this QueryBuilder.public void setWhere(Where<T,ID> where)
Where
object on the query. This allows someone to use the same Where object on multiple queries.protected MappedPreparedStmt<T,ID> prepareStatement(Long limit, boolean cacheStore) throws SQLException
limit
- Limit for queries. Can be null if none.SQLException
public String prepareStatementString() throws SQLException
SQLException
public StatementBuilder.StatementInfo prepareStatementInfo() throws SQLException
StatementBuilder.StatementInfo
for more details.SQLException
public void reset()
protected String buildStatementString(List<ArgumentHolder> argList) throws SQLException
SQLException
protected void appendStatementString(StringBuilder sb, List<ArgumentHolder> argList) throws SQLException
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).
SQLException
protected abstract void appendStatementStart(StringBuilder sb, List<ArgumentHolder> argList) throws SQLException
SQLException
protected boolean appendWhereStatement(StringBuilder sb, List<ArgumentHolder> argList, StatementBuilder.WhereOperation operation) throws SQLException
SQLException
protected abstract void appendStatementEnd(StringBuilder sb, List<ArgumentHolder> argList) throws SQLException
SQLException
protected boolean shouldPrependTableNameToColumns()
protected FieldType[] getResultFieldTypes()
appendStatementStart(StringBuilder, List)
was called.
This will be null except for the QueryBuilder.protected FieldType verifyColumnName(String columnName)
IllegalArgumentException
- if the column name is not valid.protected String getTableName()
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.