11package org .springframework .data .r2dbc .dialect ;
22
3+ import java .util .function .Function ;
4+ 35import org .springframework .util .Assert ;
46
57/**
68 * This class creates new {@link BindMarkers} instances to bind parameter for a specific {@link io.r2dbc.spi.Statement}.
9+ * <p/>
10+ * Bind markers can be typically represented as placeholder and identifier. Placeholders are used within the query to
11+ * execute so the underlying database system can substitute the placeholder with the actual value. Identifiers are used
12+ * in R2DBC drivers to bind a value to a bind marker. Identifiers are typically a part of an entire bind marker when
13+ * using indexed or named bind markers.
714 *
815 * @author Mark Paluch
916 * @see BindMarkers
@@ -20,11 +27,15 @@ public interface BindMarkersFactory {
2027 BindMarkers create ();
2128
2229 /**
23- * Create index-based {@link BindMarkers}.
30+ * Create index-based {@link BindMarkers} using indexes to bind parameters. Allow customization of the bind marker
31+ * placeholder {@code prefix} to represent the bind marker as placeholder within the query.
2432 *
25- * @param prefix bind parameter prefix.
33+ * @param prefix bind parameter prefix that is included in {@link BindMarker#getPlaceholder()} but not the actual
34+ * identifier.
2635 * @param beginWith the first index to use.
2736 * @return a {@link BindMarkersFactory} using {@code prefix} and {@code beginWith}.
37+ * @see io.r2dbc.spi.Statement#bindNull(int, Class)
38+ * @see io.r2dbc.spi.Statement#bind(int, Object)
2839 */
2940 static BindMarkersFactory indexed (String prefix , int beginWith ) {
3041
@@ -33,21 +44,49 @@ static BindMarkersFactory indexed(String prefix, int beginWith) {
3344 }
3445
3546 /**
36- * Create named {@link BindMarkers}. Named bind markers can support {@link BindMarkers#next(String) name hints}.
37- * Typically, named markers use name hints. If no namehint is given, named bind markers use a counter to generate
38- * unique bind markers.
47+ * Create named {@link BindMarkers} using identifiers to bind parameters. Named bind markers can support
48+ * {@link BindMarkers#next(String) name hints}. If no {@link BindMarkers#next(String) hint} is given, named bind
49+ * markers can use a counter or a random value source to generate unique bind markers.
50+ * <p/>
51+ * Allow customization of the bind marker placeholder {@code prefix} and {@code namePrefix} to represent the bind
52+ * marker as placeholder within the query.
53+ *
54+ * @param prefix bind parameter prefix that is included in {@link BindMarker#getPlaceholder()} but not the actual
55+ * identifier.
56+ * @param namePrefix prefix for bind marker name that is included in {@link BindMarker#getPlaceholder()} and the
57+ * actual identifier.
58+ * @param maxLength maximal length of parameter names when using name hints.
59+ * @return a {@link BindMarkersFactory} using {@code prefix} and {@code beginWith}.
60+ * @see io.r2dbc.spi.Statement#bindNull(Object, Class)
61+ * @see io.r2dbc.spi.Statement#bind(Object, Object)
62+ */
63+ static BindMarkersFactory named (String prefix , String namePrefix , int maxLength ) {
64+ return named (prefix , namePrefix , maxLength , Function .identity ());
65+ }
66+ 67+ /**
68+ * Create named {@link BindMarkers} using identifiers to bind parameters. Named bind markers can support
69+ * {@link BindMarkers#next(String) name hints}. If no {@link BindMarkers#next(String) hint} is given, named bind
70+ * markers can use a counter or a random value source to generate unique bind markers.
3971 *
40- * @param prefix bind parameter prefix.
41- * @param indexPrefix prefix for bind markers that were created by incrementing a counter to generate a unique bind
42- * marker.
43- * @param nameLimit maximal length of parameter names when using name hints.
72+ * @param prefix bind parameter prefix that is included in {@link BindMarker#getPlaceholder()} but not the actual
73+ * identifier.
74+ * @param namePrefix prefix for bind marker name that is included in {@link BindMarker#getPlaceholder()} and the
75+ * actual identifier.
76+ * @param maxLength maximal length of parameter names when using name hints.
77+ * @param hintFilterFunction filter {@link Function} to consider database-specific limitations in bind marker/variable
78+ * names such as ASCII chars only.
4479 * @return a {@link BindMarkersFactory} using {@code prefix} and {@code beginWith}.
80+ * @see io.r2dbc.spi.Statement#bindNull(Object, Class)
81+ * @see io.r2dbc.spi.Statement#bind(Object, Object)
4582 */
46- static BindMarkersFactory named (String prefix , String indexPrefix , int nameLimit ) {
83+ static BindMarkersFactory named (String prefix , String namePrefix , int maxLength ,
84+ Function <String , String > hintFilterFunction ) {
4785
4886 Assert .notNull (prefix , "Prefix must not be null!" );
49- Assert .notNull (indexPrefix , "Index prefix must not be null!" );
87+ Assert .notNull (namePrefix , "Index prefix must not be null!" );
88+ Assert .notNull (hintFilterFunction , "Hint filter function must not be null!" );
5089
51- return () -> new NamedBindMarkers (prefix , indexPrefix , nameLimit );
90+ return () -> new NamedBindMarkers (prefix , namePrefix , maxLength , hintFilterFunction );
5291 }
5392}
0 commit comments