Skip to content

Commit a5de49a

Browse files
committed
#57 - hacking - minor code improvements.
1 parent 5f6ced5 commit a5de49a

File tree

2 files changed

+21
-45
lines changed

2 files changed

+21
-45
lines changed

src/main/java/org/springframework/data/r2dbc/function/DefaultDatabaseClient.java

+1-37
Original file line numberDiff line numberDiff line change
@@ -337,45 +337,9 @@ <T> FetchSpec<T> exchange(String sql, BiFunction<Row, RowMetadata, T> mappingFun
337337
if (sqlSupplier instanceof PreparedOperation<?>) {
338338
pop = ((PreparedOperation<?>) sqlSupplier);
339339
} else {
340-
pop = new PrameterbindingPreparedOperation(namedParameters.expand(sql, dataAccessStrategy.getBindMarkersFactory(),
341-
new MapBindParameterSource(byName)), byName, byIndex);
340+
pop = new ParameterbindingPreparedOperation(sql, namedParameters, dataAccessStrategy, byName, byIndex);
342341
}
343342

344-
345-
346-
Function<Connection, Statement> executeFunction = it -> {
347-
348-
if (logger.isDebugEnabled()) {
349-
logger.debug("Executing SQL statement [" + sql + "]");
350-
}
351-
352-
if (sqlSupplier instanceof PreparedOperation<?>) {
353-
return ((PreparedOperation<?>) sqlSupplier).bind(it.createStatement(sql));
354-
}
355-
356-
BindableOperation operation = namedParameters.expand(sql, dataAccessStrategy.getBindMarkersFactory(),
357-
new MapBindParameterSource(byName));
358-
359-
if (logger.isTraceEnabled()) {
360-
logger.trace("Expanded SQL [" + operation.toQuery() + "]");
361-
}
362-
363-
Statement statement = it.createStatement(operation.toQuery());
364-
365-
byName.forEach((name, o) -> {
366-
367-
if (o.getValue() != null) {
368-
operation.bind(statement, name, o.getValue());
369-
} else {
370-
operation.bindNull(statement, name, o.getType());
371-
}
372-
});
373-
374-
bindByIndex(statement, byIndex);
375-
376-
return statement;
377-
};
378-
379343
Function<Connection, Flux<Result>> resultFunction = it -> Flux.from(pop.bind(it).execute());
380344

381345
return new DefaultSqlResult<>(DefaultDatabaseClient.this, //

src/main/java/org/springframework/data/r2dbc/function/PrameterbindingPreparedOperation.java renamed to src/main/java/org/springframework/data/r2dbc/function/ParameterbindingPreparedOperation.java

+20-8
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,47 @@
1717

1818
import io.r2dbc.spi.Connection;
1919
import io.r2dbc.spi.Statement;
20-
import org.springframework.data.r2dbc.domain.SettableValue;
2120

2221
import java.util.Map;
2322

23+
import org.springframework.data.r2dbc.domain.SettableValue;
24+
2425
/**
2526
* @author Jens Schauder
2627
*/
27-
public class PrameterbindingPreparedOperation implements PreparedOperation<BindableOperation> {
28+
public class ParameterbindingPreparedOperation implements PreparedOperation<BindableOperation> {
2829

2930
private final BindableOperation operation;
3031
private final Map<String, SettableValue> byName;
3132
private final Map<Integer, SettableValue> byIndex;
3233

33-
public PrameterbindingPreparedOperation(BindableOperation operation, Map<String, SettableValue> byName, Map<Integer, SettableValue> byIndex) {
34+
private ParameterbindingPreparedOperation(BindableOperation operation, Map<String, SettableValue> byName,
35+
Map<Integer, SettableValue> byIndex) {
3436

3537
this.operation = operation;
3638
this.byName = byName;
3739
this.byIndex = byIndex;
3840
}
3941

42+
ParameterbindingPreparedOperation(String sql, NamedParameterExpander namedParameters,
43+
ReactiveDataAccessStrategy dataAccessStrategy, Map<String, SettableValue> byName,
44+
Map<Integer, SettableValue> byIndex) {
45+
46+
this( //
47+
namedParameters.expand(sql, dataAccessStrategy.getBindMarkersFactory(), new MapBindParameterSource(byName)), //
48+
byName, //
49+
byIndex //
50+
);
51+
}
52+
4053
@Override
4154
public BindableOperation getSource() {
4255
return operation;
4356
}
4457

4558
@Override
4659
public Statement bind(Statement to) {
47-
return null;
60+
throw new UnsupportedOperationException("we don't do that here");
4861
}
4962

5063
@Override
@@ -63,15 +76,14 @@ public Statement bind(Connection connection) {
6376

6477
bindByIndex(statement, byIndex);
6578

66-
return statement; }
79+
return statement;
80+
}
6781

6882
@Override
6983
public String toQuery() {
70-
return null;
84+
return operation.toQuery();
7185
}
7286

73-
74-
7587
private static void bindByName(Statement statement, Map<String, SettableValue> byName) {
7688

7789
byName.forEach((name, o) -> {

0 commit comments

Comments
 (0)