Top Description Inners Fields Constructors Methods
org.springframework.r2dbc.core

pack-priv abstract Class NamedParameterUtils

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collection, .HashSet, .Iterator, .List, .Map, .Set, .TreeMap, io.r2dbc.spi.Parameter, org.springframework.dao.InvalidDataAccessApiUsageException, org.springframework.lang.Nullable, org.springframework.r2dbc.core.binding.BindMarker, .BindMarkers, .BindMarkersFactory, .BindTarget, org.springframework.util.Assert

Helper methods for named parameter parsing.

Only intended for internal use within Spring's R2DBC framework.

References to the same parameter name are substituted with the same bind marker placeholder if a BindMarkersFactory uses identifiable placeholders.

Authors
Thomas Risberg, Juergen Hoeller, Mark Paluch, Anton Naydenov
Since
5.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
NamedParameterUtils.ExpandedQuery

Expanded query that allows binding of parameters using parameter names that were used to expand the query.

pack-priv static class
NamedParameterUtils.NamedParameters

Holder for bind markers progress.

private static class

Field Summary

Modifier and TypeField and Description
private static final String
PARAMETER_SEPARATORS

Set of characters that qualify as parameter separators, indicating that a parameter name in an SQL String has ended.

private static final boolean[]
separatorIndex

An index with separator flags per character code.

private static final String[]
START_SKIP

Set of characters that qualify as comment or quotes starting characters.

private static final String[]
STOP_SKIP

Set of characters that at are the corresponding comment or quotes ending characters.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static int
addNamedParameter(List<NamedParameterUtils.ParameterHolder> parameterList, int totalParameterCount, int escapes, int i, int j, String parameter)

private static int
addNewNamedParameter(Set<String> namedParameters, int namedParameterCount, String parameter)

private static boolean
isParameterSeparator(char c)

Determine whether a parameter name ends at the current position, that is, whether the given character qualifies as a separator.

public static ParsedSql

Returns:

the parsed statement, represented as ParsedSql instance
parseSqlStatement
(String
the SQL statement
sql
)

Parse the SQL statement and locate any placeholders or named parameters.

private static int

Returns:

next position to process after any comments or quotes are skipped
skipCommentsAndQuotes
(char[]
character array containing SQL statement
statement
,
int
current position of statement
position
)

Skip over comments and quoted names present in an SQL statement.

public static PreparedOperation<String>

Returns:

the expanded query that accepts bind parameters and allows for execution without further translation
substituteNamedParameters
(ParsedSql
the parsed representation of the SQL statement
parsedSql
,
BindMarkersFactory
the bind marker factory.
bindMarkersFactory
,
BindParameterSource
the source for named parameters
paramSource
)

Parse the SQL statement and locate any placeholders or named parameters.

public static PreparedOperation<String>

Returns:

the expanded query that accepts bind parameters and allows for execution without further translation
substituteNamedParameters
(String
the SQL statement
sql
,
BindMarkersFactory
the bind marker factory
bindMarkersFactory
,
BindParameterSource
the source for named parameters
paramSource
)

Parse the SQL statement and locate any placeholders or named parameters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PARAMETER_SEPARATORSback to summary
private static final String PARAMETER_SEPARATORS

Set of characters that qualify as parameter separators, indicating that a parameter name in an SQL String has ended.

separatorIndexback to summary
private static final boolean[] separatorIndex

An index with separator flags per character code. Technically only needed between 34 and 124 at this point.

START_SKIPback to summary
private static final String[] START_SKIP

Set of characters that qualify as comment or quotes starting characters.

STOP_SKIPback to summary
private static final String[] STOP_SKIP

Set of characters that at are the corresponding comment or quotes ending characters.

Constructor Detail

NamedParameterUtilsback to summary
pack-priv NamedParameterUtils()

Method Detail

addNamedParameterback to summary
private static int addNamedParameter(List<NamedParameterUtils.ParameterHolder> parameterList, int totalParameterCount, int escapes, int i, int j, String parameter)
addNewNamedParameterback to summary
private static int addNewNamedParameter(Set<String> namedParameters, int namedParameterCount, String parameter)
isParameterSeparatorback to summary
private static boolean isParameterSeparator(char c)

Determine whether a parameter name ends at the current position, that is, whether the given character qualifies as a separator.

parseSqlStatementback to summary
public static ParsedSql parseSqlStatement(String sql)

Parse the SQL statement and locate any placeholders or named parameters. Named parameters are substituted for an R2DBC placeholder.

Parameters
sql:String

the SQL statement

Returns:ParsedSql

the parsed statement, represented as ParsedSql instance

skipCommentsAndQuotesback to summary
private static int skipCommentsAndQuotes(char[] statement, int position)

Skip over comments and quoted names present in an SQL statement.

Parameters
statement:char[]

character array containing SQL statement

position:int

current position of statement

Returns:int

next position to process after any comments or quotes are skipped

substituteNamedParametersback to summary
public static PreparedOperation<String> substituteNamedParameters(ParsedSql parsedSql, BindMarkersFactory bindMarkersFactory, BindParameterSource paramSource)

Parse the SQL statement and locate any placeholders or named parameters. Named parameters are substituted for an R2DBC placeholder, and any select list is expanded to the required number of placeholders. Select lists may contain an array of objects, and in that case the placeholders will be grouped and enclosed with parentheses. This allows for the use of "expression lists" in the SQL statement like: select id, name, state from table where (name, age) in (('John', 35), ('Ann', 50))

The parameter values passed in are used to determine the number of placeholders to be used for a select list. Select lists should be limited to 100 or fewer elements. A larger number of elements is not guaranteed to be supported by the database and is strictly vendor-dependent.

Parameters
parsedSql:ParsedSql

the parsed representation of the SQL statement

bindMarkersFactory:BindMarkersFactory

the bind marker factory.

paramSource:BindParameterSource

the source for named parameters

Returns:PreparedOperation<String>

the expanded query that accepts bind parameters and allows for execution without further translation

See Also
parseSqlStatement
substituteNamedParametersback to summary
public static PreparedOperation<String> substituteNamedParameters(String sql, BindMarkersFactory bindMarkersFactory, BindParameterSource paramSource)

Parse the SQL statement and locate any placeholders or named parameters. Named parameters are substituted for a native placeholder and any select list is expanded to the required number of placeholders.

Parameters
sql:String

the SQL statement

bindMarkersFactory:BindMarkersFactory

the bind marker factory

paramSource:BindParameterSource

the source for named parameters

Returns:PreparedOperation<String>

the expanded query that accepts bind parameters and allows for execution without further translation

org.springframework.r2dbc.core back to summary

private Class NamedParameterUtils.ExpandedQuery

extends Object
implements PreparedOperation<String>
Class Inheritance
  • java.lang.Object
  • org.springframework.r2dbc.core.NamedParameterUtils.ExpandedQuery
All Implemented Interfaces
org.springframework.r2dbc.core.PreparedOperation, org.springframework.r2dbc.core.QueryOperation, java.util.function.Supplier

Expanded query that allows binding of parameters using parameter names that were used to expand the query. Binding unrolls Collections and nested arrays.

Field Summary

Modifier and TypeField and Description
private final String
private final NamedParameterUtils.NamedParameters
private final BindParameterSource

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
bind(BindTarget target, String identifier, Parameter parameter)

private void
bind(BindTarget target, Iterator<BindMarker> markers, Object valueToBind)

public void
bindNull(BindTarget target, String identifier, Parameter parameter)

public void
bindTo(BindTarget
the target to apply bindings to
target
)

Implements org.springframework.r2dbc.core.PreparedOperation.bindTo.

Apply bindings to the supplied BindTarget.

pack-priv List<BindMarker>
getBindMarkers(String identifier)

public String
getSource()

Implements org.springframework.r2dbc.core.PreparedOperation.getSource.

Get the underlying query source.

public String
toQuery()

Implements org.springframework.r2dbc.core.QueryOperation.toQuery.

Return the string-representation of this operation to be used with io.r2dbc.spi.Statement creation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

expandedSqlback to summary
private final String expandedSql
parametersback to summary
private final NamedParameterUtils.NamedParameters parameters
parameterSourceback to summary
private final BindParameterSource parameterSource

Constructor Detail

ExpandedQueryback to summary
pack-priv ExpandedQuery(String expandedSql, NamedParameterUtils.NamedParameters parameters, BindParameterSource parameterSource)

Method Detail

bindback to summary
public void bind(BindTarget target, String identifier, Parameter parameter)
Annotations
@SuppressWarnings:rawtypes, unchecked
bindback to summary
private void bind(BindTarget target, Iterator<BindMarker> markers, Object valueToBind)
bindNullback to summary
public void bindNull(BindTarget target, String identifier, Parameter parameter)
bindToback to summary
public void bindTo(BindTarget target)

Implements org.springframework.r2dbc.core.PreparedOperation.bindTo.

Doc from org.springframework.r2dbc.core.PreparedOperation.bindTo.

Apply bindings to the supplied BindTarget.

Parameters
target:BindTarget

the target to apply bindings to

Annotations
@Override
getBindMarkersback to summary
pack-priv List<BindMarker> getBindMarkers(String identifier)
Annotations
@Nullable
getSourceback to summary
public String getSource()

Implements org.springframework.r2dbc.core.PreparedOperation.getSource.

Doc from org.springframework.r2dbc.core.PreparedOperation.getSource.

Get the underlying query source.

Returns:String

the query source, such as a statement/criteria object

Annotations
@Override
toQueryback to summary
public String toQuery()

Implements org.springframework.r2dbc.core.QueryOperation.toQuery.

Doc from org.springframework.r2dbc.core.QueryOperation.toQuery.

Return the string-representation of this operation to be used with io.r2dbc.spi.Statement creation.

Returns:String

the operation as SQL string

Annotations
@Override
org.springframework.r2dbc.core back to summary

pack-priv Class NamedParameterUtils.NamedParameters

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.r2dbc.core.NamedParameterUtils.NamedParameters

Holder for bind markers progress.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private final BindMarkers
private final boolean
private final Map<String, List<NamedParameterUtils.NamedParameters.NamedParameter>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv List<NamedParameterUtils.NamedParameters.NamedParameter>
pack-priv NamedParameterUtils.NamedParameters.NamedParameter

Returns:

the named parameter
getOrCreate
(String
the parameter name
namedParameter
)

Get the NamedParameter identified by namedParameter.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bindMarkersback to summary
private final BindMarkers bindMarkers
identifiableback to summary
private final boolean identifiable
referencesback to summary
private final Map<String, List<NamedParameterUtils.NamedParameters.NamedParameter>> references

Constructor Detail

NamedParametersback to summary
pack-priv NamedParameters(BindMarkersFactory factory)

Method Detail

getMarkerback to summary
pack-priv List<NamedParameterUtils.NamedParameters.NamedParameter> getMarker(String name)
Annotations
@Nullable
getOrCreateback to summary
pack-priv NamedParameterUtils.NamedParameters.NamedParameter getOrCreate(String namedParameter)

Get the NamedParameter identified by namedParameter. Parameter objects get created if they do not yet exist.

Parameters
namedParameter:String

the parameter name

Returns:NamedParameterUtils.NamedParameters.NamedParameter

the named parameter

org.springframework.r2dbc.core back to summary

pack-priv Class NamedParameterUtils.NamedParameters.NamedParameter

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.r2dbc.core.NamedParameterUtils.NamedParameters.NamedParameter

Field Summary

Modifier and TypeField and Description
private final String
private final List<BindMarker>

Constructor Summary

AccessConstructor and Description
pack-priv
NamedParameter(String namedParameter)

Method Summary

Modifier and TypeMethod and Description
pack-priv String

Returns:

the placeholder to be used in the SQL statement
addPlaceholder
()

Create a placeholder to translate a single value into a bindable parameter.

pack-priv String
pack-priv String
getPlaceholder(int counter)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

namedParameterback to summary
private final String namedParameter
placeholdersback to summary
private final List<BindMarker> placeholders

Constructor Detail

NamedParameterback to summary
pack-priv NamedParameter(String namedParameter)

Method Detail

addPlaceholderback to summary
pack-priv String addPlaceholder()

Create a placeholder to translate a single value into a bindable parameter.

Can be called multiple times to create placeholders for array/collections.

Returns:String

the placeholder to be used in the SQL statement

getPlaceholderback to summary
pack-priv String getPlaceholder()
getPlaceholderback to summary
pack-priv String getPlaceholder(int counter)
org.springframework.r2dbc.core back to summary

private Class NamedParameterUtils.ParameterHolder

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.r2dbc.core.NamedParameterUtils.ParameterHolder

Field Summary

Modifier and TypeField and Description
private final int
private final String
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
ParameterHolder(String parameterName, int startIndex, int endIndex)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

pack-priv int
pack-priv String
pack-priv int
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

endIndexback to summary
private final int endIndex
parameterNameback to summary
private final String parameterName
startIndexback to summary
private final int startIndex

Constructor Detail

ParameterHolderback to summary
pack-priv ParameterHolder(String parameterName, int startIndex, int endIndex)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getEndIndexback to summary
pack-priv int getEndIndex()
getParameterNameback to summary
pack-priv String getParameterName()
getStartIndexback to summary
pack-priv int getStartIndex()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override