public class DefaultOrmQuery<T> extends Object implements SpiQuery<T>
| Type | Property and Description |
|---|---|
boolean |
selectAllForLazyLoad
Return true if select all properties was used to ensure the
property invoking a lazy load was included in the query.
|
SpiQuery.Mode, SpiQuery.Type| Constructor and Description |
|---|
DefaultOrmQuery(Class<T> beanType,
EbeanServer server,
ExpressionFactory expressionFactory,
DeployNamedQuery namedQuery)
Additional supply a query which is parsed.
|
DefaultOrmQuery(Class<T> beanType,
EbeanServer server,
ExpressionFactory expressionFactory,
String query) |
| Modifier and Type | Method and Description |
|---|---|
ExpressionList<T> |
addHaving() |
DefaultOrmQuery<T> |
addHaving(Expression expression) |
DefaultOrmQuery<T> |
addHaving(String addToHavingClause) |
ExpressionList<T> |
addWhere() |
DefaultOrmQuery<T> |
addWhere(Expression expression) |
DefaultOrmQuery<T> |
addWhere(String addToWhereClause) |
void |
cancel()
Cancel the query execution if supported by the underlying database and
driver.
|
void |
contextAdd(EntityBean bean)
Add a bean to the context additions.
|
void |
convertManyFetchJoinsToQueryJoins(boolean allowOne,
int queryBatch)
Convert any many joins fetch joins to query joins.
|
void |
convertWhereNaturalKeyToId(Object idValue)
Convert this natural key query into a find by id query.
|
DefaultOrmQuery<T> |
copy()
Return a copy of the query.
|
boolean |
createOwnTransaction()
Return true if using background fetching or a queryListener.
|
DefaultOrmQuery<T> |
fetch(String property)
Specify a path to load including all its properties.
|
DefaultOrmQuery<T> |
fetch(String property,
FetchConfig joinConfig)
Additionally specify a JoinConfig to specify a "query join" and or define
the lazy loading query.
|
DefaultOrmQuery<T> |
fetch(String property,
String columns)
Specify a path to fetch with its specific properties to include
(aka partial object).
|
DefaultOrmQuery<T> |
fetch(String property,
String columns,
FetchConfig config)
Additionally specify a FetchConfig to use a separate query or lazy loading
to load this path.
|
ExpressionList<T> |
filterMany(String prop)
This applies a filter on the 'many' property list rather than the root
level objects.
|
FutureIds<T> |
findFutureIds()
Execute find Id's query in a background thread.
|
FutureList<T> |
findFutureList()
Execute find list query in a background thread.
|
FutureRowCount<T> |
findFutureRowCount()
Execute find row count query in a background thread.
|
List<Object> |
findIds()
Execute the query returning the list of Id's.
|
QueryIterator<T> |
findIterate()
Execute the query iterating over the results.
|
List<T> |
findList()
Execute the query returning the list of objects.
|
Map<?,T> |
findMap()
Execute the query returning a map of the objects.
|
<K> Map<K,T> |
findMap(String keyProperty,
Class<K> keyType)
Return a typed map specifying the key property and type.
|
PagingList<T> |
findPagingList(int pageSize)
Return a PagingList for this query.
|
int |
findRowCount()
Return the count of entities this query should return.
|
Set<T> |
findSet()
Execute the query returning the set of objects.
|
T |
findUnique()
Execute the query returning either a single bean or null (if no matching
bean is found).
|
void |
findVisit(QueryResultVisitor<T> visitor)
Execute the query using callbacks to a visitor to process the resulting
beans one at a time.
|
String |
getAdditionalHaving()
Return any additional having clauses.
|
String |
getAdditionalWhere()
Return any additional where clauses.
|
AutoFetchManager |
getAutoFetchManager()
If return null then no autoFetch profiling for this query.
|
int |
getBackgroundFetchAfter()
Return the number of rows after which fetching should occur in a
background thread.
|
BeanCollectionTouched |
getBeanCollectionTouched()
Return a listener that wants to be notified when the bean collection is
first used.
|
Class<T> |
getBeanType()
Return the type of beans queries.
|
BindParams |
getBindParams()
Return the bind parameters.
|
int |
getBufferFetchSizeHint()
Return the hint for Statement.setFetchSize().
|
ArrayList<EntityBean> |
getContextAdditions()
Return any beans that should be added to the persistence context prior to
executing the query.
|
OrmQueryDetail |
getDetail()
Return the query detail.
|
ExpressionFactory |
getExpressionFactory()
Return the ExpressionFactory used by this query.
|
int |
getFirstRow()
Return the index of the first row to return in the query.
|
String |
getGeneratedSql()
Return the sql that was generated for executing this query.
|
SpiExpressionList<T> |
getHavingExpressions()
Can return null if no expressions where added to the having clause.
|
Object |
getId()
Return the Id value.
|
List<Object> |
getIdList()
Return the list of Id's that is currently being fetched by a background
thread.
|
TableJoin |
getIncludeTableJoin() |
List<Object> |
getLazyLoadForParentIds()
Return the list of parent Id's for lazy loading.
|
BeanPropertyAssocMany<?> |
getLazyLoadForParentsProperty()
Return the lazy loading 'many' property.
|
String |
getLazyLoadManyPath()
Return the lazy load path.
|
String |
getLazyLoadProperty()
Return the property that invoked lazy load.
|
QueryListener<T> |
getListener()
Return the findListener is one has been set.
|
String |
getLoadDescription()
Return a more detailed description of the lazy or query load.
|
String |
getLoadMode()
Return the load mode (+lazy or +query).
|
ManyWhereJoins |
getManyWhereJoins()
Return the joins required to support predicates on the many properties.
|
String |
getMapKey()
Return the property used to specify keys for a map.
|
int |
getMaxRows()
Return the maximum number of rows to return in the query.
|
SpiQuery.Mode |
getMode()
Return the query mode.
|
String |
getName()
Return the query name.
|
NaturalKeyBindParam |
getNaturalKeyBindParam()
Return a Natural Key bind parameter if supported by this query.
|
OrderBy<T> |
getOrderBy()
Return the Order By clause or null if there is none defined.
|
ObjectGraphNode |
getParentNode()
Used to hook back a lazy loading query to the original query (query
point).
|
PersistenceContext |
getPersistenceContext()
Return the TransactionContext.
|
String |
getQuery()
Get the orm query as a String.
|
RawSql |
getRawSql()
Return the RawSql that was set to use for this query.
|
String |
getRawWhereClause()
Return the order by clause.
|
int |
getTimeout()
Return the timeout.
|
int |
getTotalHits() |
SpiQuery.Type |
getType()
Return the type of query (List, Set, Map, Bean, rowCount etc).
|
SpiExpressionList<T> |
getWhereExpressions()
Can return null if no expressions where added to the where clause.
|
boolean |
hasMaxRowsOrFirstRow()
Returns true if either firstRow or maxRows has been set.
|
ExpressionList<T> |
having()
Add Expressions to the Having clause return the ExpressionList.
|
DefaultOrmQuery<T> |
having(Expression expression)
Add an expression to the having clause returning the query.
|
DefaultOrmQuery<T> |
having(String addToHavingClause)
Add additional clause(s) to the having clause.
|
boolean |
initManyWhereJoins()
Return true if the where expressions contains a many property.
|
Boolean |
isAutofetch()
Return explicit autoFetch setting or null.
|
boolean |
isAutofetchTuned()
Returns true if this query was tuned by autoFetch.
|
boolean |
isCancelled()
Return true if this query has been cancelled.
|
boolean |
isDetailEmpty()
Return true if the query detail has neither select or joins specified.
|
boolean |
isDistinct()
return true if this query uses DISTINCT.
|
boolean |
isForUpdate()
Return true if this query has forUpdate set.
|
boolean |
isFutureFetch()
Return true if this is a query executing in the background.
|
boolean |
isLoadBeanCache()
Return true if the beans from this query should be loaded into the bean
cache.
|
boolean |
isRawSql()
Return true if this is a RawSql query.
|
Boolean |
isReadOnly()
Return true if the beans returned by this query should be read only.
|
boolean |
isSqlSelect()
Return true if this is a query based on a SqlSelect rather than
generated.
|
boolean |
isUsageProfiling()
Return false when this is a lazy load or refresh query for a bean.
|
Boolean |
isUseBeanCache()
Return true if this query should use/check the bean cache.
|
boolean |
isUseQueryCache()
Return true if this query should use/check the query cache.
|
OrderBy<T> |
order()
Return the OrderBy so that you can append an ascending or descending
property to the order by clause.
|
DefaultOrmQuery<T> |
order(String orderByClause)
Set the order by clause replacing the existing order by clause if there is
one.
|
OrderBy<T> |
orderBy()
Return the OrderBy so that you can append an ascending or descending
property to the order by clause.
|
DefaultOrmQuery<T> |
orderBy(String orderByClause)
Set the order by clause replacing the existing order by clause if there is
one.
|
HashQueryPlan |
queryAutofetchHash(HashQueryPlanBuilder builder)
Calculate a hash used by AutoFetch to identify when a query has changed
(and hence potentially needs a new tuned query plan to be developed).
|
int |
queryBindHash()
Calculate a hash based on the bind values used in the query.
|
HashQuery |
queryHash()
Return a hash that includes the query plan and bind values.
|
HashQueryPlan |
queryPlanHash(BeanQueryRequest<?> request)
Calculate a hash that should be unique for the generated SQL across a
given bean type.
|
List<OrmQueryProperties> |
removeLazyJoins()
Remove the lazy joins from query detail.
|
List<OrmQueryProperties> |
removeQueryJoins()
Remove the query joins from query detail.
|
DefaultOrmQuery<T> |
select(String columns)
Explicitly set a comma delimited list of the properties to fetch on the
'main' entity bean (aka partial object).
|
boolean |
selectAllForLazyLoadProperty()
Return true if select all properties was used to ensure the
property invoking a lazy load was included in the query.
|
DefaultOrmQuery<T> |
setAutofetch(boolean autoFetch)
Explicitly specify whether to use Autofetch for this query.
|
DefaultOrmQuery<T> |
setAutoFetch(boolean autoFetch) |
void |
setAutoFetchManager(AutoFetchManager autoFetchManager)
This has the effect of turning on autoFetch profiling for this query.
|
void |
setAutoFetchTuned(boolean autoFetchTuned)
Set to true if this query has been tuned by autoFetch.
|
DefaultOrmQuery<T> |
setBackgroundFetchAfter(int backgroundFetchAfter)
Set the rows after which fetching should continue in a background thread.
|
void |
setBeanCollectionTouched(BeanCollectionTouched notify)
Set a listener to be notified when the bean collection has been touched
(when the list/set/map is first used).
|
void |
setBeanDescriptor(BeanDescriptor<?> beanDescriptor)
Set the BeanDescriptor for the root type of this query.
|
Query<T> |
setBufferFetchSizeHint(int bufferFetchSizeHint)
A hint which for JDBC translates to the Statement.fetchSize().
|
void |
setCancelableQuery(CancelableQuery cancelableQuery)
Set the underlying cancelable query (with the PreparedStatement).
|
void |
setDefaultSelectClause()
Set default select clauses where none have been explicitly defined.
|
void |
setDetail(OrmQueryDetail detail)
Replace the query detail.
|
DefaultOrmQuery<T> |
setDistinct(boolean isDistinct)
Set whether this query uses DISTINCT.
|
void |
setFilterMany(String prop,
ExpressionList<?> filterMany)
Set a filter to a join path.
|
DefaultOrmQuery<T> |
setFirstRow(int firstRow)
Set the first row to return for this query.
|
DefaultOrmQuery<T> |
setForUpdate(boolean forUpdate)
executed the select with "for update" which should lock the record
"on read"
|
void |
setFutureFetch(boolean backgroundFetch)
Set to true to indicate the query is executing in a background thread
asynchronously.
|
void |
setGeneratedSql(String generatedSql)
Set the generated sql for debug purposes.
|
DefaultOrmQuery<T> |
setId(Object id)
Set the Id value to query.
|
void |
setIdList(List<Object> partialIds)
Set the list of Id's that is being populated.
|
void |
setIncludeTableJoin(TableJoin includeTableJoin) |
void |
setLazyLoadForParents(List<Object> parentIds,
BeanPropertyAssocMany<?> many)
This becomes a lazy loading query for a many relationship.
|
void |
setLazyLoadManyPath(String lazyLoadManyPath)
Set the path of the many when +query/+lazy loading query is executed.
|
void |
setLazyLoadProperty(String lazyLoadProperty)
Set the property that invoked the lazy load and MUST be included in the
lazy loading query.
|
DefaultOrmQuery<T> |
setListener(QueryListener<T> queryListener)
Set a FindListener.
|
DefaultOrmQuery<T> |
setLoadBeanCache(boolean loadBeanCache)
When set to true all the beans from this query are loaded into the bean
cache.
|
void |
setLoadDescription(String loadMode,
String loadDescription)
Set the load mode (+lazy or +query) and the load description.
|
DefaultOrmQuery<T> |
setMapKey(String mapKey)
Set the property to use as keys for a map.
|
DefaultOrmQuery<T> |
setMaxRows(int maxRows)
Set the maximum number of rows to return in the query.
|
void |
setMode(SpiQuery.Mode mode)
Set the query mode.
|
DefaultOrmQuery<T> |
setOrder(OrderBy<T> orderBy)
Set an OrderBy object to replace any existing OrderBy clause.
|
DefaultOrmQuery<T> |
setOrderBy(OrderBy<T> orderBy)
Set an OrderBy object to replace any existing OrderBy clause.
|
DefaultOrmQuery<T> |
setOrderBy(String orderByClause) |
ObjectGraphNode |
setOrigin(CallStack callStack)
Return the origin point for the query.
|
protected void |
setOrmQueryDetail(OrmQueryDetail detail) |
DefaultOrmQuery<T> |
setParameter(int position,
Object value)
Set an ordered bind parameter according to its position.
|
DefaultOrmQuery<T> |
setParameter(String name,
Object value)
Set a named bind parameter.
|
void |
setParentNode(ObjectGraphNode parentNode)
Set the profile point of the bean or collection that is lazy loading.
|
void |
setPersistenceContext(PersistenceContext persistenceContext)
Set an explicit TransactionContext (typically for a refresh query).
|
DefaultOrmQuery<T> |
setProperties(String columns) |
DefaultOrmQuery<T> |
setQuery(String queryString) |
DefaultOrmQuery<T> |
setRawSql(RawSql rawSql)
Set RawSql to use for this query.
|
protected void |
setRawWhereClause(String rawWhereClause) |
DefaultOrmQuery<T> |
setReadOnly(boolean readOnly)
When set to true when you want the returned beans to be read only.
|
void |
setSelectId()
Set the select clause to select the Id property.
|
DefaultOrmQuery<T> |
setTimeout(int secs)
Set a timeout on this query.
|
void |
setTotalHits(int totalHits) |
void |
setType(SpiQuery.Type type)
Set the query type (List, Set etc).
|
void |
setUsageProfiling(boolean usageProfiling)
Set to false if this query should not be included in the autoFetch usage
profiling information.
|
DefaultOrmQuery<T> |
setUseCache(boolean useBeanCache)
Set this to true to use the bean cache.
|
DefaultOrmQuery<T> |
setUseQueryCache(boolean useQueryCache)
Set this to true to use the query cache.
|
String |
toString() |
boolean |
tuneFetchProperties(OrmQueryDetail tunedDetail)
Autofetch tune the detail specifying properties to select on already defined joins
and adding extra joins where they are missing.
|
ExpressionList<T> |
where()
Add Expressions to the where clause with the ability to chain on the
ExpressionList.
|
DefaultOrmQuery<T> |
where(Expression expression)
Add a single Expression to the where clause returning the query.
|
DefaultOrmQuery<T> |
where(String addToWhereClause)
Add additional clause(s) to the where clause.
|
selectAllForLazyLoadProperty in interface SpiQuery<T>public DefaultOrmQuery(Class<T> beanType, EbeanServer server, ExpressionFactory expressionFactory, String query)
public DefaultOrmQuery(Class<T> beanType, EbeanServer server, ExpressionFactory expressionFactory, DeployNamedQuery namedQuery) throws javax.persistence.PersistenceException
javax.persistence.PersistenceExceptionpublic int getTotalHits()
public void setTotalHits(int totalHits)
public void setBeanDescriptor(BeanDescriptor<?> beanDescriptor)
setBeanDescriptor in interface SpiQuery<T>public boolean selectAllForLazyLoadProperty()
selectAllForLazyLoadProperty in interface SpiQuery<T>public RawSql getRawSql()
Querypublic DefaultOrmQuery<T> setRawSql(RawSql rawSql)
Querypublic String getLazyLoadProperty()
SpiQuerygetLazyLoadProperty in interface SpiQuery<T>public void setLazyLoadProperty(String lazyLoadProperty)
SpiQuerysetLazyLoadProperty in interface SpiQuery<T>public String getLazyLoadManyPath()
SpiQuerygetLazyLoadManyPath in interface SpiQuery<T>public ExpressionFactory getExpressionFactory()
QuerygetExpressionFactory in interface Query<T>public boolean initManyWhereJoins()
initManyWhereJoins in interface SpiQuery<T>public ManyWhereJoins getManyWhereJoins()
SpiQuerygetManyWhereJoins in interface SpiQuery<T>public List<OrmQueryProperties> removeQueryJoins()
SpiQueryThese are registered with the Load Context.
removeQueryJoins in interface SpiQuery<T>public List<OrmQueryProperties> removeLazyJoins()
SpiQueryThese are registered with the Load Context.
removeLazyJoins in interface SpiQuery<T>public void setLazyLoadManyPath(String lazyLoadManyPath)
SpiQuerysetLazyLoadManyPath in interface SpiQuery<T>public void convertManyFetchJoinsToQueryJoins(boolean allowOne,
int queryBatch)
convertManyFetchJoinsToQueryJoins in interface SpiQuery<T>public void setSelectId()
setSelectId in interface SpiQuery<T>public void convertWhereNaturalKeyToId(Object idValue)
SpiQueryconvertWhereNaturalKeyToId in interface SpiQuery<T>public NaturalKeyBindParam getNaturalKeyBindParam()
SpiQuerygetNaturalKeyBindParam in interface SpiQuery<T>public DefaultOrmQuery<T> copy()
SpiQuerypublic SpiQuery.Type getType()
SpiQuerypublic void setType(SpiQuery.Type type)
SpiQuerypublic String getLoadDescription()
SpiQuerygetLoadDescription in interface SpiQuery<T>public String getLoadMode()
SpiQuerygetLoadMode in interface SpiQuery<T>public void setLoadDescription(String loadMode, String loadDescription)
SpiQuerysetLoadDescription in interface SpiQuery<T>public PersistenceContext getPersistenceContext()
If no TransactionContext is present on the query then the TransactionContext from the Transaction is used (transaction scoped persistence context).
getPersistenceContext in interface SpiQuery<T>public void setPersistenceContext(PersistenceContext persistenceContext)
If no TransactionContext is present on the query then the TransactionContext from the Transaction is used (transaction scoped persistence context).
setPersistenceContext in interface SpiQuery<T>public void setLazyLoadForParents(List<Object> parentIds, BeanPropertyAssocMany<?> many)
SpiQuerysetLazyLoadForParents in interface SpiQuery<T>public List<Object> getLazyLoadForParentIds()
SpiQuerygetLazyLoadForParentIds in interface SpiQuery<T>public BeanPropertyAssocMany<?> getLazyLoadForParentsProperty()
SpiQuerygetLazyLoadForParentsProperty in interface SpiQuery<T>public boolean isDetailEmpty()
isDetailEmpty in interface SpiQuery<T>public boolean isAutofetchTuned()
QueryisAutofetchTuned in interface Query<T>public void setAutoFetchTuned(boolean autoFetchTuned)
SpiQuerysetAutoFetchTuned in interface SpiQuery<T>public Boolean isAutofetch()
SpiQueryisAutofetch in interface SpiQuery<T>public boolean isForUpdate()
QueryisForUpdate in interface Query<T>public DefaultOrmQuery<T> setAutoFetch(boolean autoFetch)
public DefaultOrmQuery<T> setAutofetch(boolean autoFetch)
QueryIf you do not call this method on a query the "Implicit Autofetch mode" is used to determine if Autofetch should be used for a given query.
Autofetch can add additional fetch paths to the query and specify which properties are included for each path. If you have explicitly defined some fetch paths Autofetch will not remove.
setAutofetch in interface Query<T>public DefaultOrmQuery<T> setForUpdate(boolean forUpdate)
QuerysetForUpdate in interface Query<T>public AutoFetchManager getAutoFetchManager()
SpiQuerygetAutoFetchManager in interface SpiQuery<T>public void setAutoFetchManager(AutoFetchManager autoFetchManager)
SpiQuerysetAutoFetchManager in interface SpiQuery<T>public SpiQuery.Mode getMode()
SpiQuerypublic void setMode(SpiQuery.Mode mode)
SpiQuerypublic boolean isUsageProfiling()
SpiQueryWe just take/copy the data from those beans and don't collect autoFetch usage profiling on those lazy load or refresh beans.
isUsageProfiling in interface SpiQuery<T>public void setUsageProfiling(boolean usageProfiling)
SpiQuerysetUsageProfiling in interface SpiQuery<T>public void setParentNode(ObjectGraphNode parentNode)
SpiQueryThis enables use to hook this back to the original 'root' query by the queryPlanHash and stackPoint.
setParentNode in interface SpiQuery<T>public ObjectGraphNode getParentNode()
SpiQueryThis will return null or an "original" query.
getParentNode in interface SpiQuery<T>public ObjectGraphNode setOrigin(CallStack callStack)
SpiQueryThis MUST be call prior to a query being changed via tuning. This is because the queryPlanHash is used to identify the query point.
public HashQueryPlan queryAutofetchHash(HashQueryPlanBuilder builder)
queryAutofetchHash in interface SpiQuery<T>public HashQueryPlan queryPlanHash(BeanQueryRequest<?> request)
This can used to enable the caching and reuse of a 'query plan'.
This is calculated AFTER AutoFetch query tuning has occurred.
queryPlanHash in interface SpiQuery<T>public int queryBindHash()
Used with queryPlanHash() to get a unique hash for a query.
queryBindHash in interface SpiQuery<T>public HashQuery queryHash()
This hash can be used to identify if we have executed the exact same query (including bind values) before.
public String getName()
public boolean isSqlSelect()
SpiQueryisSqlSelect in interface SpiQuery<T>public boolean isRawSql()
SpiQuerypublic String getAdditionalWhere()
getAdditionalWhere in interface SpiQuery<T>public int getTimeout()
getTimeout in interface SpiQuery<T>public String getAdditionalHaving()
getAdditionalHaving in interface SpiQuery<T>public boolean hasMaxRowsOrFirstRow()
SpiQueryhasMaxRowsOrFirstRow in interface SpiQuery<T>public Boolean isReadOnly()
SpiQueryisReadOnly in interface SpiQuery<T>public DefaultOrmQuery<T> setReadOnly(boolean readOnly)
QuerysetReadOnly in interface Query<T>public Boolean isUseBeanCache()
SpiQueryisUseBeanCache in interface SpiQuery<T>public boolean isUseQueryCache()
SpiQueryisUseQueryCache in interface SpiQuery<T>public DefaultOrmQuery<T> setUseCache(boolean useBeanCache)
QueryIf the query result is in cache then by default this same instance is returned. In this sense it should be treated as a read only object graph.
setUseCache in interface Query<T>public DefaultOrmQuery<T> setUseQueryCache(boolean useQueryCache)
QuerysetUseQueryCache in interface Query<T>public boolean isLoadBeanCache()
SpiQueryisLoadBeanCache in interface SpiQuery<T>public DefaultOrmQuery<T> setLoadBeanCache(boolean loadBeanCache)
QuerysetLoadBeanCache in interface Query<T>public DefaultOrmQuery<T> setTimeout(int secs)
QueryThis will typically result in a call to setQueryTimeout() on a preparedStatement. If the timeout occurs an exception will be thrown - this will be a SQLException wrapped up in a PersistenceException.
setTimeout in interface Query<T>secs - the query timeout limit in seconds. Zero means there is no limit.public DefaultOrmQuery<T> setQuery(String queryString) throws javax.persistence.PersistenceException
javax.persistence.PersistenceExceptionprotected void setOrmQueryDetail(OrmQueryDetail detail)
protected void setRawWhereClause(String rawWhereClause)
public DefaultOrmQuery<T> setProperties(String columns)
public void setDefaultSelectClause()
SpiQuerysetDefaultSelectClause in interface SpiQuery<T>public DefaultOrmQuery<T> select(String columns)
Query
Query<Customer> query = Ebean.createQuery(Customer.class);
// Only fetch the customer id, name and status.
// This is described as a "Partial Object"
query.select("name, status");
query.where("lower(name) like :custname").setParameter("custname", "rob%");
List<Customer> customerList = query.findList();
public DefaultOrmQuery<T> fetch(String property)
Query
The same as Query.fetch(String, String) with the fetchProperties as "*".
public DefaultOrmQuery<T> fetch(String property, FetchConfig joinConfig)
Querypublic DefaultOrmQuery<T> fetch(String property, String columns)
QueryWhen you specify a join this means that property (associated bean(s)) will be fetched and populated. If you specify "*" then all the properties of the associated bean will be fetched and populated. You can specify a comma delimited list of the properties of that associated bean which means that only those properties are fetched and populated resulting in a "Partial Object" - a bean that only has some of its properties populated.
// query orders...
Query<Order> query = Ebean.createQuery(Order.class);
// fetch the customer...
// ... getting the customer's name and phone number
query.fetch("customer", "name, phNumber");
// ... also fetch the customers billing address (* = all properties)
query.fetch("customer.billingAddress", "*");
If columns is null or "*" then all columns/properties for that path are fetched.
// fetch customers (their id, name and status)
Query<Customer> query = Ebean.createQuery(Customer.class);
// only fetch some of the properties of the customers
query.select("name, status");
List<Customer> list = query.findList();
public DefaultOrmQuery<T> fetch(String property, String columns, FetchConfig config)
Querypublic List<Object> findIds()
QueryThis query will execute against the EbeanServer that was used to create it.
findIds in interface Query<T>EbeanServer.findIds(Query, Transaction)public int findRowCount()
QueryThis is the number of 'top level' or 'root level' entities.
findRowCount in interface Query<T>public void findVisit(QueryResultVisitor<T> visitor)
QuerySimilar to findIterate() this query method does not require all the result beans to be all held in memory at once and as such is useful for processing large queries.
Query<Customer> query = server.find(Customer.class)
.fetch("contacts", new FetchConfig().query(2))
.where().gt("id", 0)
.orderBy("id")
.setMaxRows(2);
query.findVisit(new QueryResultVisitor<Customer>() {
public boolean accept(Customer customer) {
// do something with customer
System.out.println("-- visit " + customer);
return true;
}
});
public QueryIterator<T> findIterate()
Query
Remember that with QueryIterator you must call
QueryIterator.close() when you have finished iterating the results
(typically in a finally block).
This query will execute against the EbeanServer that was used to create it.
findIterate in interface Query<T>public List<T> findList()
QueryThis query will execute against the EbeanServer that was used to create it.
findList in interface Query<T>EbeanServer.findList(Query, Transaction)public Set<T> findSet()
QueryThis query will execute against the EbeanServer that was used to create it.
findSet in interface Query<T>EbeanServer.findSet(Query, Transaction)public Map<?,T> findMap()
QueryThis query will execute against the EbeanServer that was used to create it.
You can use setMapKey() so specify the property values to be used as keys on the map. If one is not specified then the id property is used.
Query<Product> query = Ebean.createQuery(Product.class);
query.setMapKey("sku");
Map<?, Product> map = query.findMap();
findMap in interface Query<T>EbeanServer.findMap(Query, Transaction)public <K> Map<K,T> findMap(String keyProperty, Class<K> keyType)
Querypublic T findUnique()
QueryIf more than 1 row is found for this query then a PersistenceException is thrown.
This is useful when your predicates dictate that your query should only return 0 or 1 results.
// assuming the sku of products is unique...
Product product =
Ebean.find(Product.class)
.where("sku = ?")
.set(1, "aa113")
.findUnique();
...
It is also useful with finding objects by their id when you want to specify further join information.
// Fetch order 1 and additionally fetch join its order details...
Order order =
Ebean.find(Order.class)
.setId(1)
.fetch("details")
.findUnique();
List<OrderDetail> details = order.getDetails();
...
findUnique in interface Query<T>public FutureIds<T> findFutureIds()
QueryThis returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).
findFutureIds in interface Query<T>public FutureList<T> findFutureList()
QueryThis returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).
findFutureList in interface Query<T>public FutureRowCount<T> findFutureRowCount()
QueryThis returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).
findFutureRowCount in interface Query<T>public PagingList<T> findPagingList(int pageSize)
QueryThis can be used to break up a query into multiple queries to fetch the data a page at a time.
This typically works by using a query per page and setting
Query.setFirstRow(int) and and Query.setMaxRows(int) on the
query. This usually would translate into SQL that uses limit offset, rownum
or row_number function to limit the result set.
findPagingList in interface Query<T>pageSize - the number of beans fetched per Pagepublic DefaultOrmQuery<T> setParameter(int position, Object value)
setParameter in interface Query<T>position - the parameter bind position starting from 1 (not 0)value - the parameter bind value.public DefaultOrmQuery<T> setParameter(String name, Object value)
setParameter in interface Query<T>name - the parameter namevalue - the parameter valuepublic OrderBy<T> getOrderBy()
SpiQuerygetOrderBy in interface SpiQuery<T>public String getRawWhereClause()
getRawWhereClause in interface SpiQuery<T>public OrderBy<T> orderBy()
QueryThis will never return a null. If no order by clause exists then an 'empty' OrderBy object is returned.
This is EXACTLY the same as Query.order().
public OrderBy<T> order()
QueryThis will never return a null. If no order by clause exists then an 'empty' OrderBy object is returned.
This is EXACTLY the same as Query.orderBy().
public DefaultOrmQuery<T> setOrderBy(String orderByClause)
public DefaultOrmQuery<T> orderBy(String orderByClause)
QueryThis follows SQL syntax using commas between each property with the optional asc and desc keywords representing ascending and descending order respectively.
This is EXACTLY the same as Query.order(String).
public DefaultOrmQuery<T> order(String orderByClause)
QueryThis follows SQL syntax using commas between each property with the optional asc and desc keywords representing ascending and descending order respectively.
This is EXACTLY the same as Query.orderBy(String).
public DefaultOrmQuery<T> setOrderBy(OrderBy<T> orderBy)
Query
This is EXACTLY the same as Query.setOrder(OrderBy).
setOrderBy in interface Query<T>public DefaultOrmQuery<T> setOrder(OrderBy<T> orderBy)
Query
This is EXACTLY the same as Query.setOrderBy(OrderBy).
public boolean isDistinct()
isDistinct in interface SpiQuery<T>public DefaultOrmQuery<T> setDistinct(boolean isDistinct)
setDistinct in interface Query<T>public QueryListener<T> getListener()
getListener in interface SpiQuery<T>public DefaultOrmQuery<T> setListener(QueryListener<T> queryListener)
Note that the returning List Set or Map will be empty.
setListener in interface Query<T>public Class<T> getBeanType()
SpiQuerygetBeanType in interface SpiQuery<T>public void setDetail(OrmQueryDetail detail)
SpiQueryNote care must be taken to keep the where, orderBy, firstRows and maxRows held in the detail attributes.
public boolean tuneFetchProperties(OrmQueryDetail tunedDetail)
SpiQuerytuneFetchProperties in interface SpiQuery<T>public OrmQueryDetail getDetail()
SpiQuerypublic final ArrayList<EntityBean> getContextAdditions()
getContextAdditions in interface SpiQuery<T>public void contextAdd(EntityBean bean)
These are added to the persistence context before executing the query.
contextAdd in interface SpiQuery<T>public TableJoin getIncludeTableJoin()
getIncludeTableJoin in interface SpiQuery<T>public void setIncludeTableJoin(TableJoin includeTableJoin)
setIncludeTableJoin in interface SpiQuery<T>public int getFirstRow()
SpiQuerygetFirstRow in interface Query<T>getFirstRow in interface SpiQuery<T>public DefaultOrmQuery<T> setFirstRow(int firstRow)
QuerysetFirstRow in interface Query<T>public int getMaxRows()
SpiQuerygetMaxRows in interface Query<T>getMaxRows in interface SpiQuery<T>public DefaultOrmQuery<T> setMaxRows(int maxRows)
QuerysetMaxRows in interface Query<T>maxRows - the maximum number of rows to return in the query.public String getMapKey()
SpiQuerypublic DefaultOrmQuery<T> setMapKey(String mapKey)
QueryIf no property is set then the id property is used.
// Assuming sku is unique for products...
Query<Product> query = Ebean.createQuery(Product.class);
// use sku for keys...
query.setMapKey("sku");
Map<?,Product> productMap = query.findMap();
...
public int getBackgroundFetchAfter()
SpiQuerygetBackgroundFetchAfter in interface SpiQuery<T>public DefaultOrmQuery<T> setBackgroundFetchAfter(int backgroundFetchAfter)
QuerysetBackgroundFetchAfter in interface Query<T>public DefaultOrmQuery<T> setId(Object id)
QueryYou can use this to have further control over the query. For example adding fetch joins.
Query<Order> query = Ebean.createQuery(Order.class);
Order order = query.setId(1).join("details").findUnique();
List<OrderDetail> details = order.getDetails();
...
public BindParams getBindParams()
SpiQuerygetBindParams in interface SpiQuery<T>public String getQuery()
SpiQuerypublic DefaultOrmQuery<T> addWhere(String addToWhereClause)
public DefaultOrmQuery<T> addWhere(Expression expression)
public ExpressionList<T> addWhere()
public DefaultOrmQuery<T> where(String addToWhereClause)
Query
This typically contains named parameters which will need to be set via
Query.setParameter(String, Object).
Query<Order> query = Ebean.createQuery(Order.class, "top");
...
if (...) {
query.where("status = :status and lower(customer.name) like :custName");
query.setParameter("status", Order.NEW);
query.setParameter("custName", "rob%");
}
Internally the addToWhereClause string is processed by removing named parameters (replacing them with ?) and by converting logical property names to database column names (with table alias). The rest of the string is left as is and it is completely acceptable and expected for the addToWhereClause string to include sql functions and columns.
public DefaultOrmQuery<T> where(Expression expression)
Query
List<Order> newOrders =
Ebean.find(Order.class)
.where().eq("status", Order.NEW)
.findList();
...
public ExpressionList<T> where()
Query
Query<Order> query = Ebean.createQuery(Order.class, "top");
...
if (...) {
query.where()
.eq("status", Order.NEW)
.ilike("customer.name","rob%");
}
public ExpressionList<T> filterMany(String prop)
QueryTypically you will use this in a scenario where the cardinality is high on the 'many' property you wish to join to. Say you want to fetch customers and their associated orders... but instead of getting all the orders for each customer you only want to get the new orders they placed since last week. In this case you can use filterMany() to filter the orders.
List<Customer> list = Ebean
.find(Customer.class)
// .fetch("orders", new FetchConfig().lazy())
// .fetch("orders", new FetchConfig().query())
.fetch("orders").where().ilike("name", "rob%").filterMany("orders")
.eq("status", Order.Status.NEW).gt(
"orderDate", lastWeek).findList();
Please note you have to be careful that you add expressions to the correct expression list - as there is one for the 'root level' and one for each filterMany that you have.
filterMany in interface Query<T>prop - the name of the many property that you want to have a filter on.public void setFilterMany(String prop, ExpressionList<?> filterMany)
SpiQuerysetFilterMany in interface SpiQuery<T>public DefaultOrmQuery<T> addHaving(String addToHavingClause)
public DefaultOrmQuery<T> addHaving(Expression expression)
public ExpressionList<T> addHaving()
public DefaultOrmQuery<T> having(String addToHavingClause)
Query
This typically contains named parameters which will need to be set via
Query.setParameter(String, Object).
Query<ReportOrder> query = Ebean.createQuery(ReportOrder.class);
...
if (...) {
query.having("score > :min");
query.setParameter("min", 1);
}
public DefaultOrmQuery<T> having(Expression expression)
QueryCurrently only beans based on raw sql will use the having clause.
This is similar to Query.having() except it returns the query rather
than the ExpressionList. This is useful when you want to further specify
something on the query.
public ExpressionList<T> having()
QueryCurrently only beans based on raw sql will use the having clause.
Note that this returns the ExpressionList (so you can add multiple expressions to the query in a fluent API way).
public SpiExpressionList<T> getHavingExpressions()
SpiQuerygetHavingExpressions in interface SpiQuery<T>public SpiExpressionList<T> getWhereExpressions()
SpiQuerygetWhereExpressions in interface SpiQuery<T>public boolean createOwnTransaction()
createOwnTransaction in interface SpiQuery<T>public String getGeneratedSql()
QueryThis is only available after the query has been executed and provided only for informational purposes.
getGeneratedSql in interface Query<T>public void setGeneratedSql(String generatedSql)
SpiQuerysetGeneratedSql in interface SpiQuery<T>public Query<T> setBufferFetchSizeHint(int bufferFetchSizeHint)
QueryGives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet.
setBufferFetchSizeHint in interface Query<T>public int getBufferFetchSizeHint()
SpiQuerygetBufferFetchSizeHint in interface SpiQuery<T>public void setBeanCollectionTouched(BeanCollectionTouched notify)
SpiQuerysetBeanCollectionTouched in interface SpiQuery<T>public BeanCollectionTouched getBeanCollectionTouched()
SpiQuerygetBeanCollectionTouched in interface SpiQuery<T>public List<Object> getIdList()
SpiQuerypublic void setIdList(List<Object> partialIds)
SpiQueryThis is a mutating list of id's and we are setting this so that other threads have access to the id's before the id query has finished.
public boolean isFutureFetch()
SpiQueryisFutureFetch in interface SpiQuery<T>public void setFutureFetch(boolean backgroundFetch)
SpiQuerysetFutureFetch in interface SpiQuery<T>public void setCancelableQuery(CancelableQuery cancelableQuery)
SpiQuerysetCancelableQuery in interface SpiQuery<T>public void cancel()
QueryThis must be called from a different thread to the query executor.
public boolean isCancelled()
SpiQueryisCancelled in interface SpiQuery<T>Copyright © 2014. All Rights Reserved.