Package org.fryske_akademy.jpa
Class JpqlBuilderImpl
- java.lang.Object
-
- org.fryske_akademy.jpa.JpqlBuilderImpl
-
- All Implemented Interfaces:
JpqlBuilder
@Singleton public class JpqlBuilderImpl extends Object implements JpqlBuilder
Stateless, threadsafe builder containing functions for building jpql}. Supports all comparison expressions except "between" when building jpql.- Author:
- eduard
-
-
Field Summary
Fields Modifier and Type Field Description static StringENTITY_PREFIX
-
Constructor Summary
Constructors Constructor Description JpqlBuilderImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringorderClause(Map<String,CrudReadService.SORTORDER> sort)builds an order by clause, usesENTITY_PREFIX.protected voidset(javax.persistence.Query q, String key, Object value)When the Query has the parameter "key" callQuery.setParameter(java.lang.String, java.lang.Object)otherwise callQuery.setParameter(int, java.lang.Object)with Short.valueOf(key), because then a positional parameter in a native query is assumed.voidsetParam(javax.persistence.Query q, Param param)Fills parameters prepared insetWhereParams(javax.persistence.Query, java.util.List), if the type of the field in the query is a Short or an Integer and the paramValue is a String, it is converted accordingly.voidsetWhereParams(javax.persistence.Query q, List<Param> params)CallssetParam(Query, Param)for each filter.StringwhereClause(List<Param> params)builds a where clause, callswhereCondition(Param)for every entry.StringwhereCondition(Param param)builds a where condition, prepares query parameters later filled insetWhereParams(javax.persistence.Query, java.util.List).
-
-
-
Field Detail
-
ENTITY_PREFIX
public static final String ENTITY_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
orderClause
public String orderClause(Map<String,CrudReadService.SORTORDER> sort)
builds an order by clause, usesENTITY_PREFIX.- Specified by:
orderClausein interfaceJpqlBuilder- Parameters:
sort-- Returns:
-
whereClause
public String whereClause(List<Param> params)
builds a where clause, callswhereCondition(Param)for every entry.- Specified by:
whereClausein interfaceJpqlBuilder- Parameters:
params-- Returns:
- See Also:
JpqlBuilder.whereCondition(Param),JpqlBuilder.setWhereParams(javax.persistence.Query, java.util.List)
-
whereCondition
public String whereCondition(Param param)
builds a where condition, prepares query parameters later filled insetWhereParams(javax.persistence.Query, java.util.List). "member of" support for singular param value and for a collection as param value, when param value is a collection multiple "member of" conditions are generated. "between" is not supported.- Specified by:
whereConditionin interfaceJpqlBuilder- Parameters:
param-- Returns:
- See Also:
JpqlBuilder.setWhereParams(javax.persistence.Query, java.util.List)
-
setWhereParams
public void setWhereParams(javax.persistence.Query q, List<Param> params)CallssetParam(Query, Param)for each filter.- Specified by:
setWhereParamsin interfaceJpqlBuilder- Parameters:
q-params-
-
set
protected void set(javax.persistence.Query q, String key, Object value)When the Query has the parameter "key" callQuery.setParameter(java.lang.String, java.lang.Object)otherwise callQuery.setParameter(int, java.lang.Object)with Short.valueOf(key), because then a positional parameter in a native query is assumed. When the value is anOPERATORuseOPERATOR.getUserInput()as value.- Parameters:
q-key-value-
-
setParam
public void setParam(javax.persistence.Query q, Param param)Fills parameters prepared insetWhereParams(javax.persistence.Query, java.util.List), if the type of the field in the query is a Short or an Integer and the paramValue is a String, it is converted accordingly. For native queriesParam.getParamKey()should be a numeric positional parameter. When the operator is member of and the value is a Collection a value is set for each entry in the collection, for this a parameter keyParam.getParamKey()with an index number appended is assumed,whereCondition(Param)prepares this. For the type check eitherParameter.getParameterType()is used, or, when null,Param.getParamType(). Via Param you have full control over the Object that is used as paramValue.- Specified by:
setParamin interfaceJpqlBuilder- Parameters:
q-param-
-
-