Package com.axelor.db
Class QueryBinder
- java.lang.Object
-
- com.axelor.db.QueryBinder
-
public class QueryBinder extends Object
The query binder class provides the helper methods to bind query parameters and mark the query cacheable.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryBinder
bind(String name, Object value)
Bind the given named parameter with the given value.QueryBinder
bind(Map<String,Object> namedParams, Object... params)
Bind the query with the given named and/or positional parameters.javax.persistence.Query
getQuery()
Get the underlying query instance.static QueryBinder
of(javax.persistence.Query query)
Create a new query binder for the given query instance.QueryBinder
opts(boolean cacheable, javax.persistence.FlushModeType type)
Shortcut to thesetCacheable()
andsetFlushMode(FlushModeType)
methods.QueryBinder
setCacheable()
Set the query cacheable.QueryBinder
setCacheable(boolean cacheable)
Set whether to set the query cacheable or not.QueryBinder
setFlushMode(javax.persistence.FlushModeType mode)
Set query flush mode.QueryBinder
setReadOnly()
Set the query readOnly.QueryBinder
setReadOnly(boolean readOnly)
Set the query readOnly.
-
-
-
Method Detail
-
of
public static QueryBinder of(javax.persistence.Query query)
Create a new query binder for the given query instance.- Parameters:
query
- the query instance- Returns:
- a new query binder instance
-
setCacheable
public QueryBinder setCacheable()
Set the query cacheable.- Returns:
- the same query binder instance
-
setCacheable
public QueryBinder setCacheable(boolean cacheable)
Set whether to set the query cacheable or not.- Parameters:
cacheable
- whether to set cacheable or not- Returns:
- the same query binder instance
-
setReadOnly
public QueryBinder setReadOnly()
Set the query readOnly.- Returns:
- the same query binder instance
-
setReadOnly
public QueryBinder setReadOnly(boolean readOnly)
Set the query readOnly.This will give better performance if the result is not meant for updates. For example, REST api data fetching can benefit from this.
- Returns:
- the same query binder instance
-
setFlushMode
public QueryBinder setFlushMode(javax.persistence.FlushModeType mode)
Set query flush mode.- Parameters:
mode
- flush mode- Returns:
- the same query binder instance
-
opts
public QueryBinder opts(boolean cacheable, javax.persistence.FlushModeType type)
Shortcut to thesetCacheable()
andsetFlushMode(FlushModeType)
methods.- Parameters:
cacheable
- whether to mark the query cacheabletype
- theFlushModeType
, only set if type is not null- Returns:
- the same query binder instance
-
bind
public QueryBinder bind(Map<String,Object> namedParams, Object... params)
Bind the query with the given named and/or positional parameters.The parameter values will be automatically adapted to correct data type of the query parameter.
- Parameters:
namedParams
- the named parametersparams
- the positional parameters- Returns:
- the same query binder instance
-
bind
public QueryBinder bind(String name, Object value)
Bind the given named parameter with the given value.- Parameters:
name
- the named parametervalue
- the parameter value- Returns:
- the same query binder instance
-
getQuery
public javax.persistence.Query getQuery()
Get the underlying query instance.- Returns:
- the query instance
-
-