18
18
import io .r2dbc .spi .Connection ;
19
19
import io .r2dbc .spi .Statement ;
20
20
21
+ import java .util .ArrayList ;
22
+ import java .util .List ;
21
23
import java .util .Map ;
22
- import java .util .function .Function ;
23
24
24
25
import org .springframework .data .r2dbc .domain .SettableValue ;
25
26
26
27
/**
27
28
* @author Jens Schauder
28
29
*/
29
- public class ParameterbindingPreparedOperation implements PreparedOperation <BindableOperation > {
30
+ public class ExpandedPreparedOperation
31
+ extends DefaultStatementFactory .PreparedOperationSupport <BindableOperation > {
30
32
31
33
private final BindableOperation operation ;
32
34
private final Map <String , SettableValue > byName ;
33
35
private final Map <Integer , SettableValue > byIndex ;
34
36
35
- private ParameterbindingPreparedOperation (BindableOperation operation , Map <String , SettableValue > byName ,
36
- Map <Integer , SettableValue > byIndex ) {
37
+ private ExpandedPreparedOperation (BindableOperation operation , Map <String , SettableValue > byName ,
38
+ Map <Integer , SettableValue > byIndex ) {
39
+
40
+ super (createBindings (operation , byName , byIndex ));
37
41
38
42
this .operation = operation ;
39
43
this .byName = byName ;
40
44
this .byIndex = byIndex ;
41
45
}
42
46
43
- ParameterbindingPreparedOperation (String sql , NamedParameterExpander namedParameters ,
44
- ReactiveDataAccessStrategy dataAccessStrategy , Map <String , SettableValue > byName ,
47
+ private static Bindings createBindings (BindableOperation operation , Map <String , SettableValue > byName ,
45
48
Map <Integer , SettableValue > byIndex ) {
46
49
50
+ List <Bindings .SingleBinding > bindings = new ArrayList <>();
51
+
52
+ byName .forEach (
53
+ (identifier , settableValue ) -> bindings .add (new Bindings .NamedExpandedSingleBinding (identifier , settableValue , operation )));
54
+
55
+ byIndex .forEach ((identifier , settableValue ) -> bindings .add (new Bindings .IndexedSingleBinding (identifier , settableValue )));
56
+
57
+ return new Bindings (bindings );
58
+ }
59
+
60
+ ExpandedPreparedOperation (String sql , NamedParameterExpander namedParameters ,
61
+ ReactiveDataAccessStrategy dataAccessStrategy , Map <String , SettableValue > byName ,
62
+ Map <Integer , SettableValue > byIndex ) {
63
+
47
64
this ( //
48
65
namedParameters .expand (sql , dataAccessStrategy .getBindMarkersFactory (), new MapBindParameterSource (byName )), //
49
66
byName , //
50
67
byIndex //
51
68
);
52
69
}
53
70
71
+ @ Override
72
+ protected String createBaseSql () {
73
+ return toQuery ();
74
+ }
75
+
54
76
@ Override
55
77
public BindableOperation getSource () {
56
78
return operation ;
@@ -67,28 +89,18 @@ public Statement createBoundStatement(Connection connection) {
67
89
return statement ;
68
90
}
69
91
70
- @ Override
71
- public void addSqlFilter (Function <String , String > filter ) {
72
-
73
- }
74
-
75
- @ Override
76
- public void addBindingFilter (Function <Bindings , Bindings > filter ) {
77
-
78
- }
79
-
80
92
@ Override
81
93
public String toQuery () {
82
94
return operation .toQuery ();
83
95
}
84
96
85
97
// todo that is a weird assymmetry between bindByName and bindByIndex
86
- private void bindByName (Statement statement , Map <String , SettableValue > byName ) {
98
+ private void bindByName (Statement statement , Map <String , SettableValue > byName ) {
87
99
88
100
byName .forEach ((name , o ) -> {
89
101
90
102
if (o .getValue () != null ) {
91
- operation .bind (statement ,name , o .getValue ());
103
+ operation .bind (statement , name , o .getValue ());
92
104
} else {
93
105
operation .bindNull (statement , name , o .getType ());
94
106
}
0 commit comments