Package io.ebeaninternal.server.core
Class OrmQueryRequest<T>
- java.lang.Object
-
- io.ebeaninternal.server.core.BeanRequest
-
- io.ebeaninternal.server.core.OrmQueryRequest<T>
-
- All Implemented Interfaces:
BeanQueryRequest<T>
,SpiOrmQueryRequest<T>
,DocQueryRequest<T>
public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQueryRequest<T>
Wraps the objects involved in executing a Query.
-
-
Constructor Summary
Constructors Constructor Description OrmQueryRequest(SpiEbeanServer server, OrmQueryEngine queryEngine, SpiQuery<T> query, SpiTransaction t)
Create the InternalQueryRequest.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDependentTables(Set<String> tables)
DeployParser
createDeployParser()
JsonReadOptions
createJsonReadOptions()
Return the JsonReadOptions taking into account lazy loading and persistence context.int
delete()
Execute the query as a delete.BeanPropertyAssocMany<?>
determineMany()
Determine and return the ToMany property that is included in the query.void
endTransIfRequired()
Will end a locally created transaction.String
escapeLikeString(String value)
Return the database platform escaped like string.void
executeSecondaryQueries(boolean forEach)
Execute secondary queries.int
findCount()
Execute the find row count query.void
findEach(Consumer<T> consumer)
Execute the find returning a QueryIterator and visitor pattern.void
findEachWhile(Predicate<T> consumer)
Execute the find returning a QueryIterator and visitor pattern.Object
findId()
Execute the query as findById.<A> List<A>
findIds()
Execute the find ids query.QueryIterator<T>
findIterate()
Execute the find returning a QueryIterator.List<T>
findList()
Execute the query as findList.<K> Map<K,T>
findMap()
Execute the query as findMap.SpiResultSet
findResultSet()
Execute returning the ResultSet.Set<T>
findSet()
Execute the query as findSet.<A> List<A>
findSingleAttributeList()
Execute the findSingleAttributeList query.List<Version<T>>
findVersions()
Execute the finVersions() query.void
flushPersistenceContextOnIterate()
For iterate queries reset the persistenceContext and loadContext.String
getBaseTableAlias()
Return the base table alias for this query.List<T>
getBeanCacheHits()
Return the bean cache hits (when all hits / no misses).<K> Map<K,T>
getBeanCacheHitsAsMap()
Return the bean cache hits for findMap (when all hits / no misses).BeanDescriptor<T>
getBeanDescriptor()
Return the BeanDescriptor for the associated bean.BeanFindController
getBeanFinder()
Return a bean specific finder if one has been set.String
getDBLikeClause(boolean rawLikeExpression)
Return the database platform like clause.boolean
getFromBeanCache()
Maybe hit the bean cache returning true if everything was obtained from the cache (that there were no misses).Object
getFromQueryCache()
Try to get the query result from the query cache.LoadContext
getGraphContext()
Return the graph context for this query.int
getLazyLoadBatchSize()
Return the batch size for lazy loading on this bean query request.BeanPropertyAssocMany<?>
getManyProperty()
Return the many property that is fetched in the query or null if there is not one.PersistenceContext
getPersistenceContext()
Return the PersistenceContext used for this request.SpiQuery<T>
getQuery()
Return the find that is to be performed.CQueryPlan
getQueryPlan()
Return a queryPlan for the current query if one exists.CQueryPlanKey
getQueryPlanKey()
Return the queryPlanHash.int
getSecondaryQueriesMinBatchSize(int defaultQueryBatch)
For use with QueryIterator and secondary queries this returns the minimum batch size that should be loaded before executing the secondary queries.Object
getTenantId()
Return the tenantId associated with this request.void
initTransIfRequired()
This will create a local (readOnly) transaction if no current transaction exists.boolean
isAuditReads()
Return true if read auditing is on for this query request.boolean
isBeanCachePut()
boolean
isBeanCachePutMany()
boolean
isDeleteByStatement()
Return true if delete by statement is allowed for this type given cascade rules etc.boolean
isFindById()
Return true if this is a find by id (rather than List Set or Map).boolean
isFindIterate()
Return true if this is a findEach, findIterate type query where we expect many results.boolean
isInlineCountDistinct()
boolean
isInlineSqlUpdateLimit()
Return true if no MaxRows or use LIMIT in SQL update.boolean
isIterateSingleContext()
boolean
isMultiValueIdSupported()
Return true if multi-value binding using Array or Table Values is supported.boolean
isMultiValueSupported(Class<?> valueType)
Return true if multi-value binding is supported for this value type.boolean
isNativeSql()
boolean
isPadInExpression()
Return true if an Id IN expression should have the bind parameters padded.boolean
isQueryCachePut()
boolean
isRawSql()
Boolean
isReadOnly()
Return the Normal, sharedInstance, ReadOnly state of this query.boolean
isUseDocStore()
Return true if this query is expected to use the doc store.void
logSql(String sql)
Log the SQL if the logLevel is appropriate.void
markNotQueryOnly()
Mark the transaction as not being query only.void
mergeCacheHits(BeanCollection<T> result)
Merge in prior L2 bean cache hits with the query result.void
persistenceContextAdd(EntityBean bean)
Add the bean to the persistence context.void
prepareQuery()
Prepare the query and calculate the query plan key.void
putQueryPlan(CQueryPlan queryPlan)
Put the QueryPlan into the cache.void
putToQueryCache(Object result)
void
resetBeanCacheAutoMode(boolean findOne)
Reset Bean cache mode AUTO - require explicit setting for bean cache use with findList().void
rollbackTransIfRequired()
Rollback the transaction if it was created for this request.void
setCancelableQuery(CancelableQuery cancelableQuery)
Set an Query object that owns the PreparedStatement that can be cancelled.void
setDefaultFetchBuffer(int fetchSize)
Set the JDBC buffer fetchSize hint if not set explicitly.void
setInlineCountDistinct()
void
setIterateSingleContext()
Set when we want to use a single persistence context for all beans returned in the query (so all beans are held in memory)void
slowQueryCheck(long executionTimeMicros, int rowCount)
Check for slow query event.javax.persistence.PersistenceException
translate(String bindLog, String sql, SQLException e)
int
update()
Execute the query as a update.-
Methods inherited from class io.ebeaninternal.server.core.BeanRequest
clearTransIfRequired, commitTransIfRequired, createImplicitTransIfRequired, getDataTimeZone, getEbeanServer, getServer, getTransaction, isLogSql, isLogSummary, setTransaction
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.ebean.event.BeanQueryRequest
getEbeanServer, getTransaction
-
Methods inherited from interface io.ebeanservice.docstore.api.DocQueryRequest
getTransaction, setTransaction
-
-
-
-
Constructor Detail
-
OrmQueryRequest
public OrmQueryRequest(SpiEbeanServer server, OrmQueryEngine queryEngine, SpiQuery<T> query, SpiTransaction t)
Create the InternalQueryRequest.
-
-
Method Detail
-
translate
public javax.persistence.PersistenceException translate(String bindLog, String sql, SQLException e)
-
setIterateSingleContext
public void setIterateSingleContext()
Description copied from interface:SpiOrmQueryRequest
Set when we want to use a single persistence context for all beans returned in the query (so all beans are held in memory)- Specified by:
setIterateSingleContext
in interfaceSpiOrmQueryRequest<T>
-
isIterateSingleContext
public boolean isIterateSingleContext()
-
isDeleteByStatement
public boolean isDeleteByStatement()
Description copied from interface:SpiOrmQueryRequest
Return true if delete by statement is allowed for this type given cascade rules etc.- Specified by:
isDeleteByStatement
in interfaceSpiOrmQueryRequest<T>
-
isPadInExpression
public boolean isPadInExpression()
Description copied from interface:BeanQueryRequest
Return true if an Id IN expression should have the bind parameters padded.- Specified by:
isPadInExpression
in interfaceBeanQueryRequest<T>
-
isMultiValueIdSupported
public boolean isMultiValueIdSupported()
Description copied from interface:BeanQueryRequest
Return true if multi-value binding using Array or Table Values is supported.- Specified by:
isMultiValueIdSupported
in interfaceBeanQueryRequest<T>
-
isMultiValueSupported
public boolean isMultiValueSupported(Class<?> valueType)
Description copied from interface:BeanQueryRequest
Return true if multi-value binding is supported for this value type.- Specified by:
isMultiValueSupported
in interfaceBeanQueryRequest<T>
-
markNotQueryOnly
public void markNotQueryOnly()
Mark the transaction as not being query only.- Specified by:
markNotQueryOnly
in interfaceSpiOrmQueryRequest<T>
-
getDBLikeClause
public String getDBLikeClause(boolean rawLikeExpression)
Return the database platform like clause.- Specified by:
getDBLikeClause
in interfaceSpiOrmQueryRequest<T>
-
escapeLikeString
public String escapeLikeString(String value)
Return the database platform escaped like string.- Specified by:
escapeLikeString
in interfaceSpiOrmQueryRequest<T>
-
executeSecondaryQueries
public void executeSecondaryQueries(boolean forEach)
Description copied from interface:DocQueryRequest
Execute secondary queries.- Specified by:
executeSecondaryQueries
in interfaceDocQueryRequest<T>
-
getSecondaryQueriesMinBatchSize
public int getSecondaryQueriesMinBatchSize(int defaultQueryBatch)
For use with QueryIterator and secondary queries this returns the minimum batch size that should be loaded before executing the secondary queries.If -1 is returned then NO secondary queries are registered and simple iteration is fine.
-
isReadOnly
public Boolean isReadOnly()
Return the Normal, sharedInstance, ReadOnly state of this query.
-
getBeanDescriptor
public BeanDescriptor<T> getBeanDescriptor()
Return the BeanDescriptor for the associated bean.- Specified by:
getBeanDescriptor
in interfaceSpiOrmQueryRequest<T>
-
getGraphContext
public LoadContext getGraphContext()
Return the graph context for this query.
-
isUseDocStore
public boolean isUseDocStore()
Description copied from interface:SpiOrmQueryRequest
Return true if this query is expected to use the doc store.- Specified by:
isUseDocStore
in interfaceSpiOrmQueryRequest<T>
-
prepareQuery
public void prepareQuery()
Prepare the query and calculate the query plan key.- Specified by:
prepareQuery
in interfaceSpiOrmQueryRequest<T>
-
isNativeSql
public boolean isNativeSql()
-
isRawSql
public boolean isRawSql()
-
createDeployParser
public DeployParser createDeployParser()
-
getPersistenceContext
public PersistenceContext getPersistenceContext()
Return the PersistenceContext used for this request.
-
persistenceContextAdd
public void persistenceContextAdd(EntityBean bean)
Add the bean to the persistence context.
-
initTransIfRequired
public void initTransIfRequired()
This will create a local (readOnly) transaction if no current transaction exists.A transaction may have been passed in explicitly or currently be active in the thread local. If not, then a readOnly transaction is created to execute this query.
- Specified by:
initTransIfRequired
in interfaceSpiOrmQueryRequest<T>
-
rollbackTransIfRequired
public void rollbackTransIfRequired()
Rollback the transaction if it was created for this request.- Overrides:
rollbackTransIfRequired
in classBeanRequest
-
createJsonReadOptions
public JsonReadOptions createJsonReadOptions()
Return the JsonReadOptions taking into account lazy loading and persistence context.- Specified by:
createJsonReadOptions
in interfaceDocQueryRequest<T>
-
flushPersistenceContextOnIterate
public void flushPersistenceContextOnIterate()
For iterate queries reset the persistenceContext and loadContext.
-
endTransIfRequired
public void endTransIfRequired()
Will end a locally created transaction.It ends the query only transaction.
- Specified by:
endTransIfRequired
in interfaceSpiOrmQueryRequest<T>
-
isFindById
public boolean isFindById()
Return true if this is a find by id (rather than List Set or Map).
-
isFindIterate
public boolean isFindIterate()
Return true if this is a findEach, findIterate type query where we expect many results.
-
delete
public int delete()
Execute the query as a delete.- Specified by:
delete
in interfaceSpiOrmQueryRequest<T>
-
update
public int update()
Execute the query as a update.- Specified by:
update
in interfaceSpiOrmQueryRequest<T>
-
findResultSet
public SpiResultSet findResultSet()
Description copied from interface:SpiOrmQueryRequest
Execute returning the ResultSet.- Specified by:
findResultSet
in interfaceSpiOrmQueryRequest<T>
-
findId
public Object findId()
Execute the query as findById.- Specified by:
findId
in interfaceSpiOrmQueryRequest<T>
-
findCount
public int findCount()
Description copied from interface:SpiOrmQueryRequest
Execute the find row count query.- Specified by:
findCount
in interfaceSpiOrmQueryRequest<T>
-
findIds
public <A> List<A> findIds()
Description copied from interface:SpiOrmQueryRequest
Execute the find ids query.- Specified by:
findIds
in interfaceSpiOrmQueryRequest<T>
-
findEach
public void findEach(Consumer<T> consumer)
Description copied from interface:SpiOrmQueryRequest
Execute the find returning a QueryIterator and visitor pattern.- Specified by:
findEach
in interfaceSpiOrmQueryRequest<T>
-
findEachWhile
public void findEachWhile(Predicate<T> consumer)
Description copied from interface:SpiOrmQueryRequest
Execute the find returning a QueryIterator and visitor pattern.- Specified by:
findEachWhile
in interfaceSpiOrmQueryRequest<T>
-
findIterate
public QueryIterator<T> findIterate()
Description copied from interface:SpiOrmQueryRequest
Execute the find returning a QueryIterator.- Specified by:
findIterate
in interfaceSpiOrmQueryRequest<T>
-
findList
public List<T> findList()
Execute the query as findList.- Specified by:
findList
in interfaceSpiOrmQueryRequest<T>
-
findVersions
public List<Version<T>> findVersions()
Description copied from interface:SpiOrmQueryRequest
Execute the finVersions() query.- Specified by:
findVersions
in interfaceSpiOrmQueryRequest<T>
-
findSet
public Set<T> findSet()
Execute the query as findSet.- Specified by:
findSet
in interfaceSpiOrmQueryRequest<T>
-
findMap
public <K> Map<K,T> findMap()
Execute the query as findMap.- Specified by:
findMap
in interfaceSpiOrmQueryRequest<T>
-
findSingleAttributeList
public <A> List<A> findSingleAttributeList()
Execute the findSingleAttributeList query.- Specified by:
findSingleAttributeList
in interfaceSpiOrmQueryRequest<T>
-
getBeanFinder
public BeanFindController getBeanFinder()
Return a bean specific finder if one has been set.
-
getQuery
public SpiQuery<T> getQuery()
Return the find that is to be performed.- Specified by:
getQuery
in interfaceBeanQueryRequest<T>
- Specified by:
getQuery
in interfaceDocQueryRequest<T>
- Specified by:
getQuery
in interfaceSpiOrmQueryRequest<T>
-
determineMany
public BeanPropertyAssocMany<?> determineMany()
Determine and return the ToMany property that is included in the query.
-
getManyProperty
public BeanPropertyAssocMany<?> getManyProperty()
Return the many property that is fetched in the query or null if there is not one.
-
getQueryPlan
public CQueryPlan getQueryPlan()
Return a queryPlan for the current query if one exists. Returns null if no query plan for this query exists.
-
getQueryPlanKey
public CQueryPlanKey getQueryPlanKey()
Return the queryPlanHash.This identifies the query plan for a given bean type. It effectively matches a SQL statement with ? bind variables. A query plan can be reused with just the bind variables changing.
-
putQueryPlan
public void putQueryPlan(CQueryPlan queryPlan)
Put the QueryPlan into the cache.
-
resetBeanCacheAutoMode
public void resetBeanCacheAutoMode(boolean findOne)
Description copied from interface:SpiOrmQueryRequest
Reset Bean cache mode AUTO - require explicit setting for bean cache use with findList().- Specified by:
resetBeanCacheAutoMode
in interfaceSpiOrmQueryRequest<T>
-
isQueryCachePut
public boolean isQueryCachePut()
-
isBeanCachePutMany
public boolean isBeanCachePutMany()
-
isBeanCachePut
public boolean isBeanCachePut()
-
mergeCacheHits
public void mergeCacheHits(BeanCollection<T> result)
Merge in prior L2 bean cache hits with the query result.
-
getBeanCacheHits
public List<T> getBeanCacheHits()
Description copied from interface:SpiOrmQueryRequest
Return the bean cache hits (when all hits / no misses).- Specified by:
getBeanCacheHits
in interfaceSpiOrmQueryRequest<T>
-
getBeanCacheHitsAsMap
public <K> Map<K,T> getBeanCacheHitsAsMap()
Description copied from interface:SpiOrmQueryRequest
Return the bean cache hits for findMap (when all hits / no misses).- Specified by:
getBeanCacheHitsAsMap
in interfaceSpiOrmQueryRequest<T>
-
getFromBeanCache
public boolean getFromBeanCache()
Description copied from interface:SpiOrmQueryRequest
Maybe hit the bean cache returning true if everything was obtained from the cache (that there were no misses). Do this for findList() on many natural keys or many Ids.- Specified by:
getFromBeanCache
in interfaceSpiOrmQueryRequest<T>
-
getFromQueryCache
public Object getFromQueryCache()
Try to get the query result from the query cache.- Specified by:
getFromQueryCache
in interfaceSpiOrmQueryRequest<T>
-
putToQueryCache
public void putToQueryCache(Object result)
-
setCancelableQuery
public void setCancelableQuery(CancelableQuery cancelableQuery)
Set an Query object that owns the PreparedStatement that can be cancelled.
-
getLazyLoadBatchSize
public int getLazyLoadBatchSize()
Return the batch size for lazy loading on this bean query request.
-
isAuditReads
public boolean isAuditReads()
Return true if read auditing is on for this query request.This means that read audit is on for this bean type and that query has not explicitly disabled it.
-
getBaseTableAlias
public String getBaseTableAlias()
Return the base table alias for this query.
-
setDefaultFetchBuffer
public void setDefaultFetchBuffer(int fetchSize)
Set the JDBC buffer fetchSize hint if not set explicitly.
-
getTenantId
public Object getTenantId()
Return the tenantId associated with this request.
-
slowQueryCheck
public void slowQueryCheck(long executionTimeMicros, int rowCount)
Check for slow query event.
-
setInlineCountDistinct
public void setInlineCountDistinct()
-
isInlineCountDistinct
public boolean isInlineCountDistinct()
-
addDependentTables
public void addDependentTables(Set<String> tables)
-
isInlineSqlUpdateLimit
public boolean isInlineSqlUpdateLimit()
Return true if no MaxRows or use LIMIT in SQL update.
-
-