T
- Entity class to create an query for.public class QueryBuilder<T>
extends java.lang.Object
AbstractDao.queryBuilder()
or AbstractDaoSession.queryBuilder(Class)
.
Entity properties are referenced by Fields in the "Properties" inner class of the generated DAOs. This approach
allows compile time checks and prevents typo errors occuring at build time.
List joes = dao.queryBuilder().where(Properties.FirstName.eq("Joe")).orderAsc(Properties.LastName).list();
Modifier and Type | Field and Description |
---|---|
static boolean |
LOG_SQL
Set to true to debug the SQL.
|
static boolean |
LOG_VALUES
Set to see the given values.
|
Modifier | Constructor and Description |
---|---|
protected |
QueryBuilder(AbstractDao<T,?> dao) |
protected |
QueryBuilder(AbstractDao<T,?> dao,
java.lang.String tablePrefix) |
Modifier and Type | Method and Description |
---|---|
WhereCondition |
and(WhereCondition cond1,
WhereCondition cond2,
WhereCondition... condMore)
Creates a WhereCondition by combining the given conditions using AND.
|
protected java.lang.StringBuilder |
append(java.lang.StringBuilder builder,
Property property) |
Query<T> |
build()
Builds a reusable query object (Query objects can be executed more efficiently than creating a QueryBuilder for
each execution.
|
CountQuery<T> |
buildCount()
Builds a reusable query object for counting rows (Query objects can be executed more efficiently than creating a
QueryBuilder for each execution.
|
CursorQuery |
buildCursor()
Builds a reusable query object for low level android.database.Cursor access.
|
DeleteQuery<T> |
buildDelete()
Builds a reusable query object for deletion (Query objects can be executed more efficiently than creating a
QueryBuilder for each execution.
|
long |
count()
Shorthand for
buildCount() . |
QueryBuilder<T> |
distinct()
Use a SELECT DISTINCT to avoid duplicate entities returned, e.g. when doing joins.
|
static <T2> QueryBuilder<T2> |
internalCreate(AbstractDao<T2,?> dao)
For internal use by greenDAO only.
|
<J> Join<T,J> |
join(java.lang.Class<J> destinationEntityClass,
Property destinationProperty)
Expands the query to another entity type by using a JOIN.
|
<J> Join<T,J> |
join(Join<?,T> sourceJoin,
Property sourceProperty,
java.lang.Class<J> destinationEntityClass,
Property destinationProperty)
Expands the query to another entity type by using a JOIN.
|
<J> Join<T,J> |
join(Property sourceProperty,
java.lang.Class<J> destinationEntityClass)
Expands the query to another entity type by using a JOIN.
|
<J> Join<T,J> |
join(Property sourceProperty,
java.lang.Class<J> destinationEntityClass,
Property destinationProperty)
Expands the query to another entity type by using a JOIN.
|
QueryBuilder<T> |
limit(int limit)
Limits the number of results returned by queries.
|
java.util.List<T> |
list()
Shorthand for
build() . |
CloseableListIterator<T> |
listIterator()
Shorthand for
build() . |
LazyList<T> |
listLazy()
Shorthand for
build() . |
LazyList<T> |
listLazyUncached()
Shorthand for
build() . |
QueryBuilder<T> |
offset(int offset)
Sets the offset for query results in combination with
limit(int) . |
WhereCondition |
or(WhereCondition cond1,
WhereCondition cond2,
WhereCondition... condMore)
Creates a WhereCondition by combining the given conditions using OR.
|
QueryBuilder<T> |
orderAsc(Property... properties)
Adds the given properties to the ORDER BY section using ascending order.
|
QueryBuilder<T> |
orderCustom(Property property,
java.lang.String customOrderForProperty)
Adds the given properties to the ORDER BY section using the given custom order.
|
QueryBuilder<T> |
orderDesc(Property... properties)
Adds the given properties to the ORDER BY section using descending order.
|
QueryBuilder<T> |
orderRaw(java.lang.String rawOrder)
Adds the given raw SQL string to the ORDER BY section.
|
T |
unique()
Shorthand for
build() . |
T |
uniqueOrThrow()
Shorthand for
build() . |
QueryBuilder<T> |
where(WhereCondition cond,
WhereCondition... condMore)
Adds the given conditions to the where clause using an logical AND.
|
QueryBuilder<T> |
whereOr(WhereCondition cond1,
WhereCondition cond2,
WhereCondition... condMore)
Adds the given conditions to the where clause using an logical OR.
|
public static boolean LOG_SQL
public static boolean LOG_VALUES
protected QueryBuilder(AbstractDao<T,?> dao)
protected QueryBuilder(AbstractDao<T,?> dao, java.lang.String tablePrefix)
public static <T2> QueryBuilder<T2> internalCreate(AbstractDao<T2,?> dao)
public QueryBuilder<T> distinct()
public QueryBuilder<T> where(WhereCondition cond, WhereCondition... condMore)
public QueryBuilder<T> whereOr(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)
public WhereCondition or(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)
where(WhereCondition, WhereCondition...)
or
whereOr(WhereCondition, WhereCondition, WhereCondition...)
.public WhereCondition and(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)
where(WhereCondition, WhereCondition...)
or
whereOr(WhereCondition, WhereCondition, WhereCondition...)
.public <J> Join<T,J> join(java.lang.Class<J> destinationEntityClass, Property destinationProperty)
public <J> Join<T,J> join(Property sourceProperty, java.lang.Class<J> destinationEntityClass)
public <J> Join<T,J> join(Property sourceProperty, java.lang.Class<J> destinationEntityClass, Property destinationProperty)
public <J> Join<T,J> join(Join<?,T> sourceJoin, Property sourceProperty, java.lang.Class<J> destinationEntityClass, Property destinationProperty)
public QueryBuilder<T> orderAsc(Property... properties)
public QueryBuilder<T> orderDesc(Property... properties)
public QueryBuilder<T> orderCustom(Property property, java.lang.String customOrderForProperty)
public QueryBuilder<T> orderRaw(java.lang.String rawOrder)
protected java.lang.StringBuilder append(java.lang.StringBuilder builder, Property property)
public QueryBuilder<T> limit(int limit)
public QueryBuilder<T> offset(int offset)
limit(int)
. The first limit
results are
skipped and the total number of results will be limited by limit
. You cannot use offset without limit.public Query<T> build()
public CursorQuery buildCursor()
public DeleteQuery<T> buildDelete()
public CountQuery<T> buildCount()
public java.util.List<T> list()
build()
.list()
; see Query.list()
for
details. To execute a query more than once, you should build the query and keep the Query
object for
efficiency reasons.public LazyList<T> listLazy()
build()
.listLazy()
; see
Query.listLazy()
for details. To execute a query more than once, you should build the query and keep the
Query
object for efficiency reasons.public LazyList<T> listLazyUncached()
build()
.listLazyUncached()
; see
Query.listLazyUncached()
for details. To execute a query more than once, you should build the query and
keep the Query
object for efficiency reasons.public CloseableListIterator<T> listIterator()
build()
.listIterator()
; see
Query.listIterator()
for details. To execute a query more than once, you should build the query and keep
the Query
object for efficiency reasons.public T unique()
build()
.unique()
; see Query.unique()
for details. To execute a query more than once, you should build the query and keep the Query
object for
efficiency reasons.public T uniqueOrThrow()
build()
.uniqueOrThrow()
; see
Query.uniqueOrThrow()
for details. To execute a query more than once, you should build the query and
keep
the Query
object for efficiency reasons.public long count()
buildCount()
.count()
; see
CountQuery.count()
for details. To execute a query more than once, you should build the query and keep
the CountQuery
object for efficiency reasons.Available under the Apache License, Version 2.0 - Copyright © 2011-2015 greenrobot.de. All Rights Reserved.