Package org.greenrobot.greendao.query
Class QueryBuilder<T>
- java.lang.Object
-
- org.greenrobot.greendao.query.QueryBuilder<T>
-
- Type Parameters:
T- Entity class to create an query for.
public class QueryBuilder<T> extends java.lang.ObjectBuilds custom entity queries using constraints and parameters and without SQL (QueryBuilder creates SQL for you). To acquire an QueryBuilder, useAbstractDao.queryBuilder()orAbstractDaoSession.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.
Example: Query for all users with the first name "Joe" ordered by their last name. (The class Properties is an inner class of UserDao and should be imported before.)
Listjoes = dao.queryBuilder().where(Properties.FirstName.eq("Joe")).orderAsc(Properties.LastName).list();
-
-
Field Summary
Fields Modifier and Type Field Description static booleanLOG_SQLSet to true to debug the SQL.static booleanLOG_VALUESSet to see the given values.
-
Constructor Summary
Constructors Modifier Constructor Description protectedQueryBuilder(AbstractDao<T,?> dao)protectedQueryBuilder(AbstractDao<T,?> dao, java.lang.String tablePrefix)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WhereConditionand(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)Creates a WhereCondition by combining the given conditions using AND.protected java.lang.StringBuilderappend(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.CursorQuerybuildCursor()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.longcount()QueryBuilder<T>distinct()Use a SELECT DISTINCT to avoid duplicate entities returned, e.g.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(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.<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.QueryBuilder<T>limit(int limit)Limits the number of results returned by queries.java.util.List<T>list()CloseableListIterator<T>listIterator()LazyList<T>listLazy()LazyList<T>listLazyUncached()QueryBuilder<T>offset(int offset)Sets the offset for query results in combination withlimit(int).WhereConditionor(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.QueryBuilder<T>preferLocalizedStringOrder()If using Android's embedded SQLite, this enables localized ordering of strings (seeorderAsc(Property...)andorderDesc(Property...)).RxQuery<T>rx()Shorthand forbuild().Query.__InternalRx().RxQuery<T>rxPlain()Shorthand forbuild().Query.__internalRxPlain().QueryBuilder<T>stringOrderCollation(java.lang.String stringOrderCollation)Customizes the ordering of strings used byorderAsc(Property...)andorderDesc(Property...).Tunique()TuniqueOrThrow()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.
-
-
-
Constructor Detail
-
QueryBuilder
protected QueryBuilder(AbstractDao<T,?> dao)
-
QueryBuilder
protected QueryBuilder(AbstractDao<T,?> dao, java.lang.String tablePrefix)
-
-
Method Detail
-
internalCreate
public static <T2> QueryBuilder<T2> internalCreate(AbstractDao<T2,?> dao)
For internal use by greenDAO only.
-
distinct
public QueryBuilder<T> distinct()
Use a SELECT DISTINCT to avoid duplicate entities returned, e.g. when doing joins.
-
preferLocalizedStringOrder
public QueryBuilder<T> preferLocalizedStringOrder()
If using Android's embedded SQLite, this enables localized ordering of strings (seeorderAsc(Property...)andorderDesc(Property...)). This uses "COLLATE LOCALIZED", which is unavailable in SQLCipher (in that case, the ordering is unchanged).- See Also:
stringOrderCollation
-
stringOrderCollation
public QueryBuilder<T> stringOrderCollation(java.lang.String stringOrderCollation)
Customizes the ordering of strings used byorderAsc(Property...)andorderDesc(Property...). Default is "COLLATE NOCASE".- See Also:
preferLocalizedStringOrder()
-
where
public QueryBuilder<T> where(WhereCondition cond, WhereCondition... condMore)
Adds the given conditions to the where clause using an logical AND. To create new conditions, use the properties given in the generated dao classes.
-
whereOr
public QueryBuilder<T> whereOr(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)
Adds the given conditions to the where clause using an logical OR. To create new conditions, use the properties given in the generated dao classes.
-
or
public WhereCondition or(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)
Creates a WhereCondition by combining the given conditions using OR. The returned WhereCondition must be used insidewhere(WhereCondition, WhereCondition...)orwhereOr(WhereCondition, WhereCondition, WhereCondition...).
-
and
public WhereCondition and(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)
Creates a WhereCondition by combining the given conditions using AND. The returned WhereCondition must be used insidewhere(WhereCondition, WhereCondition...)orwhereOr(WhereCondition, WhereCondition, WhereCondition...).
-
join
public <J> Join<T,J> join(java.lang.Class<J> destinationEntityClass, Property destinationProperty)
Expands the query to another entity type by using a JOIN. The primary key property of the primary entity for this QueryBuilder is used to match the given destinationProperty.
-
join
public <J> Join<T,J> join(Property sourceProperty, java.lang.Class<J> destinationEntityClass)
Expands the query to another entity type by using a JOIN. The given sourceProperty is used to match the primary key property of the given destinationEntity.
-
join
public <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. The given sourceProperty is used to match the given destinationProperty of the given destinationEntity.
-
join
public <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. The given sourceJoin's property is used to match the given destinationProperty of the given destinationEntity. Note that destination entity of the given join is used as the source for the new join to add. In this way, it is possible to compose complex "join of joins" across several entities if required.
-
orderAsc
public QueryBuilder<T> orderAsc(Property... properties)
Adds the given properties to the ORDER BY section using ascending order.
-
orderDesc
public QueryBuilder<T> orderDesc(Property... properties)
Adds the given properties to the ORDER BY section using descending order.
-
orderCustom
public QueryBuilder<T> orderCustom(Property property, java.lang.String customOrderForProperty)
Adds the given properties to the ORDER BY section using the given custom order.
-
orderRaw
public QueryBuilder<T> orderRaw(java.lang.String rawOrder)
Adds the given raw SQL string to the ORDER BY section. Do not use this for standard properties: orderAsc and orderDesc are preferred.
-
append
protected java.lang.StringBuilder append(java.lang.StringBuilder builder, Property property)
-
limit
public QueryBuilder<T> limit(int limit)
Limits the number of results returned by queries.
-
offset
public QueryBuilder<T> offset(int offset)
Sets the offset for query results in combination withlimit(int). The firstoffsetresults are skipped and the total number of results will be limited bylimit. You cannot use offset without limit.
-
build
public Query<T> build()
Builds a reusable query object (Query objects can be executed more efficiently than creating a QueryBuilder for each execution.
-
buildCursor
public CursorQuery buildCursor()
Builds a reusable query object for low level android.database.Cursor access. (Query objects can be executed more efficiently than creating a QueryBuilder for each execution.
-
buildDelete
public DeleteQuery<T> buildDelete()
Builds a reusable query object for deletion (Query objects can be executed more efficiently than creating a QueryBuilder for each execution.
-
buildCount
public 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.
-
list
public java.util.List<T> list()
Shorthand forbuild().list(); seeQuery.list()for details. To execute a query more than once, you should build the query and keep theQueryobject for efficiency reasons.
-
rx
@Experimental public RxQuery<T> rx()
Shorthand forbuild().Query.__InternalRx().
-
rxPlain
@Experimental public RxQuery<T> rxPlain()
Shorthand forbuild().Query.__internalRxPlain().
-
listLazy
public LazyList<T> listLazy()
Shorthand forbuild().listLazy(); seeQuery.listLazy()for details. To execute a query more than once, you should build the query and keep theQueryobject for efficiency reasons.
-
listLazyUncached
public LazyList<T> listLazyUncached()
Shorthand forbuild().listLazyUncached(); seeQuery.listLazyUncached()for details. To execute a query more than once, you should build the query and keep theQueryobject for efficiency reasons.
-
listIterator
public CloseableListIterator<T> listIterator()
Shorthand forbuild().listIterator(); seeQuery.listIterator()for details. To execute a query more than once, you should build the query and keep theQueryobject for efficiency reasons.
-
unique
public T unique()
Shorthand forbuild().unique(); seeQuery.unique()for details. To execute a query more than once, you should build the query and keep theQueryobject for efficiency reasons.
-
uniqueOrThrow
public T uniqueOrThrow()
Shorthand forbuild().uniqueOrThrow(); seeQuery.uniqueOrThrow()for details. To execute a query more than once, you should build the query and keep theQueryobject for efficiency reasons.
-
count
public long count()
Shorthand forbuildCount().count(); seeCountQuery.count()for details. To execute a query more than once, you should build the query and keep theCountQueryobject for efficiency reasons.
-
-