Skip to content

Commit 565faf5

Browse files
committed
#73 - hacking - removed old bind method from interface.
1 parent a158c6b commit 565faf5

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ public String toQuery() {
465465
* (non-Javadoc)
466466
* @see org.springframework.data.r2dbc.function.PreparedOperation#bind(io.r2dbc.spi.Statement)
467467
*/
468-
@Override
469-
public Statement bind(Statement to) {
468+
protected Statement bind(Statement to) {
470469

471470
binding.apply(to);
472471
return to;
@@ -480,12 +479,7 @@ public Statement bind(Connection connection) {
480479
// logger.debug("Executing SQL statement [" + sql + "]");
481480
// }
482481

483-
Statement statement = connection.createStatement(toQuery());
484-
485-
// TODO there is too much binding going on.
486-
// this looks silly and is by no means easy to understand (i.e. I don't)
487-
binding.apply(statement);
488-
return bind(statement);
482+
return bind(connection.createStatement(toQuery()));
489483
}
490484
}
491485
}

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

-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ public BindableOperation getSource() {
5555
return operation;
5656
}
5757

58-
@Override
59-
public Statement bind(Statement to) {
60-
throw new UnsupportedOperationException("we don't do that here");
61-
}
62-
6358
@Override
6459
public Statement bind(Connection connection) {
6560

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@ public interface PreparedOperation<T> extends QueryOperation {
4242
/**
4343
* Bind query parameters to a {@link Statement}.
4444
*
45-
* @param to the target statement to bind parameters to.
45+
* @param connection the {@link Connection} used for constructing a statement
4646
* @return the bound statement.
4747
*/
48-
@Deprecated
49-
Statement bind(Statement to);
50-
5148
Statement bind(Connection connection);
5249
}

src/test/java/org/springframework/data/r2dbc/function/StatementFactoryUnitTests.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.assertj.core.api.Assertions.*;
1919
import static org.mockito.Mockito.*;
2020

21+
import io.r2dbc.spi.Connection;
2122
import io.r2dbc.spi.Statement;
2223

2324
import java.util.Arrays;
@@ -46,6 +47,11 @@ public class StatementFactoryUnitTests {
4647
.createRenderContext());
4748

4849
Statement statementMock = mock(Statement.class);
50+
Connection connectionMock = mock(Connection.class);
51+
52+
{
53+
when(connectionMock.createStatement(anyString())).thenReturn(statementMock);
54+
}
4955

5056
@Test
5157
public void shouldToQuerySimpleSelectWithoutBindings() {
@@ -55,7 +61,8 @@ public void shouldToQuerySimpleSelectWithoutBindings() {
5561
assertThat(select.getSource()).isInstanceOf(Select.class);
5662
assertThat(select.toQuery()).isEqualTo("SELECT foo.bar, foo.baz FROM foo");
5763

58-
select.bind(statementMock);
64+
select.bind(connectionMock);
65+
5966
verifyZeroInteractions(statementMock);
6067
}
6168

@@ -69,7 +76,8 @@ public void shouldToQuerySimpleSelectWithSimpleFilter() {
6976
assertThat(select.getSource()).isInstanceOf(Select.class);
7077
assertThat(select.toQuery()).isEqualTo("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe = $1");
7178

72-
select.bind(statementMock);
79+
select.bind(connectionMock);
80+
7381
verify(statementMock).bind(0, "John");
7482
verifyNoMoreInteractions(statementMock);
7583
}
@@ -85,7 +93,8 @@ public void shouldToQuerySimpleSelectWithMultipleFilters() {
8593
assertThat(select.getSource()).isInstanceOf(Select.class);
8694
assertThat(select.toQuery()).isEqualTo("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe = $1 AND foo.baz = $2");
8795

88-
select.bind(statementMock);
96+
select.bind(connectionMock);
97+
8998
verify(statementMock).bind(0, "John");
9099
verify(statementMock).bind(1, "Jake");
91100
verifyNoMoreInteractions(statementMock);
@@ -101,7 +110,7 @@ public void shouldToQuerySimpleSelectWithNullFilter() {
101110
assertThat(select.getSource()).isInstanceOf(Select.class);
102111
assertThat(select.toQuery()).isEqualTo("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe IS NULL");
103112

104-
select.bind(statementMock);
113+
select.bind(connectionMock);
105114
verifyZeroInteractions(statementMock);
106115
}
107116

@@ -115,7 +124,7 @@ public void shouldToQuerySimpleSelectWithIterableFilter() {
115124
assertThat(select.getSource()).isInstanceOf(Select.class);
116125
assertThat(select.toQuery()).isEqualTo("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe IN ($1, $2)");
117126

118-
select.bind(statementMock);
127+
select.bind(connectionMock);
119128
verify(statementMock).bind(0, "John");
120129
verify(statementMock).bind(1, "Jake");
121130
verifyNoMoreInteractions(statementMock);
@@ -138,7 +147,7 @@ public void shouldToQuerySimpleInsert() {
138147
assertThat(insert.getSource()).isInstanceOf(Insert.class);
139148
assertThat(insert.toQuery()).isEqualTo("INSERT INTO foo (bar) VALUES ($1)");
140149

141-
insert.bind(statementMock);
150+
insert.bind(connectionMock);
142151
verify(statementMock).bind(0, "Foo");
143152
verify(statementMock).returnGeneratedValues(any(String[].class));
144153
verifyNoMoreInteractions(statementMock);
@@ -161,7 +170,7 @@ public void shouldToQuerySimpleUpdate() {
161170
assertThat(update.getSource()).isInstanceOf(Update.class);
162171
assertThat(update.toQuery()).isEqualTo("UPDATE foo SET bar = $1");
163172

164-
update.bind(statementMock);
173+
update.bind(connectionMock);
165174
verify(statementMock).bind(0, "Foo");
166175
verifyNoMoreInteractions(statementMock);
167176
}
@@ -176,7 +185,7 @@ public void shouldToQueryNullUpdate() {
176185
assertThat(update.getSource()).isInstanceOf(Update.class);
177186
assertThat(update.toQuery()).isEqualTo("UPDATE foo SET bar = $1");
178187

179-
update.bind(statementMock);
188+
update.bind(connectionMock);
180189
verify(statementMock).bindNull(0, String.class);
181190

182191
verifyNoMoreInteractions(statementMock);
@@ -193,7 +202,7 @@ public void shouldToQueryUpdateWithFilter() {
193202
assertThat(update.getSource()).isInstanceOf(Update.class);
194203
assertThat(update.toQuery()).isEqualTo("UPDATE foo SET bar = $1 WHERE foo.baz = $2");
195204

196-
update.bind(statementMock);
205+
update.bind(connectionMock);
197206
verify(statementMock).bind(0, "Foo");
198207
verify(statementMock).bind(1, "Baz");
199208
verifyNoMoreInteractions(statementMock);
@@ -209,7 +218,7 @@ public void shouldToQuerySimpleDeleteWithSimpleFilter() {
209218
assertThat(delete.getSource()).isInstanceOf(Delete.class);
210219
assertThat(delete.toQuery()).isEqualTo("DELETE FROM foo WHERE foo.doe = $1");
211220

212-
delete.bind(statementMock);
221+
delete.bind(connectionMock);
213222
verify(statementMock).bind(0, "John");
214223
verifyNoMoreInteractions(statementMock);
215224
}
@@ -225,7 +234,7 @@ public void shouldToQuerySimpleDeleteWithMultipleFilters() {
225234
assertThat(delete.getSource()).isInstanceOf(Delete.class);
226235
assertThat(delete.toQuery()).isEqualTo("DELETE FROM foo WHERE foo.doe = $1 AND foo.baz = $2");
227236

228-
delete.bind(statementMock);
237+
delete.bind(connectionMock);
229238
verify(statementMock).bind(0, "John");
230239
verify(statementMock).bind(1, "Jake");
231240
verifyNoMoreInteractions(statementMock);
@@ -241,7 +250,7 @@ public void shouldToQuerySimpleDeleteWithNullFilter() {
241250
assertThat(delete.getSource()).isInstanceOf(Delete.class);
242251
assertThat(delete.toQuery()).isEqualTo("DELETE FROM foo WHERE foo.doe IS NULL");
243252

244-
delete.bind(statementMock);
253+
delete.bind(connectionMock);
245254
verifyZeroInteractions(statementMock);
246255
}
247256
}

0 commit comments

Comments
 (0)