Package org.fryske_akademy.jpa
Class Param.Builder
- java.lang.Object
-
- org.fryske_akademy.jpa.Param.Builder
-
- Enclosing class:
- Param
public static class Param.Builder extends Object
A factory for Param objects, parameter values can be added in two ways:- as (the correct) Object => only syntax and wildcard support for String values
- as a String using a converter => syntax support also for non String values, no wildcard support
Users may use syntax in values they submit (comparisons must be at the start):
- wildcards: * and ?
- !
- (!)is null
- (!)is empty
- (!)is blank
- (!)>(=)
- (!)<(=)
- 1 <=> 10
- 1 <=> 10 AND >12
- < 3 OR >6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classParam.Builder.DefaultWildcardMapping* => %, ? => _, NOTE that this mapping causes all four characters to be interpreted as wildcards in jpql/sql.static interfaceParam.Builder.WildcardMappingtranslation table for wildcards
-
Field Summary
Fields Modifier and Type Field Description static Param.Builder.WildcardMappingDEFAULT_MAPPING
-
Constructor Summary
Constructors Constructor Description Builder()Builder with syntax support in value (!, >[=], <[=], [!]is null, [!]is empty, [!]is blank).Builder(boolean caseInsensitive)CallsBuilder(boolean, WildcardMapping, boolean)} with true, null and the caseInsensitive argument.Builder(boolean syntaxInValue, Param.Builder.WildcardMapping wildcardMapping, boolean caseInsensitive)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Param.Builderadd(String paramKey, Object paramValue)This method is suitable when your paramValue is the correct object for the query to be executed.Param.Builderadd(String paramKey, Object paramValue, boolean or)This method is suitable when your paramValue is the correct object for the query to be executed.Param.Builderadd(String paramKey, String paramValue, boolean or, com.vectorprint.StringConverter converter)This method is suitable when your paramValue is a String that must be converted to get the correct object for the query to be executed.Param.Builderadd(String paramKey, String paramValue, com.vectorprint.StringConverter converter)This method is suitable when your paramValue is a String that must be converted to get the correct object for the query to be executed.Param.Builderadd(String propertyPath, String paramKey, Object paramValue, boolean or)This method is suitable when your paramValue is the correct object for the query to be executed.Param.Builderadd(String paramKey, String paramValue, String operator, boolean or, com.vectorprint.StringConverter converter)Assumes key and propertyPath are the sameParam.Builderadd(String propertyPath, String paramKey, String paramValue, com.vectorprint.StringConverter converter)This method is suitable when your paramValue is a String that must be converted to get the correct object for the query to be executed.Param.Builderadd(String propertyPath, String paramKey, String operator, Object paramValue, boolean not, boolean or)Callsadd(String, String, String, Object, boolean, boolean, Object)with null for maxValueParam.Builderadd(String propertyPath, String paramKey, String operator, Object paramValue, boolean not, boolean or, Object maxValue)Param.Builderadd(String propertyPath, String paramKey, String operator, String paramValue, boolean or, com.vectorprint.StringConverter converter)Bottleneck method for String values, when configured in the Builder, applies syntax support and wildcard mapping, applies conversion when a converter is supplied.Param.Builderadd(String propertyPath, String paramKey, OPERATOR operator, Object paramValue, boolean not, boolean or)Callsadd(String, String, OPERATOR, Object, boolean, boolean, Object)with null for maxValueParam.Builderadd(String propertyPath, String paramKey, OPERATOR operator, Object paramValue, boolean not, boolean or, Object maxValue)Bottleneck method, adds a new Param, does not apply any intelligence.Param.BuilderaddParam(List<Param> p)Param.BuilderaddParam(Param... p)List<Param>build()usefull if for example you need to add parameters yielded by a diffently configured builderParam.BuildercheckNotNull(String propertyPath)Param.Builderclear()booleancontainsKey(String key)booleanisNegation(String value)check if a string (user value) indicates a negation when syntaxInValue is usedbooleanisSyntaxInValue()when true wildcards are not replaced and syntax in value is not appliedParam.Builderremove(String paramKey)Param.BuildersetGroupEndsLastParam(int group)how many groups does the last parameter end, ")";Param.BuildersetGroupEndsParam(int group, int paramIndex)Param.BuildersetGroupEndsParam(int group, String key)Param.BuildersetGroupStartsLastParam(int group)how many groups does the last parameter start, "(";Param.BuildersetGroupStartsParam(int group, int paramIndex)Param.BuildersetGroupStartsParam(int group, String key)
-
-
-
Field Detail
-
DEFAULT_MAPPING
public static final Param.Builder.WildcardMapping DEFAULT_MAPPING
-
-
Constructor Detail
-
Builder
public Builder(boolean syntaxInValue, Param.Builder.WildcardMapping wildcardMapping, boolean caseInsensitive)
-
Builder
public Builder()
Builder with syntax support in value (!, >[=], <[=], [!]is null, [!]is empty, [!]is blank). CallsBuilder(boolean, WildcardMapping, boolean)with true, null and false.
-
Builder
public Builder(boolean caseInsensitive)
CallsBuilder(boolean, WildcardMapping, boolean)} with true, null and the caseInsensitive argument.- Parameters:
caseInsensitive-
-
-
Method Detail
-
add
public Param.Builder add(String paramKey, Object paramValue)
This method is suitable when your paramValue is the correct object for the query to be executed. It uses "like" as operator for String, otherwise "=".- Parameters:
paramKey-paramValue-- Returns:
-
add
public Param.Builder add(String paramKey, Object paramValue, boolean or)
This method is suitable when your paramValue is the correct object for the query to be executed. It uses "like" as operator for String, otherwise "=".- Parameters:
paramKey-paramValue-or- will be prepended to parameters in the query except the first- Returns:
-
add
public Param.Builder add(String propertyPath, String paramKey, Object paramValue, boolean or)
This method is suitable when your paramValue is the correct object for the query to be executed. The propertyPath may differ from key allowing you to apply multiple comparisons for the same propertyPath (i.e. e.column1=:column1 or e.column1=:column2). It uses "like" as operator for String, otherwise "=".- Parameters:
propertyPath-paramKey-paramValue-or- will be prepended to parameters in the query except the first- Returns:
-
add
public Param.Builder add(String paramKey, String paramValue, com.vectorprint.StringConverter converter)
This method is suitable when your paramValue is a String that must be converted to get the correct object for the query to be executed. It uses "like" as operator when converter is null otherwise "=".- Parameters:
paramKey-paramValue-converter- seeStringConverter- Returns:
-
add
public Param.Builder add(String propertyPath, String paramKey, String paramValue, com.vectorprint.StringConverter converter)
This method is suitable when your paramValue is a String that must be converted to get the correct object for the query to be executed. The propertyPath may differ from key allowing you to apply multiple comparisons for the same propertyPath (i.e. e.column1=:column1 or e.column1=:column2). It uses "like" as operator when converter is null otherwise "=".- Parameters:
propertyPath-paramKey-paramValue-converter- seeStringConverter- Returns:
-
add
public Param.Builder add(String paramKey, String paramValue, boolean or, com.vectorprint.StringConverter converter)
This method is suitable when your paramValue is a String that must be converted to get the correct object for the query to be executed. It uses "like" as operator when converter is null otherwise "=".- Parameters:
paramKey-paramValue-or-converter- seeStringConverter- Returns:
-
add
public Param.Builder add(String paramKey, String paramValue, String operator, boolean or, com.vectorprint.StringConverter converter)
Assumes key and propertyPath are the same- Parameters:
paramKey-paramValue-operator-or-converter-- Returns:
-
add
public Param.Builder add(String propertyPath, String paramKey, String operator, String paramValue, boolean or, com.vectorprint.StringConverter converter)
Bottleneck method for String values, when configured in the Builder, applies syntax support and wildcard mapping, applies conversion when a converter is supplied. NOTE that when using AND or OR as syntax, multiple parameters will be added, where the name of the key is the concatenation of the original key with the index of the parameter added, starting at 0. Callsadd(String, String, OPERATOR, Object, boolean, boolean, Object)} withOPERATOR.operator(String, String, boolean)for the operator. The value will be the empty string whenOPERATOR.valueIsOperator(String, boolean)is true, will beStringConverter.convert(java.lang.String)when a converter is provided (negation is stripped), otherwise the value is returned with wildcards replaced and negation stripped (provided syntax support in values is active).- Parameters:
propertyPath- The propertyPath may differ from key allowing you to apply multiple comparisons for the same propertyPath (i.e. e.column1=:column1 or e.column1=:column2).paramKey-operator-paramValue-or-converter- seeStringConverter- Returns:
-
checkNotNull
public Param.Builder checkNotNull(String propertyPath)
-
setGroupStartsLastParam
public Param.Builder setGroupStartsLastParam(int group)
how many groups does the last parameter start, "(";- Returns:
-
setGroupStartsParam
public Param.Builder setGroupStartsParam(int group, String key)
-
setGroupStartsParam
public Param.Builder setGroupStartsParam(int group, int paramIndex)
-
setGroupEndsLastParam
public Param.Builder setGroupEndsLastParam(int group)
how many groups does the last parameter end, ")";- Returns:
-
setGroupEndsParam
public Param.Builder setGroupEndsParam(int group, int paramIndex)
-
setGroupEndsParam
public Param.Builder setGroupEndsParam(int group, String key)
-
add
public Param.Builder add(String propertyPath, String paramKey, OPERATOR operator, Object paramValue, boolean not, boolean or, Object maxValue)
Bottleneck method, adds a new Param, does not apply any intelligence.- Parameters:
propertyPath- The propertyPath may differ from key allowing you to apply multiple comparisons for the same propertyPath (i.e. e.column1=:column1 or e.column1=:column2).paramKey-operator-paramValue-not-or-maxValue- forOPERATOR.BETWEEN- Returns:
- Throws:
IllegalArgumentException- when paramKey is already present, value is null or invalid BETWEEN values
-
add
public Param.Builder add(String propertyPath, String paramKey, OPERATOR operator, Object paramValue, boolean not, boolean or)
Callsadd(String, String, OPERATOR, Object, boolean, boolean, Object)with null for maxValue- Parameters:
propertyPath-paramKey-operator-paramValue-not-or-- Returns:
-
add
public Param.Builder add(String propertyPath, String paramKey, String operator, Object paramValue, boolean not, boolean or, Object maxValue)
Callsadd(String, String, OPERATOR, Object, boolean, boolean, Object)withOPERATOR.fromToken(String)- Parameters:
propertyPath-paramKey-operator-paramValue-not-or-maxValue- forOPERATOR.BETWEEN- Returns:
-
add
public Param.Builder add(String propertyPath, String paramKey, String operator, Object paramValue, boolean not, boolean or)
Callsadd(String, String, String, Object, boolean, boolean, Object)with null for maxValue- Parameters:
propertyPath-paramKey-operator-paramValue-not-or-- Returns:
-
remove
public Param.Builder remove(String paramKey)
-
clear
public Param.Builder clear()
-
isNegation
public boolean isNegation(String value)
check if a string (user value) indicates a negation when syntaxInValue is used- Parameters:
value-- Returns:
- See Also:
OPERATOR.negation(String)
-
addParam
public Param.Builder addParam(List<Param> p)
-
addParam
public Param.Builder addParam(Param... p)
-
build
public List<Param> build()
usefull if for example you need to add parameters yielded by a diffently configured builder- Returns:
-
isSyntaxInValue
public boolean isSyntaxInValue()
when true wildcards are not replaced and syntax in value is not applied- Returns:
-
containsKey
public boolean containsKey(String key)
-
-