org.ujoframework.orm
Class Query<UJO extends OrmUjo>

java.lang.Object
  extended by org.ujoframework.orm.Query<UJO>
All Implemented Interfaces:
java.lang.Iterable<UJO>

public class Query<UJO extends OrmUjo>
extends java.lang.Object
implements java.lang.Iterable<UJO>

ORM query.

Author:
Pavel Ponec

Constructor Summary
Query(MetaTable table, Criterion<UJO> criterion)
          Create new ORM query without a session.
Query(MetaTable table, Criterion<UJO> criterion, Session session)
          Create new ORM query.
 
Method Summary
 void addCriterion(Criterion<UJO> criterion)
          Add a new Criterion
 Query<UJO> addOrderBy(UjoProperty<UJO,?> property)
          Add an item to the end of order list.
 boolean exists()
          The method performs a new database request and returns result of the function UjoIterator.hasNext().
 MetaColumn getColumn(int index)
          Get Column List
 java.util.List<MetaColumn> getColumns()
          Get Column List
 long getCount()
          Returns a count of the items
 Criterion<UJO> getCriterion()
          Criterion
 CriterionDecoder getDecoder()
          Method builds and retuns a criterion decoder.
 int getFetchSize()
          Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed.
 int getLimit()
          The max row count for the resultset.
 long getLimitedCount()
          Returns a database row count along a current limit and offset attribues.
 int getOffset()
          Get the first row to retrieve (offset).
 java.util.List<UjoProperty<UJO,?>> getOrderBy()
          Get the order item list.
 Session getSession()
          Session
 java.sql.PreparedStatement getStatement()
          Create a PreparedStatement include assigned parameter values
 java.lang.String getStatementInfo()
          Get the SQL statement or null, of statement is not known yet.
 MetaTable getTableModel()
          Table Type
 boolean isLockRequest()
          Pessimistic lock request
 boolean isOffset()
          Has this Query an offset?
 UjoIterator<UJO> iterate()
          Deprecated. Use iterator() instead of.
 UjoIterator<UJO> iterator()
          Create a new iterator by the query.
 java.util.List<UJO> list()
          There is recommended to use the method iterator() rather.
 Query<UJO> orderBy(java.util.List<UjoProperty> orderItems)
          Set an order of the rows by a SQL ORDER BY phrase.
 Query<UJO> orderBy(UjoProperty<UJO,?> orderItem)
          Set an order of the rows by a SQL ORDER BY phrase.
 Query<UJO> orderBy(UjoProperty<UJO,?> orderItem1, UjoProperty<UJO,?> orderItem2)
          Set an order of the rows by a SQL ORDER BY phrase.
 Query<UJO> orderBy(UjoProperty<UJO,?> orderItem1, UjoProperty<UJO,?> orderItem2, UjoProperty<UJO,?> orderItem3)
          Set an order of the rows by a SQL ORDER BY phrase.
 Query<UJO> orderByMany(UjoProperty... orderItems)
          Set an order of the rows by a SQL ORDER BY phrase.
 MetaColumn readOrderColumn(int i)
          Returns an order column.
 Query<UJO> setCriterion(Criterion<UJO> criterion)
          Set a new Criterion
 Query<UJO> setFetchSize(int fetchSize)
          Retrieves the number of result set rows that is the default fetch size for ResultSet objects generated from this Statement object.
 Query<UJO> setLimit(int limit)
          The max row count for the resultset.
 Query<UJO> setLimit(int limit, int offset)
          Set a limit and offset.
 Query<UJO> setLockRequest()
          Set pessimistic lock request.
 Query<UJO> setLockRequest(boolean lockRequest)
          Pessimistic lock request.
 Query<UJO> setMaxRows(int limit)
          Deprecated. 
 Query<UJO> setOffset(int offset)
          Get the first row to retrieve (offset).
 Query<UJO> setOrder(UjoProperty... order)
          Deprecated. Use the orderByMany(org.ujoframework.UjoProperty[]) method instead of
<ITEM> void
setParameter(UjoProperty<UJO,ITEM> property, ITEM value)
           
 Query<UJO> setSession(Session session)
          An open session must be assigned before executing a database request.
 java.lang.String toString()
           
 UJO uniqueResult()
          Returns a unique result or null if no result item (database row) was found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query(MetaTable table,
             Criterion<UJO> criterion,
             Session session)
Create new ORM query.

Parameters:
table - Table model
criterion - If criterion is null, then a TRUE constant criterion is used.
session - Session

Query

public Query(MetaTable table,
             Criterion<UJO> criterion)
Create new ORM query without a session. An open session must be assigned before executing a database request.

Parameters:
table - Table model
criterion - If criterion is null, then a TRUE constant criterion is used.
See Also:
setSession(org.ujoframework.orm.Session)
Method Detail

setSession

public Query<UJO> setSession(Session session)
An open session must be assigned before executing a database request.


getLimitedCount

public long getLimitedCount()
Returns a database row count along a current limit and offset attribues.

See Also:
getCount()

getCount

public long getCount()
Returns a count of the items

See Also:
getLimitedCount()

setParameter

public <ITEM> void setParameter(UjoProperty<UJO,ITEM> property,
                                ITEM value)

addCriterion

public void addCriterion(Criterion<UJO> criterion)
Add a new Criterion


setCriterion

public Query<UJO> setCriterion(Criterion<UJO> criterion)
Set a new Criterion


getCriterion

public Criterion<UJO> getCriterion()
Criterion


getDecoder

public final CriterionDecoder getDecoder()
Method builds and retuns a criterion decoder. The new decoder is cached to a next order by change.


getSession

public Session getSession()
Session


getTableModel

public MetaTable getTableModel()
Table Type


getColumns

public java.util.List<MetaColumn> getColumns()
Get Column List


getColumn

public MetaColumn getColumn(int index)
Get Column List


iterator

public UjoIterator<UJO> iterator()
Create a new iterator by the query. The result iterator can be used in the Java statement for(...) directly.
NOTE: The items can be iterated inside a database transaction only, in other case call the next expression:
iterator().toList()

Specified by:
iterator in interface java.lang.Iterable<UJO extends OrmUjo>
See Also:
uniqueResult(), exists()

iterate

@Deprecated
public final UjoIterator<UJO> iterate()
Deprecated. Use iterator() instead of.

Create a new iterator by the query.

See Also:
iterator()

list

public java.util.List<UJO> list()
There is recommended to use the method iterator() rather. The method calls internally the next statement:
iterator().toList()

See Also:
iterator(), OrmTools.loadLazyValues(java.lang.Iterable, int), OrmTools.loadLazyValuesAsBatch(org.ujoframework.orm.Query)

uniqueResult

public UJO uniqueResult()
                                throws java.util.NoSuchElementException
Returns a unique result or null if no result item (database row) was found.

Throws:
java.util.NoSuchElementException - Result is not unique.
See Also:
iterator(), exists()

exists

public boolean exists()
The method performs a new database request and returns result of the function UjoIterator.hasNext(). The result TRUE means the query covers one item (database row) at least.

See Also:
iterator(), uniqueResult()

getOrderBy

public final java.util.List<UjoProperty<UJO,?>> getOrderBy()
Get the order item list. The method returns a not null result always.


setOrder

@Deprecated
public Query<UJO> setOrder(UjoProperty... order)
Deprecated. Use the orderByMany(org.ujoframework.UjoProperty[]) method instead of

Set an order of the rows by a SQL ORDER BY phrase.

See Also:
orderByMany(org.ujoframework.UjoProperty[])

orderBy

public Query<UJO> orderBy(UjoProperty<UJO,?> orderItem)
Set an order of the rows by a SQL ORDER BY phrase.


orderBy

public Query<UJO> orderBy(UjoProperty<UJO,?> orderItem1,
                          UjoProperty<UJO,?> orderItem2)
Set an order of the rows by a SQL ORDER BY phrase.


orderBy

public Query<UJO> orderBy(UjoProperty<UJO,?> orderItem1,
                          UjoProperty<UJO,?> orderItem2,
                          UjoProperty<UJO,?> orderItem3)
Set an order of the rows by a SQL ORDER BY phrase.


orderByMany

public Query<UJO> orderByMany(UjoProperty... orderItems)
Set an order of the rows by a SQL ORDER BY phrase.
WARNING: the parameters are not type checked.


orderBy

public Query<UJO> orderBy(java.util.List<UjoProperty> orderItems)
Set an order of the rows by a SQL ORDER BY phrase. WARNING: the list items are not type checked. If you need an item chacking, use the method addOrderBy(org.ujoframework.UjoProperty) rather.

See Also:
addOrderBy(org.ujoframework.UjoProperty)

addOrderBy

public Query<UJO> addOrderBy(UjoProperty<UJO,?> property)
Add an item to the end of order list.


readOrderColumn

public MetaColumn readOrderColumn(int i)
Returns an order column. A method for an internal use only.


isOffset

public boolean isOffset()
Has this Query an offset?


getOffset

public final int getOffset()
Get the first row to retrieve (offset). Default value is 0.


setOffset

public Query<UJO> setOffset(int offset)
Get the first row to retrieve (offset). Default value is 0.

See Also:
setLimit(int, int)

getLimit

public final int getLimit()
The max row count for the resultset. The value -1 means no change, value 0 means no limit (or a default value by the JDBC driver implementation.

See Also:
java.sql.Statement#getLimit()

setLimit

public Query<UJO> setLimit(int limit)
The max row count for the resultset. The value -1 means no change, value 0 means no limit (or a default value by the JDBC driver implementation.

See Also:
Statement.setMaxRows(int)

setLimit

public Query<UJO> setLimit(int limit,
                           int offset)
Set a limit and offset.

Parameters:
limit - The max row count for the resultset. The value -1 means no change, value 0 means no limit (or a default value by the JDBC driver implementation.
offset - Get the first row to retrieve (offset). Default value is 0.
See Also:
setLimit(int), setOffset(int)

setMaxRows

@Deprecated
public final Query<UJO> setMaxRows(int limit)
Deprecated. 

Use the method setLimit(int) rather.

See Also:
setLimit(int)

getFetchSize

public int getFetchSize()
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed.

See Also:
Statement.getFetchSize()

setFetchSize

public Query<UJO> setFetchSize(int fetchSize)
Retrieves the number of result set rows that is the default fetch size for ResultSet objects generated from this Statement object.

See Also:
Statement.setFetchSize(int)

getStatement

public java.sql.PreparedStatement getStatement()
Create a PreparedStatement include assigned parameter values


getStatementInfo

public java.lang.String getStatementInfo()
Get the SQL statement or null, of statement is not known yet.


isLockRequest

public boolean isLockRequest()
Pessimistic lock request


setLockRequest

public Query<UJO> setLockRequest(boolean lockRequest)
Pessimistic lock request. A default value is false.


setLockRequest

public Query<UJO> setLockRequest()
Set pessimistic lock request. A default value is false.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.