Skip to content

Commit 13690ea

Browse files
committed
#73 - hacking - added backup.
1 parent 7f9c42c commit 13690ea

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.r2dbc.function;
17+
18+
import io.r2dbc.spi.Connection;
19+
import io.r2dbc.spi.Statement;
20+
21+
import java.util.Map;
22+
import java.util.function.Function;
23+
24+
import org.springframework.data.r2dbc.domain.SettableValue;
25+
26+
/**
27+
* @author Jens Schauder
28+
*/
29+
public class OldParameterbindingPreparedOperation implements PreparedOperation<BindableOperation> {
30+
31+
private final BindableOperation operation;
32+
private final Map<String, SettableValue> byName;
33+
private final Map<Integer, SettableValue> byIndex;
34+
35+
private OldParameterbindingPreparedOperation(BindableOperation operation, Map<String, SettableValue> byName,
36+
Map<Integer, SettableValue> byIndex) {
37+
38+
this.operation = operation;
39+
this.byName = byName;
40+
this.byIndex = byIndex;
41+
}
42+
43+
OldParameterbindingPreparedOperation(String sql, NamedParameterExpander namedParameters,
44+
ReactiveDataAccessStrategy dataAccessStrategy, Map<String, SettableValue> byName,
45+
Map<Integer, SettableValue> byIndex) {
46+
47+
this( //
48+
namedParameters.expand(sql, dataAccessStrategy.getBindMarkersFactory(), new MapBindParameterSource(byName)), //
49+
byName, //
50+
byIndex //
51+
);
52+
}
53+
54+
@Override
55+
public BindableOperation getSource() {
56+
return operation;
57+
}
58+
59+
@Override
60+
public Statement createBoundStatement(Connection connection) {
61+
62+
Statement statement = connection.createStatement(operation.toQuery());
63+
64+
bindByName(statement, byName);
65+
bindByIndex(statement, byIndex);
66+
67+
return statement;
68+
}
69+
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+
@Override
81+
public String toQuery() {
82+
return operation.toQuery();
83+
}
84+
85+
// todo that is a weird assymmetry between bindByName and bindByIndex
86+
private void bindByName(Statement statement, Map<String, SettableValue> byName) {
87+
88+
byName.forEach((name, o) -> {
89+
90+
if (o.getValue() != null) {
91+
operation.bind(statement,name, o.getValue());
92+
} else {
93+
operation.bindNull(statement, name, o.getType());
94+
}
95+
});
96+
}
97+
98+
private static void bindByIndex(Statement statement, Map<Integer, SettableValue> byIndex) {
99+
100+
byIndex.forEach((i, o) -> {
101+
102+
if (o.getValue() != null) {
103+
statement.bind(i.intValue(), o.getValue());
104+
} else {
105+
statement.bindNull(i.intValue(), o.getType());
106+
}
107+
});
108+
}
109+
}

0 commit comments

Comments
 (0)