Package com.clickhouse.client
Class ClickHouseParameterizedQuery
java.lang.Object
com.clickhouse.client.ClickHouseParameterizedQuery
- All Implemented Interfaces:
Serializable
A parameterized query is a parsed query with parameters being extracted for
substitution.
Here parameter is define in the format of :<name>[(<type>)]. It
starts with colon, immediately followed by name, and then optionally type
within brackets. For example: in query "select :no as no, :name(String) as
name", we have two parameters: no and name. Moreover, type of
the last parameter is String.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA part of query. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedClickHouseParameterizedQuery(ClickHouseConfig config, String query) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds part of query and the following parameter.protected voidAdds part of query and the following parameter.protected StringBuilderappendLastPartIfExists(StringBuilder builder) Appends last part of the query if it exists.voidapply(StringBuilder builder, Object[] values) Applies raw parameters to the given string builder.voidapply(StringBuilder builder, Object param, Object... more) Applies raw parameters to the given string builder.voidapply(StringBuilder builder, String[] values) Applies stringified parameters to the given string builder.voidapply(StringBuilder builder, String param, String... more) Applies stringified parameters to the given string builder.static voidSubstitute named parameters in given SQL.voidapply(StringBuilder builder, Collection<String> params) Applies stringified parameters to the given string builder.voidapply(StringBuilder builder, Map<String, String> params) Applies stringified parameters to the given string builder.static StringSubstitute named parameters in given SQL.booleanGets original query.Gets named parameters.Gets parameter templates for converting value to SQL expression.protected List<ClickHouseParameterizedQuery.QueryPart>getParts()Gets immutable list of query parts.Gets query parts.inthashCode()booleanChecks if the query has at least one parameter or not.static ClickHouseParameterizedQueryof(ClickHouseConfig config, String query) Creates an instance by parsing the given query.protected Stringparse()Parses the query given in constructor.protected StringtoSqlExpression(String paramName, Object value) Converts given raw value to SQL expression.
-
Field Details
-
config
-
originalQuery
-
-
Constructor Details
-
ClickHouseParameterizedQuery
Default constructor.- Parameters:
config- non-null configquery- non-blank query
-
-
Method Details
-
apply
Substitute named parameters in given SQL.- Parameters:
sql- SQL containing named parametersparams- mapping between parameter name and correspoding SQL expression(NOT raw value)- Returns:
- substituted SQL, or the given sql if one of
sqlandparamsis null or empty
-
apply
Substitute named parameters in given SQL.- Parameters:
builder- non-null string buildersql- SQL containing named parametersparams- mapping between parameter name and correspoding SQL expression(NOT raw value)
-
of
Creates an instance by parsing the given query.- Parameters:
config- non-null configquery- non-empty SQL query- Returns:
- parameterized query
-
addPart
Adds part of query and the following parameter.- Parameters:
part- part of the query, between previous and current parameterparamIndex- zero-based index of the parameterparamType- type of the parameter, could be null
-
addPart
Adds part of query and the following parameter.- Parameters:
part- part of the query, between previous and current parameterparamIndex- zero-based index of the parameterparamName- name of the parameter, null meansString.valueOf(paramIndex)paramType- type of the parameter, could be null
-
getParts
Gets immutable list of query parts.- Returns:
- immutable list of query parts
-
parse
Parses the query given in constructor.- Returns:
- remaining part(right after the last parameter) after parsing, could be null
-
appendLastPartIfExists
Appends last part of the query if it exists.- Parameters:
builder- non-null string builder- Returns:
- the builder
-
toSqlExpression
Converts given raw value to SQL expression.- Parameters:
paramName- name of the parametervalue- raw value, could be null- Returns:
- non-null SQL expression
-
apply
Applies stringified parameters to the given string builder.- Parameters:
builder- non-null string builderparams- stringified parameters
-
apply
Applies stringified parameters to the given string builder.- Parameters:
builder- non-null string builderparams- stringified parameters
-
apply
Applies raw parameters to the given string builder.ClickHouseValues.convertToSqlExpression(Object)will be used to stringify the parameters.- Parameters:
builder- non-null string builderparam- raw parametermore- more raw parameters if any
-
apply
Applies raw parameters to the given string builder.ClickHouseValues.convertToSqlExpression(Object)will be used to stringify the parameters.- Parameters:
builder- non-null string buildervalues- raw parameters
-
apply
Applies stringified parameters to the given string builder.- Parameters:
builder- non-null string builderparam- stringified parametermore- more stringified parameters if any
-
apply
Applies stringified parameters to the given string builder.- Parameters:
builder- non-null string buildervalues- stringified parameters
-
getParameters
Gets named parameters.- Returns:
- list of named parameters
-
getOriginalQuery
Gets original query.- Returns:
- original query
-
getQueryParts
Gets query parts. Each part is composed of a snippet taken fromgetOriginalQuery(), followed by a parameter name, which might be null.- Returns:
- query parts
-
getParameterTemplates
Gets parameter templates for converting value to SQL expression.- Returns:
- parameter templates
-
hasParameter
public boolean hasParameter()Checks if the query has at least one parameter or not.- Returns:
- true if there's at least one parameter; false otherwise
-
hashCode
public int hashCode() -
equals
-