1818import io .r2dbc .spi .Connection ;
1919import io .r2dbc .spi .Statement ;
2020
21+ import java .util .ArrayList ;
22+ import java .util .List ;
2123import java .util .Map ;
22- import java .util .function .Function ;
2324
2425import org .springframework .data .r2dbc .domain .SettableValue ;
2526
2627/**
2728 * @author Jens Schauder
2829 */
29- public class ParameterbindingPreparedOperation implements PreparedOperation <BindableOperation > {
30+ public class ExpandedPreparedOperation
31+ extends DefaultStatementFactory .PreparedOperationSupport <BindableOperation > {
3032
3133 private final BindableOperation operation ;
3234 private final Map <String , SettableValue > byName ;
3335 private final Map <Integer , SettableValue > byIndex ;
3436
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 ));
3741
3842 this .operation = operation ;
3943 this .byName = byName ;
4044 this .byIndex = byIndex ;
4145 }
4246
43- ParameterbindingPreparedOperation (String sql , NamedParameterExpander namedParameters ,
44- ReactiveDataAccessStrategy dataAccessStrategy , Map <String , SettableValue > byName ,
47+ private static Bindings createBindings (BindableOperation operation , Map <String , SettableValue > byName ,
4548 Map <Integer , SettableValue > byIndex ) {
4649
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+
4764 this ( //
4865 namedParameters .expand (sql , dataAccessStrategy .getBindMarkersFactory (), new MapBindParameterSource (byName )), //
4966 byName , //
5067 byIndex //
5168 );
5269 }
5370
71+ @ Override
72+ protected String createBaseSql () {
73+ return toQuery ();
74+ }
75+
5476 @ Override
5577 public BindableOperation getSource () {
5678 return operation ;
@@ -67,28 +89,18 @@ public Statement createBoundStatement(Connection connection) {
6789 return statement ;
6890 }
6991
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-
8092 @ Override
8193 public String toQuery () {
8294 return operation .toQuery ();
8395 }
8496
8597 // 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 ) {
8799
88100 byName .forEach ((name , o ) -> {
89101
90102 if (o .getValue () != null ) {
91- operation .bind (statement ,name , o .getValue ());
103+ operation .bind (statement , name , o .getValue ());
92104 } else {
93105 operation .bindNull (statement , name , o .getType ());
94106 }
0 commit comments