com.scooterframework.orm.activerecord
Class QueryBuilder

java.lang.Object
  extended by com.scooterframework.orm.activerecord.QueryBuilder

public class QueryBuilder
extends java.lang.Object

QueryBuilder class provides flexible methods for building a query.


Method Summary
 Paginator getPaginator()
          Returns a Paginator that satisfy the query built by the QueryBuilder.
 ActiveRecord getRecord()
          Returns the record that satisfies the query built by the QueryBuilder.
 java.util.List<ActiveRecord> getRecords()
          Returns all the records that satisfy the query built by the QueryBuilder.
 QueryBuilder groupBy(java.lang.String groupBy)
          Setup group-by clause.
 QueryBuilder having(java.lang.String having)
          Setup having clause.
 QueryBuilder includes(java.lang.String includes)
          Setup associated models for eager loading.
 QueryBuilder includes(java.lang.String includes, boolean strict)
          Setup associated models for eager loading.
 QueryBuilder includes(java.lang.String includes, java.lang.String joinType)
          Setup associated models for eager loading.
 QueryBuilder limit(int limit)
          Setup limit for number of records per retrieval.
 QueryBuilder offset(int offset)
          Setup number of records to skip.
 QueryBuilder orderBy(java.lang.String orderBy)
          Setup group-by clause.
 QueryBuilder page(int page)
          Setup current page number.
 QueryBuilder where(java.lang.String conditionsSQL)
          Setup where clause.
 QueryBuilder where(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLDataMap)
          Setup where clause.
 QueryBuilder where(java.lang.String conditionsSQL, java.lang.Object[] conditionsSQLData)
          Setup where clause.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getRecords

public java.util.List<ActiveRecord> getRecords()

Returns all the records that satisfy the query built by the QueryBuilder.

Returns:
a list of ActiveRecord objects

getRecord

public ActiveRecord getRecord()

Returns the record that satisfies the query built by the QueryBuilder.

Returns:
the ActiveRecord object

getPaginator

public Paginator getPaginator()

Returns a Paginator that satisfy the query built by the QueryBuilder. Total number of records and paged list of records can be obtained from the returned Paginator instance.

Returns:
a Paginator instance

where

public QueryBuilder where(java.lang.String conditionsSQL)

Setup where clause.

Parameters:
conditionsSQL - a valid SQL query where clause string
Returns:
current QueryBuilder instance

where

public QueryBuilder where(java.lang.String conditionsSQL,
                          java.lang.Object[] conditionsSQLData)

Setup where clause.

Parameters:
conditionsSQL - a valid SQL query where clause string
conditionsSQLData - an array of data for the conditionsSQL string
Returns:
current QueryBuilder instance

where

public QueryBuilder where(java.lang.String conditionsSQL,
                          java.util.Map<java.lang.String,java.lang.Object> conditionsSQLDataMap)

Setup where clause.

Parameters:
conditionsSQL - a valid SQL query where clause string
conditionsSQLDataMap - a map of data for the keys in the conditionsSQL string
Returns:
current QueryBuilder instance

includes

public QueryBuilder includes(java.lang.String includes)

Setup associated models for eager loading.

Parameters:
includes - a string of associated models
Returns:
current QueryBuilder instance

includes

public QueryBuilder includes(java.lang.String includes,
                             java.lang.String joinType)

Setup associated models for eager loading.

Parameters:
includes - a string of associated models
joinType - type of join
Returns:
current QueryBuilder instance

includes

public QueryBuilder includes(java.lang.String includes,
                             boolean strict)

Setup associated models for eager loading.

If strict is true, then child records can only be accessed through their parent.

Parameters:
includes - a string of associated models
strict - true if strict
Returns:
current QueryBuilder instance

groupBy

public QueryBuilder groupBy(java.lang.String groupBy)

Setup group-by clause.

Parameters:
groupBy - a valid SQL query group-by clause string
Returns:
current QueryBuilder instance

having

public QueryBuilder having(java.lang.String having)

Setup having clause.

Parameters:
having - a valid SQL query having clause string
Returns:
current QueryBuilder instance

orderBy

public QueryBuilder orderBy(java.lang.String orderBy)

Setup group-by clause.

Parameters:
orderBy - a valid SQL query order-by clause string
Returns:
current QueryBuilder instance

limit

public QueryBuilder limit(int limit)

Setup limit for number of records per retrieval.

Parameters:
limit - number of records for each retrieval
Returns:
current QueryBuilder instance

offset

public QueryBuilder offset(int offset)

Setup number of records to skip.

Parameters:
offset - number of records to skip
Returns:
current QueryBuilder instance

page

public QueryBuilder page(int page)

Setup current page number. All records in previous pages are skipped.

The first page is 1, not 0.

Parameters:
page - current page number
Returns:
current QueryBuilder instance