Class DefaultOrmQuery<T>
- java.lang.Object
-
- io.ebeaninternal.server.querydefn.DefaultOrmQuery<T>
-
- All Implemented Interfaces:
Query<T>
,SpiQuery<T>
,TxnProfileEventCodes
public class DefaultOrmQuery<T> extends Object implements SpiQuery<T>
Default implementation of an Object Relational query.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.ebean.Query
Query.ForUpdate
-
Nested classes/interfaces inherited from interface io.ebeaninternal.api.SpiQuery
SpiQuery.Mode, SpiQuery.TemporalMode, SpiQuery.Type
-
-
Field Summary
-
Fields inherited from interface io.ebeaninternal.api.TxnProfileEventCodes
EVT_CALLABLESQL, EVT_COMMIT, EVT_DELETE, EVT_DELETE_PERMANENT, EVT_DELETE_SOFT, EVT_INSERT, EVT_ORMUPDATE, EVT_ROLLBACK, EVT_UPDATE, EVT_UPDATESQL, FIND_ATTRIBUTE, FIND_COUNT, FIND_DELETE, FIND_ID_LIST, FIND_ITERATE, FIND_MANY, FIND_MANY_LAZY, FIND_ONE, FIND_ONE_LAZY, FIND_SUBQUERY, FIND_UPDATE
-
-
Constructor Summary
Constructors Constructor Description DefaultOrmQuery(BeanDescriptor<T> desc, SpiEbeanServer server, ExpressionFactory expressionFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addSoftDeletePredicate(String softDeletePredicate)
DefaultOrmQuery<T>
alias(String alias)
Set root table alias.Query<T>
apply(FetchPath fetchPath)
Apply the path properties replacing the select and fetch clauses.DefaultOrmQuery<T>
asDraft()
Execute the query against the draft set of tables.<D> DtoQuery<D>
asDto(Class<D> dtoClass)
Convert the query to a DTO bean query.DefaultOrmQuery<T>
asOf(Timestamp asOfDateTime)
Perform an 'As of' query using history tables to return the object graph as of a time in the past.UpdateQuery<T>
asUpdate()
Convert the query to a UpdateQuery.CacheIdLookup<T>
cacheIdLookup()
Bean cache lookup for find by ids.void
cancel()
Cancel the query execution if supported by the underlying database and driver.void
checkNamedParameters()
Check that the named parameters have had their values set.boolean
checkPagingOrderBy()
Return true if the query should have an order by appended automatically.SpiQuerySecondary
convertJoins()
Convert joins as necessary to query joins etc.DefaultOrmQuery<T>
copy()
Return a copy of the query.DefaultOrmQuery<T>
copy(SpiEbeanServer server)
Return a copy of the query attaching to a different EbeanServer.SpiNamedParam
createNamedParameter(String name)
Create a named parameter placeholder.int
delete()
Execute as a delete query deleting the 'root level' beans that match the predicates in the query.int
delete(Transaction transaction)
Execute as a delete query returning the number of rows deleted using the given transaction.boolean
exists()
Execute the query returning true if a row is found.DefaultOrmQuery<T>
fetch(String property)
Specify a path to fetch eagerly 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 eagerly including specific properties.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.Query<T>
fetchCache(String property)
Fetch the path eagerly using L2 cache.Query<T>
fetchCache(String property, String columns)
Fetch the path and properties using L2 bean cache.Query<T>
fetchLazy(String property)
Fetch the path lazily (via batch lazy loading).Query<T>
fetchLazy(String property, String columns)
Fetch the path and properties lazily (via batch lazy loading).Query<T>
fetchQuery(String property)
Fetch the path eagerly using a "query join" (separate SQL query).Query<T>
fetchQuery(String property, String columns)
Fetch the path and properties using a "query join" (separate SQL query).ExpressionList<T>
filterMany(String prop)
This applies a filter on the 'many' property list rather than the root level objects.int
findCount()
Return the count of entities this query should return.void
findEach(Consumer<T> consumer)
Execute the query processing the beans one at a time.void
findEachWhile(Predicate<T> consumer)
Execute the query using callbacks to a visitor to process the resulting beans one at a time.FutureRowCount<T>
findFutureCount()
Execute find row count query in a background thread.FutureIds<T>
findFutureIds()
Execute find Id's query in a background thread.FutureList<T>
findFutureList()
Execute find list query in a background thread.<A> List<A>
findIds()
Execute the query returning the list of Id's.QueryIterator<T>
findIterate()
Execute the query iterating over the results.Stream<T>
findLargeStream()
Execute the query returning the result as a Stream.List<T>
findList()
Execute the query returning the list of objects.<K> Map<K,T>
findMap()
Execute the query returning a map of the objects.T
findOne()
Execute the query returning either a single bean or null (if no matching bean is found).Optional<T>
findOneOrEmpty()
Execute the query returning an optional bean.PagedList<T>
findPagedList()
Return a PagedList for this query using firstRow and maxRows.Set<T>
findSet()
Execute the query returning the set of objects.<A> A
findSingleAttribute()
Execute a query returning a single value of a single property/column.<A> List<A>
findSingleAttributeList()
Execute the query returning a list of values for a single property.Stream<T>
findStream()
Execute the query returning the result as a Stream.List<Version<T>>
findVersions()
Return versions of a @History entity bean.List<Version<T>>
findVersionsBetween(Timestamp start, Timestamp end)
Return versions of a @History entity bean between the 2 timestamps.DefaultOrmQuery<T>
forUpdate()
Execute using "for update" clause which results in the DB locking the record.DefaultOrmQuery<T>
forUpdateNoWait()
Execute using "for update" clause with "no wait" option.DefaultOrmQuery<T>
forUpdateSkipLocked()
Execute using "for update" clause with "skip locked" option.String
getAlias()
Return root table alias set byQuery.alias(String)
command.Timestamp
getAsOf()
Return the asOf Timestamp which the query should run as.int
getAsOfTableCount()
Return the table alias used for the base table.String
getBaseTable()
Return the base table to use if user defined on the query.BeanDescriptor<T>
getBeanDescriptor()
Return the bean descriptor for this query.Class<T>
getBeanType()
Return the type of beans being queried.BindParams
getBindParams()
Return the bind parameters.int
getBufferFetchSizeHint()
Return the hint for Statement.setFetchSize().CountDistinctOrder
getCountDistinctOrder()
Returns the count distinct order setting.OrmQueryDetail
getDetail()
Return the query detail.String
getDocIndexName()
For doc store query return the document index name to search against.ExpressionFactory
getExpressionFactory()
Return the ExpressionFactory used by this query.int
getFirstRow()
Return the index of the first row to return in the query.Query.ForUpdate
getForUpdateMode()
Return the ForUpdate mode.ReadEvent
getFutureFetchAudit()
Read the readEvent for future queries (null otherwise).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.Class<? extends T>
getInheritType()
Returns the inherit type.String
getLabel()
Return the label set on the query.int
getLazyLoadBatchSize()
Return the default lazy load batch size.BeanPropertyAssocMany<?>
getLazyLoadMany()
Return the lazy loading 'many' property.String
getLazyLoadProperty()
Return the property that invoked lazy load.String
getLoadDescription()
Return a more detailed description of the lazy or query load.String
getLoadMode()
Return the load mode (+lazy or +query).TableJoin
getM2mIncludeJoin()
Return the extra join for a M2M lazy load.ManyWhereJoins
getManyWhereJoins()
Return the extra joins required to support the where clause for '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
getNativeSql()
Return the unmodified native sql query (with named params etc).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.String
getOriginKey()
Return the origin key.ObjectGraphNode
getParentNode()
Used to hook back a lazy loading query to the original query (query point).PersistenceContext
getPersistenceContext()
Return the TransactionContext.PersistenceContextScope
getPersistenceContextScope()
Return the PersistenceContextScope that this query should use.String
getPlanLabel()
Return the label manually set on the query or from the profile location.String
getProfileId()
Return the id used to identify a particular query for the given bean type.ProfileLocation
getProfileLocation()
Return the profile location for this query.ProfilingListener
getProfilingListener()
If return null then no profiling for this query.Object
getQueryPlanKey()
Return the query plan key.QueryType
getQueryType()
Return the type of query being executed.SpiRawSql
getRawSql()
Return the RawSql that was set to use for this query.List<String>
getSoftDeletePredicates()
SpiQuery.TemporalMode
getTemporalMode()
Return the Temporal mode for the query.Object
getTenantId()
Return the tenantId to use for lazy loading.SpiExpressionList<T>
getTextExpression()
Return the text expressions.int
getTimeout()
Return the timeout.SpiQuery.Type
getType()
Return the type of query (List, Set, Map, Bean, rowCount etc).OrmUpdateProperties
getUpdateProperties()
Return the properties for an update query.CacheMode
getUseBeanCache()
Return the cache mode for using the bean cache (Get and Put).CacheMode
getUseQueryCache()
Return the cache mode if this query should use/check the query cache.Timestamp
getVersionEnd()
Return the find versions end timestamp.Timestamp
getVersionStart()
Return the find versions start timestamp.SpiExpressionList<T>
getWhereExpressions()
Can return null if no expressions where added to the where clause.void
handleLoadError(String fullName, Exception e)
Handles load errors.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.void
incrementAsOfTableCount()
Increment the counter of tables used in 'As Of' query.boolean
isAsDraft()
Return true if this is a 'As Draft' query.boolean
isAsOfBaseTable()
Return true if the base table is using history.boolean
isAsOfQuery()
Return true if this is a 'As Of' query.boolean
isAutoTunable()
Return true if AutoTune should be attempted on this query.Boolean
isAutoTune()
Return explicit AutoTune setting or null.boolean
isAutoTuned()
Returns true if this query was tuned by autoTune.boolean
isBeanCacheGet()
Return true if the query should GET against bean cache.boolean
isBeanCachePut()
Return true if the query should PUT against the bean cache.boolean
isCancelled()
Return true if this query has been cancelled.boolean
isCountDistinct()
Return true if this is countDistinct query.boolean
isDetailEmpty()
Return true if the query detail has neither select or joins specified.boolean
isDisableLazyLoading()
Return true if lazy loading has been disabled on the query.boolean
isDisableReadAudit()
Return true if read auditing is disabled on this query.boolean
isDistinct()
return true if user specified to use SQL DISTINCT (effectively excludes id property).boolean
isFindAll()
Return true if this is a "find all" query.boolean
isFindById()
Return true if this is a "find by id" query.boolean
isForceHitDatabase()
Return true if we must hit the DB (Cache reload or select for update).boolean
isForUpdate()
Return true if this query has forUpdate set.boolean
isFutureFetch()
Return true if this is a query executing in the background.boolean
isIncludeSoftDeletes()
Return true if this query includes soft deleted rows.boolean
isManualId()
Return true if the Id property is manually included in the query (DTO queries).boolean
isNativeSql()
Return true if this is a native sql query.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
isSingleAttribute()
Return true if this is a single attribute query.boolean
isUsageProfiling()
Return false when this is a lazy load or refresh query for a bean.boolean
isUseDocStore()
Return true if this query should be executed against the doc store.boolean
isVersionsBetween()
Return true if this is a find versions between query.boolean
isWithId()
Return true if the Id should be included in the query.NaturalKeyQueryData<T>
naturalKey()
Collect natural key data for this query or null if the query does not match the requirements of natural key lookup.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()
Deprecated.DefaultOrmQuery<T>
orderBy(String orderByClause)
Deprecated.Query<T>
orderById(boolean orderById)
Controls, if paginated queries should always append an 'order by id' statement at the end to guarantee a deterministic sort result.boolean
orderByIsEmpty()
Return true if there is no Order By clause.CQueryPlanKey
prepare(SpiOrmQueryRequest<T> request)
Prepare the query which prepares any expressions (sub-query expressions etc) and calculates the query plan key.void
prepareDocNested()
Prepare the query for docstore execution with nested paths.String
profileEventId()
Return the profile event id based on query mode and type.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.void
resetBeanCacheAutoMode(boolean findOne)
Reset AUTO mode to OFF for findList().DefaultOrmQuery<T>
select(FetchGroup<T> fetchGroup)
Apply the fetchGroup which defines what part of the object graph to load.DefaultOrmQuery<T>
select(String columns)
Specify the properties to fetch on the root level entity bean in comma delimited format.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>
setAllowLoadErrors()
Execute the query allowing properties with invalid JSON to be collected and not fail the query.void
setAsOfBaseTable()
Set when the base table is using history.DefaultOrmQuery<T>
setAutoTune(boolean autoTune)
Explicitly specify whether to use AutoTune for this query.void
setAutoTuned(boolean autoTuned)
Set to true if this query has been tuned by autoTune.Query<T>
setBaseTable(String baseTable)
Set the base table to use for this query.Query<T>
setBeanCacheMode(CacheMode beanCacheMode)
Set the mode to use the bean cache when executing 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).DefaultOrmQuery<T>
setCountDistinct(CountDistinctOrder countDistinctOrder)
Extended version for setDistinct in conjunction with "findSingleAttributeList";void
setDefaultFetchBuffer(int fetchSize)
Set the JDBC fetchSize buffer hint if not explicitly set.void
setDefaultRawSqlIfRequired()
If this is a RawSql based entity set the default RawSql if not set.void
setDefaultSelectClause()
Set default select clauses where none have been explicitly defined.CQueryPlanKey
setDeleteByIdsPlan()
Set the query to be delete by ids due to cascading delete.void
setDetail(OrmQueryDetail detail)
Replace the query detail.DefaultOrmQuery<T>
setDisableLazyLoading(boolean disableLazyLoading)
Set true if you want to disable lazy loading.Query<T>
setDisableReadAuditing()
Disable read auditing for this query.DefaultOrmQuery<T>
setDistinct(boolean distinct)
Internally set to use SQL DISTINCT on the query but still have id property included.Query<T>
setDocIndexName(String indexName)
Set the index(es) to search for a document store which uses partitions.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.void
setFutureFetch(boolean backgroundFetch)
Set to true to indicate the query is executing in a background thread asynchronously.void
setFutureFetchAudit(ReadEvent event)
Set the readEvent for future queries (as prepared in foreground thread).void
setGeneratedSql(String generatedSql)
Set the generated sql for debug purposes.DefaultOrmQuery<T>
setId(Object id)
Set the Id value to query.DefaultOrmQuery<T>
setIncludeSoftDeletes()
Execute the query including soft deleted rows.Query<T>
setInheritType(Class<? extends T> type)
Restrict the query to only return subtypes of the given inherit type.Query<T>
setLabel(String label)
Set a label on the query.Query<T>
setLazyLoadBatchSize(int lazyLoadBatchSize)
Set the default lazy loading batch size to use.void
setLazyLoadForParents(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>
setLoadBeanCache(boolean loadBeanCache)
Will be deprecated - migrate to use setBeanCacheMode(CacheMode.RECACHE).void
setLoadDescription(String loadMode, String loadDescription)
Set the load mode (+lazy or +query) and the load description.void
setM2MIncludeJoin(TableJoin m2mIncludeJoin)
Set the extra join for a M2M lazy load.void
setManualId()
Set to true when we only include the Id property if it is explicitly included in the select().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.void
setNativeSql(String nativeSql)
DefaultOrmQuery<T>
setOrder(OrderBy<T> orderBy)
Set an OrderBy object to replace any existing OrderBy clause.DefaultOrmQuery<T>
setOrderBy(OrderBy<T> orderBy)
Deprecated.ObjectGraphNode
setOrigin(CallOrigin callOrigin)
Return the origin point for the query.DefaultOrmQuery<T>
setParameter(int position, Object value)
Set an ordered bind parameter according to its position.DefaultOrmQuery<T>
setParameter(Object value)
Bind the next positioned parameter.DefaultOrmQuery<T>
setParameter(String name, Object value)
Set a named bind parameter.DefaultOrmQuery<T>
setParameters(Object... values)
Bind all the positioned parameters.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).Query<T>
setPersistenceContextScope(PersistenceContextScope scope)
Specify the PersistenceContextScope to use for this query.Query<T>
setProfileLocation(ProfileLocation profileLocation)
Set the profile location of this query.void
setProfilePath(String label, String relativePath, ProfileLocation profileLocation)
Set the on a secondary query given the label, relativePath and profile location of the parent query.void
setProfilingListener(ProfilingListener profilingListener)
This has the effect of turning on profiling for this query.DefaultOrmQuery<T>
setRawSql(RawSql rawSql)
Set RawSql to use for this query.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.void
setSingleAttribute()
Mark the query as selecting a single attribute.void
setTenantId(Object tenantId)
Set the tenantId to use for lazy loading.DefaultOrmQuery<T>
setTimeout(int secs)
Set a timeout on this query.void
setType(SpiQuery.Type type)
Set the query type (List, Set etc).void
setupForDeleteOrUpdate()
Setup to be a delete or update query.void
setUsageProfiling(boolean usageProfiling)
Set to false if this query should not be included in the AutoTune usage profiling information.DefaultOrmQuery<T>
setUseDocStore(boolean useDocStore)
Set to true if this query should execute against the doc store.DefaultOrmQuery<T>
setUseQueryCache(CacheMode useQueryCache)
Set theCacheMode
to use the query for executing this query.void
simplifyExpressions()
Simplify nested expression lists where possible.ExpressionList<T>
text()
Add Full text search expressions for Document store queries.String
toString()
boolean
tuneFetchProperties(OrmQueryDetail tunedDetail)
AutoTune tune the detail specifying properties to select on already defined joins and adding extra joins where they are missing.int
update()
Execute the UpdateQuery returning the number of rows updated.int
update(Transaction transaction)
Execute the UpdateQuery returning the number of rows updated using the given transaction.Query<T>
usingConnection(Connection connection)
Execute the query using the given connection.Query<T>
usingDatabase(Database database)
Execute the query using the given database.Query<T>
usingTransaction(Transaction transaction)
Execute the query using the given transaction.Set<String>
validate()
Returns the set of properties or paths that are unknown (do not map to known properties or paths).Set<String>
validate(BeanType<T> desc)
Validate all the expression properties/paths given the bean descriptor.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.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.ebean.Query
setUseCache, setUseQueryCache
-
-
-
-
Constructor Detail
-
DefaultOrmQuery
public DefaultOrmQuery(BeanDescriptor<T> desc, SpiEbeanServer server, ExpressionFactory expressionFactory)
-
-
Method Detail
-
setNativeSql
public void setNativeSql(String nativeSql)
-
asDto
public <D> DtoQuery<D> asDto(Class<D> dtoClass)
Description copied from interface:Query
Convert the query to a DTO bean query.We effectively use the underlying ORM query to build the SQL and then execute and map it into DTO beans.
-
asUpdate
public UpdateQuery<T> asUpdate()
Description copied from interface:Query
Convert the query to a UpdateQuery.Typically this is used with query beans to covert a query bean query into an UpdateQuery like the examples below.
int rowsUpdated = new QCustomer() .name.startsWith("Rob") .asUpdate() .set("active", false) .update();;
int rowsUpdated = new QContact() .notes.note.startsWith("Make Inactive") .email.endsWith("@foo.com") .customer.id.equalTo(42) .asUpdate() .set("inactive", true) .setRaw("email = lower(email)") .update();
-
getBeanDescriptor
public BeanDescriptor<T> getBeanDescriptor()
Description copied from interface:SpiQuery
Return the bean descriptor for this query.- Specified by:
getBeanDescriptor
in interfaceSpiQuery<T>
-
isFindAll
public boolean isFindAll()
Description copied from interface:SpiQuery
Return true if this is a "find all" query. Used to set a "find all" profile location if necessary.
-
isFindById
public boolean isFindById()
Description copied from interface:SpiQuery
Return true if this is a "find by id" query. This includes a check for a single "equal to" expression for the Id.- Specified by:
isFindById
in interfaceSpiQuery<T>
-
profileEventId
public String profileEventId()
Description copied from interface:SpiQuery
Return the profile event id based on query mode and type.- Specified by:
profileEventId
in interfaceSpiQuery<T>
-
getProfileId
public String getProfileId()
Description copied from interface:SpiQuery
Return the id used to identify a particular query for the given bean type.- Specified by:
getProfileId
in interfaceSpiQuery<T>
-
setProfileLocation
public Query<T> setProfileLocation(ProfileLocation profileLocation)
Description copied from interface:Query
Set the profile location of this query. This is used to relate query execution metrics back to a location like a specific line of code.- Specified by:
setProfileLocation
in interfaceQuery<T>
-
getLabel
public String getLabel()
Description copied from interface:SpiQuery
Return the label set on the query.
-
getPlanLabel
public String getPlanLabel()
Description copied from interface:SpiQuery
Return the label manually set on the query or from the profile location.- Specified by:
getPlanLabel
in interfaceSpiQuery<T>
-
setProfilePath
public void setProfilePath(String label, String relativePath, ProfileLocation profileLocation)
Description copied from interface:SpiQuery
Set the on a secondary query given the label, relativePath and profile location of the parent query.- Specified by:
setProfilePath
in interfaceSpiQuery<T>
-
setLabel
public Query<T> setLabel(String label)
Description copied from interface:Query
Set a label on the query.This label can be used to help identify query performance metrics but we can also use profile location enhancement on Finders so for some that would be a better option.
-
isAutoTunable
public boolean isAutoTunable()
Description copied from interface:SpiQuery
Return true if AutoTune should be attempted on this query.- Specified by:
isAutoTunable
in interfaceSpiQuery<T>
-
setUseDocStore
public DefaultOrmQuery<T> setUseDocStore(boolean useDocStore)
Description copied from interface:Query
Set to true if this query should execute against the doc store.When setting this you may also consider disabling lazy loading.
- Specified by:
setUseDocStore
in interfaceQuery<T>
-
isUseDocStore
public boolean isUseDocStore()
Description copied from interface:SpiQuery
Return true if this query should be executed against the doc store.- Specified by:
isUseDocStore
in interfaceSpiQuery<T>
-
apply
public Query<T> apply(FetchPath fetchPath)
Description copied from interface:Query
Apply the path properties replacing the select and fetch clauses.This is typically used when the FetchPath is applied to both the query and the JSON output.
-
addSoftDeletePredicate
public void addSoftDeletePredicate(String softDeletePredicate)
- Specified by:
addSoftDeletePredicate
in interfaceSpiQuery<T>
-
getSoftDeletePredicates
public List<String> getSoftDeletePredicates()
- Specified by:
getSoftDeletePredicates
in interfaceSpiQuery<T>
-
isAsOfBaseTable
public boolean isAsOfBaseTable()
Description copied from interface:SpiQuery
Return true if the base table is using history.- Specified by:
isAsOfBaseTable
in interfaceSpiQuery<T>
-
setAsOfBaseTable
public void setAsOfBaseTable()
Description copied from interface:SpiQuery
Set when the base table is using history.- Specified by:
setAsOfBaseTable
in interfaceSpiQuery<T>
-
setAllowLoadErrors
public DefaultOrmQuery<T> setAllowLoadErrors()
Description copied from interface:Query
Execute the query allowing properties with invalid JSON to be collected and not fail the query.// fetch a bean with JSON content EBasicJsonList bean= DB.find(EBasicJsonList.class) .setId(42) .setAllowLoadErrors() // collect errors into bean state if we have invalid JSON .findOne(); // get the invalid JSON errors from the bean state Map<String, Exception> errors = server().getBeanState(bean).getLoadErrors(); // If this map is not empty tell we have invalid JSON // and should try and fix the JSON content or inform the user
- Specified by:
setAllowLoadErrors
in interfaceQuery<T>
-
incrementAsOfTableCount
public void incrementAsOfTableCount()
Description copied from interface:SpiQuery
Increment the counter of tables used in 'As Of' query.- Specified by:
incrementAsOfTableCount
in interfaceSpiQuery<T>
-
getAsOfTableCount
public int getAsOfTableCount()
Description copied from interface:SpiQuery
Return the table alias used for the base table.- Specified by:
getAsOfTableCount
in interfaceSpiQuery<T>
-
getAsOf
public Timestamp getAsOf()
Description copied from interface:SpiQuery
Return the asOf Timestamp which the query should run as.
-
asOf
public DefaultOrmQuery<T> asOf(Timestamp asOfDateTime)
Description copied from interface:Query
Perform an 'As of' query using history tables to return the object graph as of a time in the past.To perform this query the DB must have underlying history tables.
-
asDraft
public DefaultOrmQuery<T> asDraft()
Description copied from interface:Query
Execute the query against the draft set of tables.
-
setIncludeSoftDeletes
public DefaultOrmQuery<T> setIncludeSoftDeletes()
Description copied from interface:Query
Execute the query including soft deleted rows.This means that Ebean will not add any predicates to the query for filtering out soft deleted rows. You can still add your own predicates for the deleted properties and effectively you have full control over the query to include or exclude soft deleted rows as needed for a given use case.
- Specified by:
setIncludeSoftDeletes
in interfaceQuery<T>
-
setDocIndexName
public Query<T> setDocIndexName(String indexName)
Description copied from interface:Query
Set the index(es) to search for a document store which uses partitions.For example, when executing a query against ElasticSearch with daily indexes we can explicitly specify the indexes to search against.
// explicitly specify the indexes to search query.setDocIndexName("logstash-2016.11.5,logstash-2016.11.6") // search today's index query.setDocIndexName("$today") // search the last 3 days query.setDocIndexName("$last-3")
If the indexName is specified with ${daily} e.g. "logstash-${daily}" ... then we can use $today and $last-x as the search docIndexName like the examples below.
// search today's index query.setDocIndexName("$today") // search the last 3 days query.setDocIndexName("$last-3")
- Specified by:
setDocIndexName
in interfaceQuery<T>
- Parameters:
indexName
- The index or indexes to search against- Returns:
- This query
-
getDocIndexName
public String getDocIndexName()
Description copied from interface:SpiQuery
For doc store query return the document index name to search against. This is for partitioned indexes (like daily logstash indexes etc).- Specified by:
getDocIndexName
in interfaceSpiQuery<T>
-
getRawSql
public SpiRawSql getRawSql()
Description copied from interface:SpiQuery
Return the RawSql that was set to use for this query.
-
setRawSql
public DefaultOrmQuery<T> setRawSql(RawSql rawSql)
Description copied from interface:Query
Set RawSql to use for this query.
-
getOriginKey
public String getOriginKey()
Description copied from interface:SpiQuery
Return the origin key.- Specified by:
getOriginKey
in interfaceSpiQuery<T>
-
getLazyLoadBatchSize
public int getLazyLoadBatchSize()
Description copied from interface:SpiQuery
Return the default lazy load batch size.- Specified by:
getLazyLoadBatchSize
in interfaceSpiQuery<T>
-
setLazyLoadBatchSize
public Query<T> setLazyLoadBatchSize(int lazyLoadBatchSize)
Description copied from interface:Query
Set the default lazy loading batch size to use.When lazy loading is invoked on beans loaded by this query then this sets the batch size used to load those beans.
- Specified by:
setLazyLoadBatchSize
in interfaceQuery<T>
- Parameters:
lazyLoadBatchSize
- the number of beans to lazy load in a single batch
-
getLazyLoadProperty
public String getLazyLoadProperty()
Description copied from interface:SpiQuery
Return the property that invoked lazy load.- Specified by:
getLazyLoadProperty
in interfaceSpiQuery<T>
-
setLazyLoadProperty
public void setLazyLoadProperty(String lazyLoadProperty)
Description copied from interface:SpiQuery
Set the property that invoked the lazy load and MUST be included in the lazy loading query.- Specified by:
setLazyLoadProperty
in interfaceSpiQuery<T>
-
getExpressionFactory
public ExpressionFactory getExpressionFactory()
Description copied from interface:Query
Return the ExpressionFactory used by this query.- Specified by:
getExpressionFactory
in interfaceQuery<T>
-
getManyWhereJoins
public ManyWhereJoins getManyWhereJoins()
Return the extra joins required to support the where clause for 'Many' properties.- Specified by:
getManyWhereJoins
in interfaceSpiQuery<T>
-
selectAllForLazyLoadProperty
public boolean selectAllForLazyLoadProperty()
Return true if select all properties was used to ensure the property invoking a lazy load was included in the query.- Specified by:
selectAllForLazyLoadProperty
in interfaceSpiQuery<T>
-
setLazyLoadManyPath
public void setLazyLoadManyPath(String lazyLoadManyPath)
Description copied from interface:SpiQuery
Set the path of the many when +query/+lazy loading query is executed.- Specified by:
setLazyLoadManyPath
in interfaceSpiQuery<T>
-
convertJoins
public SpiQuerySecondary convertJoins()
Description copied from interface:SpiQuery
Convert joins as necessary to query joins etc.- Specified by:
convertJoins
in interfaceSpiQuery<T>
-
setDefaultSelectClause
public void setDefaultSelectClause()
Description copied from interface:SpiQuery
Set default select clauses where none have been explicitly defined.- Specified by:
setDefaultSelectClause
in interfaceSpiQuery<T>
-
setTenantId
public void setTenantId(Object tenantId)
Description copied from interface:SpiQuery
Set the tenantId to use for lazy loading.- Specified by:
setTenantId
in interfaceSpiQuery<T>
-
getTenantId
public Object getTenantId()
Description copied from interface:SpiQuery
Return the tenantId to use for lazy loading.- Specified by:
getTenantId
in interfaceSpiQuery<T>
-
setDetail
public void setDetail(OrmQueryDetail detail)
Description copied from interface:SpiQuery
Replace the query detail. This is used by the AutoTune feature to as a fast way to set the query properties and joins.Note care must be taken to keep the where, orderBy, firstRows and maxRows held in the detail attributes.
-
tuneFetchProperties
public boolean tuneFetchProperties(OrmQueryDetail tunedDetail)
Description copied from interface:SpiQuery
AutoTune tune the detail specifying properties to select on already defined joins and adding extra joins where they are missing.- Specified by:
tuneFetchProperties
in interfaceSpiQuery<T>
-
getDetail
public OrmQueryDetail getDetail()
Description copied from interface:SpiQuery
Return the query detail.
-
filterMany
public ExpressionList<T> filterMany(String prop)
Description copied from interface:Query
This applies a filter on the 'many' property list rather than the root level objects.Typically 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 = DB.find(Customer.class) .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.
- Specified by:
filterMany
in interfaceQuery<T>
- Parameters:
prop
- the name of the many property that you want to have a filter on.- Returns:
- the expression list that you add filter expressions for the many to.
-
setFilterMany
public void setFilterMany(String prop, ExpressionList<?> filterMany)
Description copied from interface:SpiQuery
Set a filter to a join path.- Specified by:
setFilterMany
in interfaceSpiQuery<T>
-
prepareDocNested
public void prepareDocNested()
Description copied from interface:SpiQuery
Prepare the query for docstore execution with nested paths.- Specified by:
prepareDocNested
in interfaceSpiQuery<T>
-
setupForDeleteOrUpdate
public void setupForDeleteOrUpdate()
Setup to be a delete or update query.- Specified by:
setupForDeleteOrUpdate
in interfaceSpiQuery<T>
-
setDeleteByIdsPlan
public CQueryPlanKey setDeleteByIdsPlan()
Description copied from interface:SpiQuery
Set the query to be delete by ids due to cascading delete.- Specified by:
setDeleteByIdsPlan
in interfaceSpiQuery<T>
-
setSelectId
public void setSelectId()
Set the select clause to select the Id property.- Specified by:
setSelectId
in interfaceSpiQuery<T>
-
setSingleAttribute
public void setSingleAttribute()
Description copied from interface:SpiQuery
Mark the query as selecting a single attribute.- Specified by:
setSingleAttribute
in interfaceSpiQuery<T>
-
isSingleAttribute
public boolean isSingleAttribute()
Return true if this is a single attribute query.- Specified by:
isSingleAttribute
in interfaceSpiQuery<T>
-
getCountDistinctOrder
public CountDistinctOrder getCountDistinctOrder()
Description copied from interface:SpiQuery
Returns the count distinct order setting.- Specified by:
getCountDistinctOrder
in interfaceSpiQuery<T>
-
isWithId
public boolean isWithId()
Return true if the Id should be included in the query.
-
cacheIdLookup
public CacheIdLookup<T> cacheIdLookup()
Description copied from interface:SpiQuery
Bean cache lookup for find by ids.- Specified by:
cacheIdLookup
in interfaceSpiQuery<T>
-
naturalKey
public NaturalKeyQueryData<T> naturalKey()
Description copied from interface:SpiQuery
Collect natural key data for this query or null if the query does not match the requirements of natural key lookup.- Specified by:
naturalKey
in interfaceSpiQuery<T>
-
getNaturalKeyBindParam
public NaturalKeyBindParam getNaturalKeyBindParam()
Description copied from interface:SpiQuery
Return a Natural Key bind parameter if supported by this query.- Specified by:
getNaturalKeyBindParam
in interfaceSpiQuery<T>
-
copy
public DefaultOrmQuery<T> copy()
Description copied from interface:SpiQuery
Return a copy of the query.
-
copy
public DefaultOrmQuery<T> copy(SpiEbeanServer server)
Description copied from interface:SpiQuery
Return a copy of the query attaching to a different EbeanServer.
-
setPersistenceContextScope
public Query<T> setPersistenceContextScope(PersistenceContextScope scope)
Description copied from interface:Query
Specify the PersistenceContextScope to use for this query. When this is not set the 'default' configured onServerConfig.setPersistenceContextScope(PersistenceContextScope)
is used - this value defaults toPersistenceContextScope.TRANSACTION
. Note that the same persistence Context is used for subsequent lazy loading and query join queries. Note that #findEach uses a 'per object graph' PersistenceContext so this scope is ignored for queries executed as #findIterate, #findEach, #findEachWhile.- Specified by:
setPersistenceContextScope
in interfaceQuery<T>
- Parameters:
scope
- The scope to use for this query and subsequent lazy loading.
-
getPersistenceContextScope
public PersistenceContextScope getPersistenceContextScope()
Description copied from interface:SpiQuery
Return the PersistenceContextScope that this query should use.This can be null and in that case use the default scope.
- Specified by:
getPersistenceContextScope
in interfaceSpiQuery<T>
-
getType
public SpiQuery.Type getType()
Description copied from interface:SpiQuery
Return the type of query (List, Set, Map, Bean, rowCount etc).
-
setType
public void setType(SpiQuery.Type type)
Description copied from interface:SpiQuery
Set the query type (List, Set etc).
-
getLoadDescription
public String getLoadDescription()
Description copied from interface:SpiQuery
Return a more detailed description of the lazy or query load.- Specified by:
getLoadDescription
in interfaceSpiQuery<T>
-
getLoadMode
public String getLoadMode()
Description copied from interface:SpiQuery
Return the load mode (+lazy or +query).- Specified by:
getLoadMode
in interfaceSpiQuery<T>
-
setLoadDescription
public void setLoadDescription(String loadMode, String loadDescription)
Description copied from interface:SpiQuery
Set the load mode (+lazy or +query) and the load description.- Specified by:
setLoadDescription
in interfaceSpiQuery<T>
-
getPersistenceContext
public PersistenceContext getPersistenceContext()
Return the TransactionContext.If no TransactionContext is present on the query then the TransactionContext from the Transaction is used (transaction scoped persistence context).
- Specified by:
getPersistenceContext
in interfaceSpiQuery<T>
-
setPersistenceContext
public void setPersistenceContext(PersistenceContext persistenceContext)
Set an explicit TransactionContext (typically for a refresh query).If no TransactionContext is present on the query then the TransactionContext from the Transaction is used (transaction scoped persistence context).
- Specified by:
setPersistenceContext
in interfaceSpiQuery<T>
-
setLazyLoadForParents
public void setLazyLoadForParents(BeanPropertyAssocMany<?> many)
Description copied from interface:SpiQuery
This becomes a lazy loading query for a many relationship.- Specified by:
setLazyLoadForParents
in interfaceSpiQuery<T>
-
getLazyLoadMany
public BeanPropertyAssocMany<?> getLazyLoadMany()
Description copied from interface:SpiQuery
Return the lazy loading 'many' property.- Specified by:
getLazyLoadMany
in interfaceSpiQuery<T>
-
isDetailEmpty
public boolean isDetailEmpty()
Return true if the query detail has neither select or joins specified.- Specified by:
isDetailEmpty
in interfaceSpiQuery<T>
-
isAutoTuned
public boolean isAutoTuned()
Description copied from interface:Query
Returns true if this query was tuned by autoTune.- Specified by:
isAutoTuned
in interfaceQuery<T>
-
setAutoTuned
public void setAutoTuned(boolean autoTuned)
Description copied from interface:SpiQuery
Set to true if this query has been tuned by autoTune.- Specified by:
setAutoTuned
in interfaceSpiQuery<T>
-
isAutoTune
public Boolean isAutoTune()
Description copied from interface:SpiQuery
Return explicit AutoTune setting or null. If null then not explicitly set so we use the default behaviour.- Specified by:
isAutoTune
in interfaceSpiQuery<T>
-
setDefaultRawSqlIfRequired
public void setDefaultRawSqlIfRequired()
Description copied from interface:SpiQuery
If this is a RawSql based entity set the default RawSql if not set.- Specified by:
setDefaultRawSqlIfRequired
in interfaceSpiQuery<T>
-
setAutoTune
public DefaultOrmQuery<T> setAutoTune(boolean autoTune)
Description copied from interface:Query
Explicitly specify whether to use AutoTune for this query.If you do not call this method on a query the "Implicit AutoTune mode" is used to determine if AutoTune should be used for a given query.
AutoTune 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 AutoTune will not remove them.
- Specified by:
setAutoTune
in interfaceQuery<T>
-
forUpdate
public DefaultOrmQuery<T> forUpdate()
Description copied from interface:Query
Execute using "for update" clause which results in the DB locking the record.
-
forUpdateNoWait
public DefaultOrmQuery<T> forUpdateNoWait()
Description copied from interface:Query
Execute using "for update" clause with "no wait" option.This is typically a Postgres and Oracle only option at this stage.
- Specified by:
forUpdateNoWait
in interfaceQuery<T>
-
forUpdateSkipLocked
public DefaultOrmQuery<T> forUpdateSkipLocked()
Description copied from interface:Query
Execute using "for update" clause with "skip locked" option.This is typically a Postgres and Oracle only option at this stage.
- Specified by:
forUpdateSkipLocked
in interfaceQuery<T>
-
isForUpdate
public boolean isForUpdate()
Description copied from interface:Query
Return true if this query has forUpdate set.- Specified by:
isForUpdate
in interfaceQuery<T>
-
getForUpdateMode
public Query.ForUpdate getForUpdateMode()
Description copied from interface:SpiQuery
Return the ForUpdate mode.- Specified by:
getForUpdateMode
in interfaceQuery<T>
- Specified by:
getForUpdateMode
in interfaceSpiQuery<T>
-
getProfilingListener
public ProfilingListener getProfilingListener()
Description copied from interface:SpiQuery
If return null then no profiling for this query. If a ProfilingListener is returned this implies that profiling is turned on for this query (and all the objects this query creates).- Specified by:
getProfilingListener
in interfaceSpiQuery<T>
-
setProfilingListener
public void setProfilingListener(ProfilingListener profilingListener)
Description copied from interface:SpiQuery
This has the effect of turning on profiling for this query.- Specified by:
setProfilingListener
in interfaceSpiQuery<T>
-
getQueryType
public QueryType getQueryType()
Description copied from interface:Query
Return the type of query being executed.- Specified by:
getQueryType
in interfaceQuery<T>
-
getMode
public SpiQuery.Mode getMode()
Description copied from interface:SpiQuery
Return the query mode.
-
getTemporalMode
public SpiQuery.TemporalMode getTemporalMode()
Description copied from interface:SpiQuery
Return the Temporal mode for the query.- Specified by:
getTemporalMode
in interfaceSpiQuery<T>
-
isAsOfQuery
public boolean isAsOfQuery()
Description copied from interface:SpiQuery
Return true if this is a 'As Of' query.- Specified by:
isAsOfQuery
in interfaceSpiQuery<T>
-
isAsDraft
public boolean isAsDraft()
Description copied from interface:SpiQuery
Return true if this is a 'As Draft' query.
-
isIncludeSoftDeletes
public boolean isIncludeSoftDeletes()
Description copied from interface:SpiQuery
Return true if this query includes soft deleted rows.- Specified by:
isIncludeSoftDeletes
in interfaceSpiQuery<T>
-
setMode
public void setMode(SpiQuery.Mode mode)
Description copied from interface:SpiQuery
Set the query mode.
-
isUsageProfiling
public boolean isUsageProfiling()
Description copied from interface:SpiQuery
Return false when this is a lazy load or refresh query for a bean.We just take/copy the data from those beans and don't collect AutoTune usage profiling on those lazy load or refresh beans.
- Specified by:
isUsageProfiling
in interfaceSpiQuery<T>
-
setUsageProfiling
public void setUsageProfiling(boolean usageProfiling)
Description copied from interface:SpiQuery
Set to false if this query should not be included in the AutoTune usage profiling information.- Specified by:
setUsageProfiling
in interfaceSpiQuery<T>
-
setParentNode
public void setParentNode(ObjectGraphNode parentNode)
Description copied from interface:SpiQuery
Set the profile point of the bean or collection that is lazy loading.This enables use to hook this back to the original 'root' query by the queryPlanHash and stackPoint.
- Specified by:
setParentNode
in interfaceSpiQuery<T>
-
getParentNode
public ObjectGraphNode getParentNode()
Description copied from interface:SpiQuery
Used to hook back a lazy loading query to the original query (query point).This will return null or an "original" query.
- Specified by:
getParentNode
in interfaceSpiQuery<T>
-
setOrigin
public ObjectGraphNode setOrigin(CallOrigin callOrigin)
Description copied from interface:SpiQuery
Return the origin point for the query.This MUST be call prior to a query being changed via tuning. This is because the queryPlanHash is used to identify the query point.
-
isNativeSql
public boolean isNativeSql()
Description copied from interface:SpiQuery
Return true if this is a native sql query.- Specified by:
isNativeSql
in interfaceSpiQuery<T>
-
getNativeSql
public String getNativeSql()
Description copied from interface:SpiQuery
Return the unmodified native sql query (with named params etc).- Specified by:
getNativeSql
in interfaceSpiQuery<T>
-
getQueryPlanKey
public Object getQueryPlanKey()
Description copied from interface:SpiQuery
Return the query plan key.- Specified by:
getQueryPlanKey
in interfaceSpiQuery<T>
-
prepare
public CQueryPlanKey prepare(SpiOrmQueryRequest<T> request)
Prepare the query which prepares any expressions (sub-query expressions etc) and calculates the query plan key.
-
queryBindHash
public int queryBindHash()
Calculate a hash based on the bind values used in the query.Used with queryPlanHash() to get a unique hash for a query.
- Specified by:
queryBindHash
in interfaceSpiQuery<T>
-
queryHash
public HashQuery queryHash()
Return a hash that includes the query plan and bind values.This hash can be used to identify if we have executed the exact same query (including bind values) before.
-
isRawSql
public boolean isRawSql()
Description copied from interface:SpiQuery
Return true if this is a RawSql query.
-
getTimeout
public int getTimeout()
Return the timeout.- Specified by:
getTimeout
in interfaceSpiQuery<T>
-
hasMaxRowsOrFirstRow
public boolean hasMaxRowsOrFirstRow()
Description copied from interface:SpiQuery
Returns true if either firstRow or maxRows has been set.- Specified by:
hasMaxRowsOrFirstRow
in interfaceSpiQuery<T>
-
isVersionsBetween
public boolean isVersionsBetween()
Description copied from interface:SpiQuery
Return true if this is a find versions between query.- Specified by:
isVersionsBetween
in interfaceSpiQuery<T>
-
getVersionStart
public Timestamp getVersionStart()
Description copied from interface:SpiQuery
Return the find versions start timestamp.- Specified by:
getVersionStart
in interfaceSpiQuery<T>
-
getVersionEnd
public Timestamp getVersionEnd()
Description copied from interface:SpiQuery
Return the find versions end timestamp.- Specified by:
getVersionEnd
in interfaceSpiQuery<T>
-
isReadOnly
public Boolean isReadOnly()
Description copied from interface:SpiQuery
Return true if the beans returned by this query should be read only.- Specified by:
isReadOnly
in interfaceSpiQuery<T>
-
setReadOnly
public DefaultOrmQuery<T> setReadOnly(boolean readOnly)
Description copied from interface:Query
When set to true when you want the returned beans to be read only.- Specified by:
setReadOnly
in interfaceQuery<T>
-
isBeanCachePut
public boolean isBeanCachePut()
Description copied from interface:SpiQuery
Return true if the query should PUT against the bean cache.- Specified by:
isBeanCachePut
in interfaceSpiQuery<T>
-
isBeanCacheGet
public boolean isBeanCacheGet()
Description copied from interface:SpiQuery
Return true if the query should GET against bean cache.- Specified by:
isBeanCacheGet
in interfaceSpiQuery<T>
-
isForceHitDatabase
public boolean isForceHitDatabase()
Description copied from interface:SpiQuery
Return true if we must hit the DB (Cache reload or select for update).- Specified by:
isForceHitDatabase
in interfaceSpiQuery<T>
-
resetBeanCacheAutoMode
public void resetBeanCacheAutoMode(boolean findOne)
Description copied from interface:SpiQuery
Reset AUTO mode to OFF for findList(). Expect explicit cache use with findList().- Specified by:
resetBeanCacheAutoMode
in interfaceSpiQuery<T>
-
getUseBeanCache
public CacheMode getUseBeanCache()
Description copied from interface:SpiQuery
Return the cache mode for using the bean cache (Get and Put).- Specified by:
getUseBeanCache
in interfaceSpiQuery<T>
-
getUseQueryCache
public CacheMode getUseQueryCache()
Description copied from interface:SpiQuery
Return the cache mode if this query should use/check the query cache.- Specified by:
getUseQueryCache
in interfaceSpiQuery<T>
-
setBeanCacheMode
public Query<T> setBeanCacheMode(CacheMode beanCacheMode)
Description copied from interface:Query
Set the mode to use the bean cache when executing this query.By default "find by id" and "find by natural key" will use the bean cache when bean caching is enabled. Setting this to false means that the query will not use the bean cache and instead hit the database.
By default findList() with natural keys will not use the bean cache. In that case we need to explicitly use the bean cache.
- Specified by:
setBeanCacheMode
in interfaceQuery<T>
-
setUseQueryCache
public DefaultOrmQuery<T> setUseQueryCache(CacheMode useQueryCache)
Description copied from interface:Query
Set theCacheMode
to use the query for executing this query.- Specified by:
setUseQueryCache
in interfaceQuery<T>
-
setLoadBeanCache
public DefaultOrmQuery<T> setLoadBeanCache(boolean loadBeanCache)
Description copied from interface:Query
Will be deprecated - migrate to use setBeanCacheMode(CacheMode.RECACHE).When set to true all the beans from this query are loaded into the bean cache.
- Specified by:
setLoadBeanCache
in interfaceQuery<T>
-
setTimeout
public DefaultOrmQuery<T> setTimeout(int secs)
Description copied from interface:Query
Set a timeout on this query.This 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.
- Specified by:
setTimeout
in interfaceQuery<T>
- Parameters:
secs
- the query timeout limit in seconds. Zero means there is no limit.
-
select
public DefaultOrmQuery<T> select(String columns)
Description copied from interface:Query
Specify the properties to fetch on the root level entity bean in comma delimited format.The Id property is automatically included in the properties to fetch unless setDistinct(true) is set on the query.
Use
Query.fetch(String, String)
to specify specific properties to fetch on other non-root level paths of the object graph.List<Customer> customers = DB.find(Customer.class) // Only fetch the customer id, name and status. // This is described as a "Partial Object" .select("name, status") .where.ilike("name", "rob%") .findList();
-
select
public DefaultOrmQuery<T> select(FetchGroup<T> fetchGroup)
Description copied from interface:Query
Apply the fetchGroup which defines what part of the object graph to load.
-
fetch
public DefaultOrmQuery<T> fetch(String property)
Description copied from interface:Query
Specify a path to fetch eagerly including all its properties.Ebean will endeavour to fetch this path using a SQL join. If Ebean determines that it can not use a SQL join (due to maxRows or because it would result in a cartesian product) Ebean will automatically convert this fetch query into a "query join" - i.e. use fetchQuery().
// fetch customers (their id, name and status) List<Customer> customers = DB.find(Customer.class) // eager fetch the contacts .fetch("contacts") .findList();
-
fetchQuery
public Query<T> fetchQuery(String property)
Description copied from interface:Query
Fetch the path eagerly using a "query join" (separate SQL query).This is the same as:
fetch(path, new FetchConfig().query())
This would be used instead of a fetch() when we use a separate SQL query to fetch this part of the object graph rather than a SQL join.
We might typically get a performance benefit when the path to fetch is a OneToMany or ManyToMany, the 'width' of the 'root bean' is wide and the cardinality of the many is high.
- Specified by:
fetchQuery
in interfaceQuery<T>
- Parameters:
property
- the property path we wish to fetch eagerly
-
fetchCache
public Query<T> fetchCache(String property)
Description copied from interface:Query
Fetch the path eagerly using L2 cache.- Specified by:
fetchCache
in interfaceQuery<T>
-
fetchLazy
public Query<T> fetchLazy(String property)
Description copied from interface:Query
Fetch the path lazily (via batch lazy loading).This is the same as:
fetch(path, new FetchConfig().lazy())
The reason for using fetchLazy() is to either:
- Control/tune what is fetched as part of lazy loading
- Make use of the L2 cache, build this part of the graph from L2 cache
-
fetch
public DefaultOrmQuery<T> fetch(String property, FetchConfig joinConfig)
Description copied from interface:Query
Additionally specify a JoinConfig to specify a "query join" and or define the lazy loading query.// fetch customers (their id, name and status) List<Customer> customers = DB.find(Customer.class) // lazy fetch contacts with a batch size of 100 .fetch("contacts", new FetchConfig().lazy(100)) .findList();
-
fetch
public DefaultOrmQuery<T> fetch(String property, String columns)
Description copied from interface:Query
Specify a path to fetch eagerly including specific properties.Ebean will endeavour to fetch this path using a SQL join. If Ebean determines that it can not use a SQL join (due to maxRows or because it would result in a cartesian product) Ebean will automatically convert this fetch query into a "query join" - i.e. use fetchQuery().
// query orders... List<Order> orders = DB.find(Order.class) // fetch the customer... // ... getting the customers name and phone number .fetch("customer", "name, phoneNumber") // ... also fetch the customers billing address (* = all properties) .fetch("customer.billingAddress", "*") .findList();
If columns is null or "*" then all columns/properties for that path are fetched.
// fetch customers (their id, name and status) List<Customer> customers = DB.find(Customer.class) .select("name, status") .fetch("contacts", "firstName,lastName,email") .findList();
-
fetchQuery
public Query<T> fetchQuery(String property, String columns)
Description copied from interface:Query
Fetch the path and properties using a "query join" (separate SQL query).This is the same as:
fetch(path, fetchProperties, new FetchConfig().query())
This would be used instead of a fetch() when we use a separate SQL query to fetch this part of the object graph rather than a SQL join.
We might typically get a performance benefit when the path to fetch is a OneToMany or ManyToMany, the 'width' of the 'root bean' is wide and the cardinality of the many is high.
- Specified by:
fetchQuery
in interfaceQuery<T>
- Parameters:
property
- the property path we wish to fetch eagerly.columns
- properties of the associated bean that you want to include in the fetch (* means all properties, null also means all properties).
-
fetchCache
public Query<T> fetchCache(String property, String columns)
Description copied from interface:Query
Fetch the path and properties using L2 bean cache.- Specified by:
fetchCache
in interfaceQuery<T>
- Parameters:
property
- The path of the beans we are fetching from L2 cache.columns
- The properties that should be loaded.
-
fetchLazy
public Query<T> fetchLazy(String property, String columns)
Description copied from interface:Query
Fetch the path and properties lazily (via batch lazy loading).This is the same as:
fetch(path, fetchProperties, new FetchConfig().lazy())
The reason for using fetchLazy() is to either:
- Control/tune what is fetched as part of lazy loading
- Make use of the L2 cache, build this part of the graph from L2 cache
-
fetch
public DefaultOrmQuery<T> fetch(String property, String columns, FetchConfig config)
Description copied from interface:Query
Additionally specify a FetchConfig to use a separate query or lazy loading to load this path.// fetch customers (their id, name and status) List<Customer> customers = DB.find(Customer.class) .select("name, status") .fetch("contacts", "firstName,lastName,email", new FetchConfig().lazy(10)) .findList();
-
usingTransaction
public Query<T> usingTransaction(Transaction transaction)
Description copied from interface:Query
Execute the query using the given transaction.- Specified by:
usingTransaction
in interfaceQuery<T>
-
usingConnection
public Query<T> usingConnection(Connection connection)
Description copied from interface:Query
Execute the query using the given connection.- Specified by:
usingConnection
in interfaceQuery<T>
-
usingDatabase
public Query<T> usingDatabase(Database database)
Description copied from interface:Query
Execute the query using the given database.- Specified by:
usingDatabase
in interfaceQuery<T>
-
delete
public int delete()
Description copied from interface:Query
Execute as a delete query deleting the 'root level' beans that match the predicates in the query.Note that if the query includes joins then the generated delete statement may not be optimal depending on the database platform.
-
delete
public int delete(Transaction transaction)
Description copied from interface:Query
Execute as a delete query returning the number of rows deleted using the given transaction.Note that if the query includes joins then the generated delete statement may not be optimal depending on the database platform.
-
update
public int update()
Description copied from interface:Query
Execute the UpdateQuery returning the number of rows updated.
-
update
public int update(Transaction transaction)
Description copied from interface:Query
Execute the UpdateQuery returning the number of rows updated using the given transaction.
-
findIds
public <A> List<A> findIds()
Description copied from interface:Query
Execute the query returning the list of Id's.This query will execute against the Database that was used to create it.
-
exists
public boolean exists()
Description copied from interface:Query
Execute the query returning true if a row is found.The query is executed using max rows of 1 and will only select the id property. This method is really just a convenient way to optimise a query to perform a 'does a row exist in the db' check.
Example using a query bean:
boolean userExists = new QContact() .email.equalTo("[email protected]") .exists();
Example:
boolean userExists = query() .where().eq("email", "[email protected]") .exists();
-
findCount
public int findCount()
Description copied from interface:Query
Return the count of entities this query should return.This is the number of 'top level' or 'root level' entities.
-
findEachWhile
public void findEachWhile(Predicate<T> consumer)
Description copied from interface:Query
Execute the query using callbacks to a visitor to process the resulting beans one at a time.Note that findEachWhile (and findEach and findIterate) uses a "per graph" persistence context scope and adjusts jdbc fetch buffer size for large queries. As such it is better to use findList for small queries.
This method is functionally equivalent to findIterate() but instead of using an iterator uses the Predicate (SAM) interface which is better suited to use with Java8 closures.
DB.find(Customer.class) .fetch("contacts", new FetchConfig().query(2)) .where().eq("status", Status.NEW) .order().asc("id") .setMaxRows(2000) .findEachWhile((Customer customer) -> { // do something with customer System.out.println("-- visit " + customer); // return true to continue processing or false to stop return (customer.getId() < 40); });
- Specified by:
findEachWhile
in interfaceQuery<T>
- Parameters:
consumer
- the consumer used to process the queried beans.
-
findEach
public void findEach(Consumer<T> consumer)
Description copied from interface:Query
Execute the query processing the beans one at a time.This method is appropriate to process very large query results as the beans are consumed one at a time and do not need to be held in memory (unlike #findList #findSet etc)
Note that findEach (and findEachWhile and findIterate) uses a "per graph" persistence context scope and adjusts jdbc fetch buffer size for large queries. As such it is better to use findList for small queries.
Note that internally Ebean can inform the JDBC driver that it is expecting larger resultSet and specifically for MySQL this hint is required to stop it's JDBC driver from buffering the entire resultSet. As such, for smaller resultSets findList() is generally preferable.
Compared with #findEachWhile this will always process all the beans where as #findEachWhile provides a way to stop processing the query result early before all the beans have been read.
This method is functionally equivalent to findIterate() but instead of using an iterator uses the Consumer interface which is better suited to use with Java8 closures.
DB.find(Customer.class) .where().eq("status", Status.NEW) .order().asc("id") .findEach((Customer customer) -> { // do something with customer System.out.println("-- visit " + customer); });
-
findIterate
public QueryIterator<T> findIterate()
Description copied from interface:Query
Execute the query iterating over the results.Note that findIterate (and findEach and findEachWhile) uses a "per graph" persistence context scope and adjusts jdbc fetch buffer size for large queries. As such it is better to use findList for small queries.
Remember that with
QueryIterator
you must callQueryIterator.close()
when you have finished iterating the results (typically in a finally block).findEach() and findEachWhile() are preferred to findIterate() as they ensure the jdbc statement and resultSet are closed at the end of the iteration.
This query will execute against the Database that was used to create it.
Query<Customer> query = DB.find(Customer.class) .where().eq("status", Status.NEW) .order().asc("id"); // use try with resources to ensure QueryIterator is closed try (QueryIterator<Customer> it = query.findIterate()) { while (it.hasNext()) { Customer customer = it.next(); // do something with customer ... } }
- Specified by:
findIterate
in interfaceQuery<T>
-
findStream
public Stream<T> findStream()
Description copied from interface:Query
Execute the query returning the result as a Stream.Note that this will hold all resulting beans in memory using a single persistence context. Use findLargeStream() for queries that expect to return a large number of results.
// use try with resources to ensure Stream is closed try (Stream<Customer> stream = query.findStream()) { stream .map(...) .collect(...); }
- Specified by:
findStream
in interfaceQuery<T>
-
findLargeStream
public Stream<T> findLargeStream()
Description copied from interface:Query
Execute the query returning the result as a Stream.Note that this uses multiple persistence contexts such that we can use it with a large number of results.
// use try with resources to ensure Stream is closed try (Stream<Customer> stream = query.findLargeStream()) { stream .map(...) .collect(...); }
- Specified by:
findLargeStream
in interfaceQuery<T>
-
findVersions
public List<Version<T>> findVersions()
Description copied from interface:Query
Return versions of a @History entity bean.Note that this query will work against view based history implementations but not sql2011 standards based implementations that require a start and end timestamp to be specified.
Generally this query is expected to be a find by id or unique predicates query. It will execute the query against the history returning the versions of the bean.
- Specified by:
findVersions
in interfaceQuery<T>
-
findVersionsBetween
public List<Version<T>> findVersionsBetween(Timestamp start, Timestamp end)
Description copied from interface:Query
Return versions of a @History entity bean between the 2 timestamps.Generally this query is expected to be a find by id or unique predicates query. It will execute the query against the history returning the versions of the bean.
- Specified by:
findVersionsBetween
in interfaceQuery<T>
-
findList
public List<T> findList()
Description copied from interface:Query
Execute the query returning the list of objects.This query will execute against the Database that was used to create it.
List<Customer> customers = DB.find(Customer.class) .where().ilike("name", "rob%") .findList();
-
findSet
public Set<T> findSet()
Description copied from interface:Query
Execute the query returning the set of objects.This query will execute against the Database that was used to create it.
Set<Customer> customers = DB.find(Customer.class) .where().ilike("name", "rob%") .findSet();
-
findMap
public <K> Map<K,T> findMap()
Description copied from interface:Query
Execute the query returning a map of the objects.This query will execute against the Database 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.
Map<String, Product> map = DB.find(Product.class) .setMapKey("sku") .findMap();
-
findSingleAttributeList
public <A> List<A> findSingleAttributeList()
Description copied from interface:Query
Execute the query returning a list of values for a single property.Example 1:
List<String> names = DB.find(Customer.class) .select("name") .order().asc("name") .findSingleAttributeList();
Example 2:
List<String> names = DB.find(Customer.class) .setDistinct(true) .select("name") .where().eq("status", Customer.Status.NEW) .order().asc("name") .setMaxRows(100) .findSingleAttributeList();
- Specified by:
findSingleAttributeList
in interfaceQuery<T>
- Returns:
- the list of values for the selected property
-
findSingleAttribute
public <A> A findSingleAttribute()
Description copied from interface:Query
Execute a query returning a single value of a single property/column.String name = DB.find(Customer.class) .select("name") .where().eq("id", 42) .findSingleAttribute();
- Specified by:
findSingleAttribute
in interfaceQuery<T>
-
findOne
public T findOne()
Description copied from interface:Query
Execute the query returning either a single bean or null (if no matching bean is found).If more than 1 row is found for this query then a NonUniqueResultException 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 = DB.find(Product.class) .where().eq("sku", "aa113") .findOne(); ...
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 = DB.find(Order.class) .setId(1) .fetch("details") .findOne(); // the order details were eagerly loaded List<OrderDetail> details = order.getDetails(); ...
-
findOneOrEmpty
public Optional<T> findOneOrEmpty()
Description copied from interface:Query
Execute the query returning an optional bean.- Specified by:
findOneOrEmpty
in interfaceQuery<T>
-
findFutureIds
public FutureIds<T> findFutureIds()
Description copied from interface:Query
Execute find Id's query in a background thread.This 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).
- Specified by:
findFutureIds
in interfaceQuery<T>
- Returns:
- a Future object for the list of Id's
-
findFutureList
public FutureList<T> findFutureList()
Description copied from interface:Query
Execute find list query in a background thread.This query will execute in it's own PersistenceContext and using its own transaction. What that means is that it will not share any bean instances with other queries.
- Specified by:
findFutureList
in interfaceQuery<T>
- Returns:
- a Future object for the list result of the query
-
findFutureCount
public FutureRowCount<T> findFutureCount()
Description copied from interface:Query
Execute find row count query in a background thread.This 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).
- Specified by:
findFutureCount
in interfaceQuery<T>
- Returns:
- a Future object for the row count query
-
findPagedList
public PagedList<T> findPagedList()
Description copied from interface:Query
Return a PagedList for this query using firstRow and maxRows.The benefit of using this over findList() is that it provides functionality to get the total row count etc.
If maxRows is not set on the query prior to calling findPagedList() then a PersistenceException is thrown.
PagedList<Order> pagedList = DB.find(Order.class) .setFirstRow(50) .setMaxRows(20) .findPagedList(); // fetch the total row count in the background pagedList.loadRowCount(); List<Order> orders = pagedList.getList(); int totalRowCount = pagedList.getTotalRowCount();
- Specified by:
findPagedList
in interfaceQuery<T>
- Returns:
- The PagedList
-
setParameter
public DefaultOrmQuery<T> setParameter(Object value)
Description copied from interface:Query
Bind the next positioned parameter.// a query with a positioned parameters String oql = "where status = ? and name = ?"; List<Order> list = DB.createQuery(Order.class, oql) .setParameter(OrderStatus.NEW) .setParameter("Rob") .findList();
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameters
public DefaultOrmQuery<T> setParameters(Object... values)
Description copied from interface:Query
Bind all the positioned parameters.A convenience for multiple calls to
Query.setParameter(Object)
- Specified by:
setParameters
in interfaceQuery<T>
-
setParameter
public DefaultOrmQuery<T> setParameter(int position, Object value)
Set an ordered bind parameter according to its position. Note that the position starts at 1 to be consistent with JDBC PreparedStatement. You need to set a parameter value for each ? you have in the query.- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
position
- the parameter bind position starting from 1 (not 0)value
- the parameter bind value.
-
setParameter
public DefaultOrmQuery<T> setParameter(String name, Object value)
Set a named bind parameter. Named parameters have a colon to prefix the name.- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
name
- the parameter namevalue
- the parameter value
-
checkPagingOrderBy
public boolean checkPagingOrderBy()
Description copied from interface:SpiQuery
Return true if the query should have an order by appended automatically.- Specified by:
checkPagingOrderBy
in interfaceSpiQuery<T>
-
orderByIsEmpty
public boolean orderByIsEmpty()
Description copied from interface:SpiQuery
Return true if there is no Order By clause.- Specified by:
orderByIsEmpty
in interfaceSpiQuery<T>
-
getOrderBy
public OrderBy<T> getOrderBy()
Description copied from interface:SpiQuery
Return the Order By clause or null if there is none defined.- Specified by:
getOrderBy
in interfaceSpiQuery<T>
-
orderBy
@Deprecated public OrderBy<T> orderBy()
Deprecated.Description copied from interface:Query
Return the OrderBy so that you can append an ascending or descending property to the order by clause.This will never return a null. If no order by clause exists then an 'empty' OrderBy object is returned.
This is the same as
order()
-
order
public OrderBy<T> order()
Description copied from interface:Query
Return the OrderBy so that you can append an ascending or descending property to the order by clause.This will never return a null. If no order by clause exists then an 'empty' OrderBy object is returned.
This is the same as
orderBy()
-
orderBy
@Deprecated public DefaultOrmQuery<T> orderBy(String orderByClause)
Deprecated.Description copied from interface:Query
Set the order by clause replacing the existing order by clause if there is one.This follows SQL syntax using commas between each property with the optional asc and desc keywords representing ascending and descending order respectively.
-
order
public DefaultOrmQuery<T> order(String orderByClause)
Description copied from interface:Query
Set the order by clause replacing the existing order by clause if there is one.This follows SQL syntax using commas between each property with the optional asc and desc keywords representing ascending and descending order respectively.
-
setOrderBy
@Deprecated public DefaultOrmQuery<T> setOrderBy(OrderBy<T> orderBy)
Deprecated.Description copied from interface:Query
Set an OrderBy object to replace any existing OrderBy clause.- Specified by:
setOrderBy
in interfaceQuery<T>
-
setOrder
public DefaultOrmQuery<T> setOrder(OrderBy<T> orderBy)
Description copied from interface:Query
Set an OrderBy object to replace any existing OrderBy clause.
-
isManualId
public boolean isManualId()
Description copied from interface:SpiQuery
Return true if the Id property is manually included in the query (DTO queries).- Specified by:
isManualId
in interfaceSpiQuery<T>
-
setManualId
public void setManualId()
Description copied from interface:SpiQuery
Set to true when we only include the Id property if it is explicitly included in the select().- Specified by:
setManualId
in interfaceSpiQuery<T>
-
isDistinct
public boolean isDistinct()
return true if user specified to use SQL DISTINCT (effectively excludes id property).- Specified by:
isDistinct
in interfaceSpiQuery<T>
-
setDistinct
public DefaultOrmQuery<T> setDistinct(boolean distinct)
Internally set to use SQL DISTINCT on the query but still have id property included.- Specified by:
setDistinct
in interfaceQuery<T>
-
setCountDistinct
public DefaultOrmQuery<T> setCountDistinct(CountDistinctOrder countDistinctOrder)
Description copied from interface:Query
Extended version for setDistinct in conjunction with "findSingleAttributeList";List<CountedValue<Order.Status>> orderStatusCount = DB.find(Order.class) .select("status") .where() .gt("orderDate", LocalDate.now().minusMonths(3)) // fetch as single attribute with a COUNT .setCountDistinct(CountDistinctOrder.COUNT_DESC_ATTR_ASC) .findSingleAttributeList(); for (CountedValue<Order.Status> entry : orderStatusCount) { System.out.println(" count:" + entry.getCount()+" orderStatus:" + entry.getValue() ); } // produces count:3 orderStatus:NEW count:1 orderStatus:SHIPPED count:1 orderStatus:COMPLETE
- Specified by:
setCountDistinct
in interfaceQuery<T>
-
isCountDistinct
public boolean isCountDistinct()
Description copied from interface:Query
Return true if this is countDistinct query.- Specified by:
isCountDistinct
in interfaceQuery<T>
-
getBeanType
public Class<T> getBeanType()
Description copied from interface:Query
Return the type of beans being queried.- Specified by:
getBeanType
in interfaceQuery<T>
-
getInheritType
public Class<? extends T> getInheritType()
Description copied from interface:Query
Returns the inherit type. This is normally the same as getBeanType() returns as long as no other type is set.- Specified by:
getInheritType
in interfaceQuery<T>
-
setInheritType
public Query<T> setInheritType(Class<? extends T> type)
Description copied from interface:Query
Restrict the query to only return subtypes of the given inherit type.List<Animal> animals = new QAnimal() .name.startsWith("Fluffy") .setInheritType(Cat.class) .findList();
- Specified by:
setInheritType
in interfaceQuery<T>
- Parameters:
type
- An inheritance subtype of the
-
getM2mIncludeJoin
public TableJoin getM2mIncludeJoin()
Description copied from interface:SpiQuery
Return the extra join for a M2M lazy load.- Specified by:
getM2mIncludeJoin
in interfaceSpiQuery<T>
-
setM2MIncludeJoin
public void setM2MIncludeJoin(TableJoin m2mIncludeJoin)
Description copied from interface:SpiQuery
Set the extra join for a M2M lazy load.- Specified by:
setM2MIncludeJoin
in interfaceSpiQuery<T>
-
setDisableLazyLoading
public DefaultOrmQuery<T> setDisableLazyLoading(boolean disableLazyLoading)
Description copied from interface:Query
Set true if you want to disable lazy loading.That is, once the object graph is returned further lazy loading is disabled.
- Specified by:
setDisableLazyLoading
in interfaceQuery<T>
-
isDisableLazyLoading
public boolean isDisableLazyLoading()
Description copied from interface:SpiQuery
Return true if lazy loading has been disabled on the query.- Specified by:
isDisableLazyLoading
in interfaceSpiQuery<T>
-
getFirstRow
public int getFirstRow()
Description copied from interface:SpiQuery
Return the index of the first row to return in the query.- Specified by:
getFirstRow
in interfaceQuery<T>
- Specified by:
getFirstRow
in interfaceSpiQuery<T>
-
setFirstRow
public DefaultOrmQuery<T> setFirstRow(int firstRow)
Description copied from interface:Query
Set the first row to return for this query.- Specified by:
setFirstRow
in interfaceQuery<T>
- Parameters:
firstRow
- the first row to include in the query result.
-
getMaxRows
public int getMaxRows()
Description copied from interface:SpiQuery
Return the maximum number of rows to return in the query.- Specified by:
getMaxRows
in interfaceQuery<T>
- Specified by:
getMaxRows
in interfaceSpiQuery<T>
-
setMaxRows
public DefaultOrmQuery<T> setMaxRows(int maxRows)
Description copied from interface:Query
Set the maximum number of rows to return in the query.- Specified by:
setMaxRows
in interfaceQuery<T>
- Parameters:
maxRows
- the maximum number of rows to return in the query.
-
getMapKey
public String getMapKey()
Description copied from interface:SpiQuery
Return the property used to specify keys for a map.
-
setMapKey
public DefaultOrmQuery<T> setMapKey(String mapKey)
Description copied from interface:Query
Set the property to use as keys for a map.If no property is set then the id property is used.
// Assuming sku is unique for products... Map<String,Product> productMap = DB.find(Product.class) .setMapKey("sku") // sku map keys... .findMap();
-
setId
public DefaultOrmQuery<T> setId(Object id)
Description copied from interface:Query
Set the Id value to query. This is used with findOne().You can use this to have further control over the query. For example adding fetch joins.
Order order = DB.find(Order.class) .setId(1) .fetch("details") .findOne(); // the order details were eagerly fetched List<OrderDetail> details = order.getDetails();
-
getBindParams
public BindParams getBindParams()
Description copied from interface:SpiQuery
Return the bind parameters.- Specified by:
getBindParams
in interfaceSpiQuery<T>
-
where
public DefaultOrmQuery<T> where(Expression expression)
Description copied from interface:Query
Add a single Expression to the where clause returning the query.List<Order> newOrders = DB.find(Order.class) .where().eq("status", Order.NEW) .findList(); ...
-
text
public ExpressionList<T> text()
Description copied from interface:Query
Add Full text search expressions for Document store queries.This is currently ElasticSearch only and provides the full text expressions such as Match and Multi-Match.
This automatically makes this query a "Doc Store" query and will execute against the document store (ElasticSearch).
Expressions added here are added to the "query" section of an ElasticSearch query rather than the "filter" section.
Expressions added to the where() are added to the "filter" section of an ElasticSearch query.
-
where
public ExpressionList<T> where()
Description copied from interface:Query
Add Expressions to the where clause with the ability to chain on the ExpressionList. You can use this for adding multiple expressions to the where clause.List<Order> orders = DB.find(Order.class) .where() .eq("status", Order.NEW) .ilike("customer.name","rob%") .findList();
-
simplifyExpressions
public void simplifyExpressions()
Description copied from interface:SpiQuery
Simplify nested expression lists where possible.- Specified by:
simplifyExpressions
in interfaceSpiQuery<T>
-
having
public DefaultOrmQuery<T> having(Expression expression)
Description copied from interface:Query
Add an expression to the having clause returning the query.Currently 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.
-
having
public ExpressionList<T> having()
Description copied from interface:Query
Add Expressions to the Having clause return the ExpressionList.Currently 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).
-
getHavingExpressions
public SpiExpressionList<T> getHavingExpressions()
Description copied from interface:SpiQuery
Can return null if no expressions where added to the having clause.- Specified by:
getHavingExpressions
in interfaceSpiQuery<T>
-
getWhereExpressions
public SpiExpressionList<T> getWhereExpressions()
Description copied from interface:SpiQuery
Can return null if no expressions where added to the where clause.- Specified by:
getWhereExpressions
in interfaceSpiQuery<T>
-
getTextExpression
public SpiExpressionList<T> getTextExpression()
Description copied from interface:SpiQuery
Return the text expressions.- Specified by:
getTextExpression
in interfaceSpiQuery<T>
-
getGeneratedSql
public String getGeneratedSql()
Description copied from interface:Query
Return the sql that was generated for executing this query.This is only available after the query has been executed and provided only for informational purposes.
- Specified by:
getGeneratedSql
in interfaceQuery<T>
-
setGeneratedSql
public void setGeneratedSql(String generatedSql)
Description copied from interface:SpiQuery
Set the generated sql for debug purposes.- Specified by:
setGeneratedSql
in interfaceSpiQuery<T>
-
checkNamedParameters
public void checkNamedParameters()
Description copied from interface:SpiQuery
Check that the named parameters have had their values set.- Specified by:
checkNamedParameters
in interfaceSpiQuery<T>
-
createNamedParameter
public SpiNamedParam createNamedParameter(String name)
Description copied from interface:SpiQuery
Create a named parameter placeholder.- Specified by:
createNamedParameter
in interfaceSpiQuery<T>
-
setDefaultFetchBuffer
public void setDefaultFetchBuffer(int fetchSize)
Description copied from interface:SpiQuery
Set the JDBC fetchSize buffer hint if not explicitly set.- Specified by:
setDefaultFetchBuffer
in interfaceSpiQuery<T>
-
setBufferFetchSizeHint
public Query<T> setBufferFetchSizeHint(int bufferFetchSizeHint)
Description copied from interface:Query
A hint which for JDBC translates to the Statement.fetchSize().Gives 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.
Note that internally findEach and findEachWhile will set the fetch size if it has not already as these queries expect to process a lot of rows. If we didn't then Postgres and MySql for example would eagerly pull back all the row data and potentially consume a lot of memory in the process.
As findEach and findEachWhile automatically set the fetch size we don't have to do so generally but we might still wish to for tuning a specific use case.
- Specified by:
setBufferFetchSizeHint
in interfaceQuery<T>
-
getBufferFetchSizeHint
public int getBufferFetchSizeHint()
Description copied from interface:SpiQuery
Return the hint for Statement.setFetchSize().- Specified by:
getBufferFetchSizeHint
in interfaceSpiQuery<T>
-
setDisableReadAuditing
public Query<T> setDisableReadAuditing()
Description copied from interface:Query
Disable read auditing for this query.This is intended to be used when the query is not a user initiated query and instead part of the internal processing in an application to load a cache or document store etc. In these cases we don't want the query to be part of read auditing.
- Specified by:
setDisableReadAuditing
in interfaceQuery<T>
-
isDisableReadAudit
public boolean isDisableReadAudit()
Description copied from interface:SpiQuery
Return true if read auditing is disabled on this query.- Specified by:
isDisableReadAudit
in interfaceSpiQuery<T>
-
isFutureFetch
public boolean isFutureFetch()
Description copied from interface:SpiQuery
Return true if this is a query executing in the background.- Specified by:
isFutureFetch
in interfaceSpiQuery<T>
-
setFutureFetch
public void setFutureFetch(boolean backgroundFetch)
Description copied from interface:SpiQuery
Set to true to indicate the query is executing in a background thread asynchronously.- Specified by:
setFutureFetch
in interfaceSpiQuery<T>
-
setFutureFetchAudit
public void setFutureFetchAudit(ReadEvent event)
Description copied from interface:SpiQuery
Set the readEvent for future queries (as prepared in foreground thread).- Specified by:
setFutureFetchAudit
in interfaceSpiQuery<T>
-
getFutureFetchAudit
public ReadEvent getFutureFetchAudit()
Description copied from interface:SpiQuery
Read the readEvent for future queries (null otherwise).- Specified by:
getFutureFetchAudit
in interfaceSpiQuery<T>
-
setCancelableQuery
public void setCancelableQuery(CancelableQuery cancelableQuery)
Description copied from interface:SpiQuery
Set the underlying cancelable query (with the PreparedStatement).- Specified by:
setCancelableQuery
in interfaceSpiQuery<T>
-
setBaseTable
public Query<T> setBaseTable(String baseTable)
Description copied from interface:Query
Set the base table to use for this query.Typically this is used when a table has partitioning and we wish to specify a specific partition/table to query against.
QOrder() .setBaseTable("order_2019_05") .status.equalTo(Status.NEW) .findList();
- Specified by:
setBaseTable
in interfaceQuery<T>
-
getBaseTable
public String getBaseTable()
Description copied from interface:SpiQuery
Return the base table to use if user defined on the query.- Specified by:
getBaseTable
in interfaceSpiQuery<T>
-
alias
public DefaultOrmQuery<T> alias(String alias)
Description copied from interface:Query
Set root table alias.
-
getAlias
public String getAlias()
Description copied from interface:SpiQuery
Return root table alias set byQuery.alias(String)
command.
-
cancel
public void cancel()
Description copied from interface:Query
Cancel the query execution if supported by the underlying database and driver.This must be called from a different thread to the query executor.
-
isCancelled
public boolean isCancelled()
Description copied from interface:SpiQuery
Return true if this query has been cancelled.- Specified by:
isCancelled
in interfaceSpiQuery<T>
-
validate
public Set<String> validate()
Description copied from interface:Query
Returns the set of properties or paths that are unknown (do not map to known properties or paths).Validate the query checking the where and orderBy expression paths to confirm if they represent valid properties or paths for the given bean type.
-
validate
public Set<String> validate(BeanType<T> desc)
Validate all the expression properties/paths given the bean descriptor.
-
getUpdateProperties
public OrmUpdateProperties getUpdateProperties()
Description copied from interface:SpiQuery
Return the properties for an update query.- Specified by:
getUpdateProperties
in interfaceSpiQuery<T>
-
getProfileLocation
public ProfileLocation getProfileLocation()
Description copied from interface:SpiQuery
Return the profile location for this query.- Specified by:
getProfileLocation
in interfaceSpiQuery<T>
-
handleLoadError
public void handleLoadError(String fullName, Exception e)
Description copied from interface:SpiQuery
Handles load errors.- Specified by:
handleLoadError
in interfaceSpiQuery<T>
-
orderById
public Query<T> orderById(boolean orderById)
Description copied from interface:Query
Controls, if paginated queries should always append an 'order by id' statement at the end to guarantee a deterministic sort result. This may affect performance. If this is not enabled, and an orderBy is set on the query, it's up to the programmer that this query provides a deterministic result.
-
-