de.greenrobot.dao
Class QueryBuilder

java.lang.Object
  extended by de.greenrobot.dao.QueryBuilder
Type Parameters:
T - Entity class to create an query for.

public class QueryBuilder
extends java.lang.Object

    

Builds custom entity queries using constraints and parameters and without SQL (QueryBuilder creates SQL for you). To acquire an QueryBuilder, use 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.

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.)
List joes = dao.queryBuilder().where(Properties.FirstName.eq("Joe")).orderAsc(Properties.LastName).list();


Field Summary
static boolean LOG_SQL
          Set to true to debug the SQL.
static boolean LOG_VALUES
          Set to see the given values.
 
Method Summary
 WhereCondition and(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)
           
 Query<T> build()
          Builds a reusable query object (Query objects can be executed more efficiently than creating a QueryBuilder for each execution.
 DeleteQuery<T> buildDelete()
          Builds a reusable query object for deletion (Query objects can be executed more efficiently than creating a QueryBuilder for each execution.
QueryBuilder
join(java.lang.Class entityClass, Property toOneProperty)
          Not supported yet.
QueryBuilder
joinToMany(java.lang.Class entityClass, Property toManyProperty)
          Not supported yet.
 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)
           
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_SQL

public static boolean LOG_SQL
Set to true to debug the SQL.


LOG_VALUES

public static boolean LOG_VALUES
Set to see the given values.

Method Detail

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)

and

public WhereCondition and(WhereCondition cond1,
                          WhereCondition cond2,
                          WhereCondition... condMore)

join

public  QueryBuilder join(java.lang.Class entityClass,
                                Property toOneProperty)
Not supported yet.


joinToMany

public  QueryBuilder joinToMany(java.lang.Class entityClass,
                                      Property toManyProperty)
Not supported yet.


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: ordedAsc and orderDesc are prefered.


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 with 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.


build

public Query<T> build()
Builds a reusable query object (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.


list

public java.util.List<T> list()
Shorthand for 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.


listLazy

public LazyList<T> listLazy()
Shorthand for 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.


listLazyUncached

public LazyList<T> listLazyUncached()
Shorthand for 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.


listIterator

public CloseableListIterator<T> listIterator()
Shorthand for 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.


unique

public T unique()
Shorthand for 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.


uniqueOrThrow

public T uniqueOrThrow()
Shorthand for 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.



Copyright © 2011-2012 greenrobot.de. All Rights Reserved.