Package org.apache.ofbiz.entity.util
Class EntityQuery
java.lang.Object
org.apache.ofbiz.entity.util.EntityQuery
Used to setup various options for and subsequently execute entity queries.
All methods to set options modify the EntityQuery instance then return this modified object to allow method call chaining. It is
important to note that this object is not immutable and is modified internally, and returning EntityQuery is just a
self reference for convenience.
After a query the object can be further modified and then used to perform another query if desired.
-
Constructor Summary
ConstructorDescriptionEntityQuery
(Delegator delegator) Construct an EntityQuery object for use against the specified Delegator -
Method Summary
Modifier and TypeMethodDescriptioncache()
Specifies whether results should be read from the cache (or written to the cache if the results have not yet been cached)cache
(boolean useCache) Specifies whether results should be read from the cache (or written to the cache if the results have not yet been cached)Indicate that the ResultSet object's cursor may move only forward (this is the default behavior)Indicate that the ResultSet object's cursor is scrollable but generally not sensitive to changes to the data that underlies the ResultSet.Indicate that the ResultSet object's cursor is scrollable but generally sensitive to changes to the data that underlies the ResultSet.distinct()
Specifies that the values returned should be filtered to remove duplicate values.distinct
(boolean distinct) Specifies whether the values returned should be filtered to remove duplicate values.fetchSize
(int fetchSize) Specifies the fetch size for this query.Specifies whether the query should return only values that are currently active using from/thruDate fields.filterByDate
(String... filterByFieldName) Specifies whether the query should return only values that are currently active using the specified from/thru field name pairs.filterByDate
(Timestamp moment) Specifies whether the query should return only values that are active during the specified moment using from/thruDate fields.filterByDate
(Timestamp moment, String... filterByFieldName) Specifies whether the query should return only values that are active during the specified moment using the specified from/thru field name pairs.filterByDate
(Date moment) Specifies whether the query should return only values that are active during the specified moment using from/thruDate fields.Set the entity to query againstfrom
(DynamicViewEntity dynamicViewEntity) Set the entity to query against<T> List<T>
getFieldList
(String fieldName) Gets a list of values (no matter which type) for a specified entity field name.getLimit()
Gets limit.Gets offset.having
(EntityCondition entityCondition) Set the EntityCondition to be used as the HAVING clause for the query.limit
(int limit) Limit entity query.maxRows
(int maxRows) Specifies the max number of rows to return, 0 means all rows.offset
(int offset) Offset entity query.The fields of the named entity to order the resultset by; optionally add a " ASC" for ascending or " DESC" for descending NOTE: Each successive call to any of the orderBy(...) methods will replace the currently set orderBy fields for the query.The fields of the named entity to order the resultset by; optionally add a " ASC" for ascending or " DESC" for descending NOTE: Each successive call to any of the orderBy(...) methods will replace the currently set orderBy fields for the query.query batch iteratorlong
Executes the EntityQuery and returns the result count If the query generates more than a single result then an exception is thrownExecutes the EntityQuery and returns the first resultExecutes the EntityQuery and returns an EntityListIterator representing the result of the query.Executes the EntityQuery and returns a list of resultsqueryOne()
Executes the EntityQuery and a single result recordqueryPagedList
(int viewIndex, int viewSize) Set the fields to be returned when the query is executed.Set the fields to be returned when the query is executed.static EntityQuery
Construct an EntityQuery object for use against the specified DelegatorSet a series of field name/values to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.<T extends EntityCondition>
EntityQuerySet a list of EntityCondition objects to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.Set a Map of field name/values to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.where
(EntityCondition entityCondition) Set the EntityCondition to be used as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.where
(EntityCondition... entityCondition) Set a series of EntityConditions to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.
-
Constructor Details
-
EntityQuery
Construct an EntityQuery object for use against the specified Delegator- Parameters:
delegator
- The delegator instance to use for the query
-
-
Method Details
-
use
Construct an EntityQuery object for use against the specified Delegator- Parameters:
delegator
- The delegator instance to use for the query
-
select
Set the fields to be returned when the query is executed. Note that the select methods are not additive, if a subsequent call is made to select then the existing fields for selection will be replaced.- Parameters:
fieldsToSelect
- - A Set of Strings containing the field names to be selected- Returns:
- this EntityQuery object, to enable chaining
-
select
Set the fields to be returned when the query is executed. Note that the select methods are not additive, if a subsequent call is made to select then the existing fields for selection will be replaced.- Parameters:
fields
- - Strings containing the field names to be selected- Returns:
- this EntityQuery object, to enable chaining
-
from
Set the entity to query against- Parameters:
entityName
- - The name of the entity to query against- Returns:
- this EntityQuery object, to enable chaining
-
from
Set the entity to query against- Parameters:
dynamicViewEntity
- - The DynamicViewEntity object to query against- Returns:
- this EntityQuery object, to enable chaining
-
where
Set the EntityCondition to be used as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.- Parameters:
entityCondition
- - An EntityCondition object to be used as the where clause for this query- Returns:
- this EntityQuery object, to enable chaining
-
where
Set a Map of field name/values to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.- Parameters:
fieldMap
- - A Map of field names/values to be ANDed together as the where clause for the query- Returns:
- this EntityQuery object, to enable chaining
-
where
Set a series of field name/values to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.- Parameters:
fields
- - A series of field names/values to be ANDed together as the where clause for the query- Returns:
- this EntityQuery object, to enable chaining
-
where
Set a series of EntityConditions to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.- Parameters:
entityCondition
- - A series of EntityConditions to be ANDed together as the where clause for the query- Returns:
- this EntityQuery object, to enable chaining
-
where
Set a list of EntityCondition objects to be ANDed together as the WHERE clause for the query NOTE: Each successive call to any of the where(...) methods will replace the currently set condition for the query.- Parameters:
andConditions
- - A list of EntityCondition objects to be ANDed together as the WHERE clause for the query- Returns:
- this EntityQuery object, to enable chaining
-
having
Set the EntityCondition to be used as the HAVING clause for the query. NOTE: Each successive call to any of the having(...) methods will replace the currently set condition for the query.- Parameters:
entityCondition
- - The EntityCondition object that specifies how to constrain this query after any groupings are done (if this is a view entity with group-by aliases)- Returns:
- this EntityQuery object, to enable chaining
-
orderBy
The fields of the named entity to order the resultset by; optionally add a " ASC" for ascending or " DESC" for descending NOTE: Each successive call to any of the orderBy(...) methods will replace the currently set orderBy fields for the query.- Parameters:
orderBy
- - The fields of the named entity to order the resultset by- Returns:
- this EntityQuery object, to enable chaining
-
orderBy
The fields of the named entity to order the resultset by; optionally add a " ASC" for ascending or " DESC" for descending NOTE: Each successive call to any of the orderBy(...) methods will replace the currently set orderBy fields for the query.- Parameters:
fields
- - The fields of the named entity to order the resultset by- Returns:
- this EntityQuery object, to enable chaining
-
cursorForwardOnly
Indicate that the ResultSet object's cursor may move only forward (this is the default behavior)- Returns:
- this EntityQuery object, to enable chaining
-
cursorScrollSensitive
Indicate that the ResultSet object's cursor is scrollable but generally sensitive to changes to the data that underlies the ResultSet.- Returns:
- this EntityQuery object, to enable chaining
-
cursorScrollInsensitive
Indicate that the ResultSet object's cursor is scrollable but generally not sensitive to changes to the data that underlies the ResultSet.- Returns:
- this EntityQuery object, to enable chaining
-
fetchSize
Specifies the fetch size for this query. -1 will fall back to datasource settings.- Parameters:
fetchSize
- - The fetch size for this query- Returns:
- this EntityQuery object, to enable chaining
-
maxRows
Specifies the max number of rows to return, 0 means all rows.- Parameters:
maxRows
- - the max number of rows to return- Returns:
- this EntityQuery object, to enable chaining
-
offset
Offset entity query.- Parameters:
offset
- the offset- Returns:
- the entity query
-
getOffset
Gets offset.- Returns:
- the offset
-
limit
Limit entity query.- Parameters:
limit
- the limit- Returns:
- the entity query
-
getLimit
Gets limit.- Returns:
- the limit
-
distinct
Specifies that the values returned should be filtered to remove duplicate values.- Returns:
- this EntityQuery object, to enable chaining
-
distinct
Specifies whether the values returned should be filtered to remove duplicate values.- Parameters:
distinct
- - boolean indicating whether the values returned should be filtered to remove duplicate values- Returns:
- this EntityQuery object, to enable chaining
-
cache
Specifies whether results should be read from the cache (or written to the cache if the results have not yet been cached)- Returns:
- this EntityQuery object, to enable chaining
-
cache
Specifies whether results should be read from the cache (or written to the cache if the results have not yet been cached)- Parameters:
useCache
- - boolean to indicate if the cache should be used or not- Returns:
- this EntityQuery object, to enable chaining
-
filterByDate
Specifies whether the query should return only values that are currently active using from/thruDate fields.- Returns:
- this EntityQuery object, to enable chaining
-
filterByDate
Specifies whether the query should return only values that are active during the specified moment using from/thruDate fields.- Parameters:
moment
- - Timestamp representing the moment in time that the values should be active during- Returns:
- this EntityQuery object, to enable chaining
-
filterByDate
Specifies whether the query should return only values that are active during the specified moment using from/thruDate fields.- Parameters:
moment
- - Date representing the moment in time that the values should be active during- Returns:
- this EntityQuery object, to enable chaining
-
filterByDate
Specifies whether the query should return only values that are currently active using the specified from/thru field name pairs.- Parameters:
filterByFieldName
- - String pairs representing the from/thru date field names e.g. "fromDate", "thruDate", "contactFromDate", "contactThruDate"- Returns:
- this EntityQuery object, to enable chaining
-
filterByDate
Specifies whether the query should return only values that are active during the specified moment using the specified from/thru field name pairs.- Parameters:
moment
- - Timestamp representing the moment in time that the values should be active duringfilterByFieldName
- - String pairs representing the from/thru date field names e.g. "fromDate", "thruDate", "contactFromDate", "contactThruDate"- Returns:
- this EntityQuery object, to enable chaining
-
queryList
Executes the EntityQuery and returns a list of results- Returns:
- Returns a List of GenericValues representing the results of the query
- Throws:
GenericEntityException
-
queryIterator
Executes the EntityQuery and returns an EntityListIterator representing the result of the query. NOTE: THAT THIS MUST BE CLOSED (preferably in a finally block) WHEN YOU ARE DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION.- Returns:
- Returns an EntityListIterator representing the result of the query
- Throws:
GenericEntityException
-
queryBatchIterator
query batch iterator -
queryFirst
Executes the EntityQuery and returns the first result- Returns:
- GenericValue representing the first result record from the query
- Throws:
GenericEntityException
-
queryOne
Executes the EntityQuery and a single result record- Returns:
- GenericValue representing the only result record from the query
- Throws:
GenericEntityException
-
queryCount
Executes the EntityQuery and returns the result count If the query generates more than a single result then an exception is thrown- Returns:
- GenericValue representing the only result record from the query
- Throws:
GenericEntityException
-
getFieldList
Gets a list of values (no matter which type) for a specified entity field name.The field of the entity is first selected and the cache usage turned off to ensure no values are missing.
- Type Parameters:
T
-- Parameters:
fieldName
-- Returns:
- list with field values
- Throws:
GenericEntityException
-
queryPagedList
public PagedList<GenericValue> queryPagedList(int viewIndex, int viewSize) throws GenericEntityException - Parameters:
viewIndex
-viewSize
-- Returns:
- PagedList object with a subset of data items
- Throws:
GenericEntityException
- See Also:
-