|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.j256.ormlite.stmt.StatementBuilder<T,ID>
com.j256.ormlite.stmt.QueryBuilder<T,ID>
public class QueryBuilder<T,ID>
Assists in building sql query (SELECT) statements for a particular table in a particular database.
Here is a good tutorial of SQL commands.
Nested Class Summary | |
---|---|
static class |
QueryBuilder.InternalQueryBuilderWrapper
Internal class used to expose methods to internal classes but through a wrapper instead of a builder. |
Nested classes/interfaces inherited from class com.j256.ormlite.stmt.StatementBuilder |
---|
StatementBuilder.StatementType |
Field Summary |
---|
Fields inherited from class com.j256.ormlite.stmt.StatementBuilder |
---|
databaseType, limit, offset, tableInfo |
Constructor Summary | |
---|---|
QueryBuilder(DatabaseType databaseType,
TableInfo<T,ID> tableInfo,
Dao<T,ID> dao)
|
Method Summary | |
---|---|
protected void |
appendStatementEnd(StringBuilder sb)
Append the end of our statement string to the StringBuilder. |
protected void |
appendStatementStart(StringBuilder sb,
List<ArgumentHolder> argList)
Append the start of our statement string to the StringBuilder. |
QueryBuilder<T,ID> |
distinct()
Add "DISTINCT" clause to the SQL query statement. |
protected FieldType[] |
getResultFieldTypes()
Get the result array from our statement after the StatementBuilder.appendStatementStart(StringBuilder, List) was called. |
QueryBuilder<T,ID> |
groupBy(String columnName)
Add "GROUP BY" clause to the SQL query statement. |
QueryBuilder<T,ID> |
groupByRaw(String rawSql)
Add a raw SQL "GROUP BY" clause to the SQL query statement. |
CloseableIterator<T> |
iterator()
A short cut for Dao.iterator(prepare()). |
QueryBuilder<T,ID> |
limit(Integer maxRows)
Limit the output to maxRows maximum number of rows. |
QueryBuilder<T,ID> |
offset(Integer startRow)
Start the output at this row number. |
QueryBuilder<T,ID> |
orderBy(String columnName,
boolean ascending)
Add "ORDER BY" clause to the SQL query statement. |
QueryBuilder<T,ID> |
orderByRaw(String rawSql)
Add raw SQL "ORDER BY" clause to the SQL query statement. |
PreparedQuery<T> |
prepare()
Build and return a prepared query that can be used by Dao.query(PreparedQuery) or
Dao.iterator(PreparedQuery) methods. |
List<T> |
query()
A short cut for Dao.query(prepare()). |
QueryBuilder<T,ID> |
selectColumns(Iterable<String> columns)
Add columns to be returned by the SELECT query. |
QueryBuilder<T,ID> |
selectColumns(String... columns)
Add columns to be returned by the SELECT query. |
Methods inherited from class com.j256.ormlite.stmt.StatementBuilder |
---|
appendStatementString, prepareStatement, prepareStatementString, setWhere, verifyColumnName, where |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public QueryBuilder(DatabaseType databaseType, TableInfo<T,ID> tableInfo, Dao<T,ID> dao)
Method Detail |
---|
public PreparedQuery<T> prepare() throws SQLException
Dao.query(PreparedQuery)
or
Dao.iterator(PreparedQuery)
methods. If you change the where or make other calls you will need to re-call
this method to re-prepare the statement for execution.
SQLException
public QueryBuilder<T,ID> selectColumns(String... columns)
public QueryBuilder<T,ID> selectColumns(Iterable<String> columns)
public QueryBuilder<T,ID> groupBy(String columnName)
NOTE: Use of this means that the resulting objects may not have a valid ID column value so cannot be deleted or updated.
public QueryBuilder<T,ID> groupByRaw(String rawSql)
public QueryBuilder<T,ID> orderBy(String columnName, boolean ascending)
public QueryBuilder<T,ID> orderByRaw(String rawSql)
public QueryBuilder<T,ID> distinct()
NOTE: Use of this means that the resulting objects may not have a valid ID column value so cannot be deleted or updated.
public QueryBuilder<T,ID> limit(Integer maxRows)
public QueryBuilder<T,ID> offset(Integer startRow) throws SQLException
Dao.iterator()
method instead which handles paging with a database cursor.
Otherwise, if you are paging you probably want to specify a orderBy(String, boolean)
.
NOTE: This is not supported for all databases. Also, for some databases, the limit _must_ also be specified since the offset is an argument of the limit.
SQLException
public List<T> query() throws SQLException
Dao.query(PreparedQuery)
.
SQLException
public CloseableIterator<T> iterator() throws SQLException
Dao.iterator(PreparedQuery)
.
SQLException
protected void appendStatementStart(StringBuilder sb, List<ArgumentHolder> argList) throws SQLException
StatementBuilder
appendStatementStart
in class StatementBuilder<T,ID>
SQLException
protected FieldType[] getResultFieldTypes() throws SQLException
StatementBuilder
StatementBuilder.appendStatementStart(StringBuilder, List)
was called.
This will be null except for the QueryBuilder.
getResultFieldTypes
in class StatementBuilder<T,ID>
SQLException
protected void appendStatementEnd(StringBuilder sb) throws SQLException
StatementBuilder
appendStatementEnd
in class StatementBuilder<T,ID>
SQLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |