Skip to content

Commit 88945d7

Browse files
committed
#73 - Introduce BindTarget.
We now apply bindings to a BindTarget that can be overridden without the need to implement all Statement methods. PreparedOperation no longer has a direct dependency on R2DBC Statement. Original pull request: #82.
1 parent 02e0cb5 commit 88945d7

25 files changed

+389
-653
lines changed

src/main/java/org/springframework/data/r2dbc/dialect/BindMarker.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.r2dbc.spi.Statement;
44

5+
import org.springframework.data.r2dbc.domain.BindTarget;
6+
57
/**
68
* A bind marker represents a single bindable parameter within a query. Bind markers are dialect-specific and provide a
79
* {@link #getPlaceholder() placeholder} that is used in the actual query.
@@ -23,19 +25,19 @@ public interface BindMarker {
2325
/**
2426
* Bind the given {@code value} to the {@link Statement} using the underlying binding strategy.
2527
*
26-
* @param statement the statement to bind the value to.
28+
* @param bindTarget the target to bind the value to.
2729
* @param value the actual value. Must not be {@literal null}. Use {@link #bindNull(Statement, Class)} for
2830
* {@literal null} values.
2931
* @see Statement#bind
3032
*/
31-
void bind(Statement statement, Object value);
33+
void bind(BindTarget bindTarget, Object value);
3234

3335
/**
3436
* Bind a {@literal null} value to the {@link Statement} using the underlying binding strategy.
3537
*
36-
* @param statement the statement to bind the value to.
38+
* @param bindTarget the target to bind the value to.
3739
* @param valueType value type, must not be {@literal null}.
3840
* @see Statement#bindNull
3941
*/
40-
void bindNull(Statement statement, Class<?> valueType);
42+
void bindNull(BindTarget bindTarget, Class<?> valueType);
4143
}

src/main/java/org/springframework/data/r2dbc/dialect/IndexedBindMarker.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616
package org.springframework.data.r2dbc.dialect;
1717

18-
import io.r2dbc.spi.Statement;
18+
import org.springframework.data.r2dbc.domain.BindTarget;
1919

2020
/**
2121
* A single indexed bind marker.
2222
*/
23-
public class IndexedBindMarker implements BindMarker {
23+
class IndexedBindMarker implements BindMarker {
2424

2525
private final String placeholder;
2626

@@ -42,20 +42,20 @@ public String getPlaceholder() {
4242

4343
/*
4444
* (non-Javadoc)
45-
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindValue(io.r2dbc.spi.Statement, java.lang.Object)
45+
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindValue(org.springframework.data.r2dbc.dialect.BindTarget, java.lang.Object)
4646
*/
4747
@Override
48-
public void bind(Statement statement, Object value) {
49-
statement.bind(this.index, value);
48+
public void bind(BindTarget target, Object value) {
49+
target.bind(this.index, value);
5050
}
5151

5252
/*
5353
* (non-Javadoc)
54-
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindNull(io.r2dbc.spi.Statement, java.lang.Class)
54+
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindNull(org.springframework.data.r2dbc.dialect.BindTarget, java.lang.Class)
5555
*/
5656
@Override
57-
public void bindNull(Statement statement, Class<?> valueType) {
58-
statement.bindNull(this.index, valueType);
57+
public void bindNull(BindTarget target, Class<?> valueType) {
58+
target.bindNull(this.index, valueType);
5959
}
6060

6161

src/main/java/org/springframework/data/r2dbc/dialect/NamedBindMarkers.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.springframework.data.r2dbc.dialect;
22

3-
import io.r2dbc.spi.Statement;
4-
53
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
64
import java.util.function.Function;
75

6+
import org.springframework.data.r2dbc.domain.BindTarget;
87
import org.springframework.util.Assert;
98

109
/**
@@ -98,20 +97,20 @@ public String getPlaceholder() {
9897

9998
/*
10099
* (non-Javadoc)
101-
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindValue(io.r2dbc.spi.Statement, java.lang.Object)
100+
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindValue(org.springframework.data.r2dbc.dialect.BindTarget, java.lang.Object)
102101
*/
103102
@Override
104-
public void bind(Statement statement, Object value) {
105-
statement.bind(this.identifier, value);
103+
public void bind(BindTarget target, Object value) {
104+
target.bind(this.identifier, value);
106105
}
107106

108107
/*
109108
* (non-Javadoc)
110-
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindNull(io.r2dbc.spi.Statement, java.lang.Class)
109+
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindNull(org.springframework.data.r2dbc.dialect.BindTarget, java.lang.Class)
111110
*/
112111
@Override
113-
public void bindNull(Statement statement, Class<?> valueType) {
114-
statement.bindNull(this.identifier, valueType);
112+
public void bindNull(BindTarget target, Class<?> valueType) {
113+
target.bindNull(this.identifier, valueType);
115114
}
116115
}
117116
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.domain;
17+
18+
/**
19+
* Target to apply bindings to.
20+
*
21+
* @author Mark Paluch
22+
* @see PreparedOperation
23+
* @see io.r2dbc.spi.Statement#bind
24+
* @see io.r2dbc.spi.Statement#bindNull
25+
*/
26+
public interface BindTarget {
27+
28+
/**
29+
* Bind a value.
30+
*
31+
* @param identifier the identifier to bind to.
32+
* @param value the value to bind.
33+
*/
34+
void bind(Object identifier, Object value);
35+
36+
/**
37+
* Bind a value to an index. Indexes are zero-based.
38+
*
39+
* @param index the index to bind to.
40+
* @param value the value to bind.
41+
*/
42+
void bind(int index, Object value);
43+
44+
/**
45+
* Bind a {@code null} value.
46+
*
47+
* @param identifier the identifier to bind to.
48+
* @param type the type of {@literal null} value.
49+
*/
50+
void bindNull(Object identifier, Class<?> type);
51+
52+
/**
53+
* Bind a {@code null} value.
54+
*
55+
* @param index the index to bind to.
56+
* @param type the type of {@literal null} value.
57+
*/
58+
void bindNull(int index, Class<?> type);
59+
}

src/main/java/org/springframework/data/r2dbc/domain/OutboundRow.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class OutboundRow implements Map<String, SettableValue> {
3939
* Creates an empty {@link OutboundRow} instance.
4040
*/
4141
public OutboundRow() {
42-
rowAsMap = new LinkedHashMap<>();
42+
this.rowAsMap = new LinkedHashMap<>();
4343
}
4444

4545
/**
@@ -51,7 +51,7 @@ public OutboundRow(Map<String, SettableValue> map) {
5151

5252
Assert.notNull(map, "Map must not be null");
5353

54-
rowAsMap = new LinkedHashMap<>(map);
54+
this.rowAsMap = new LinkedHashMap<>(map);
5555
}
5656

5757
/**
@@ -61,8 +61,8 @@ public OutboundRow(Map<String, SettableValue> map) {
6161
* @param value value.
6262
*/
6363
public OutboundRow(String key, SettableValue value) {
64-
rowAsMap = new LinkedHashMap<>();
65-
rowAsMap.put(key, value);
64+
this.rowAsMap = new LinkedHashMap<>();
65+
this.rowAsMap.put(key, value);
6666
}
6767

6868
/**
@@ -78,7 +78,7 @@ public OutboundRow(String key, SettableValue value) {
7878
* @return this
7979
*/
8080
public OutboundRow append(String key, SettableValue value) {
81-
rowAsMap.put(key, value);
81+
this.rowAsMap.put(key, value);
8282
return this;
8383
}
8484

@@ -88,7 +88,7 @@ public OutboundRow append(String key, SettableValue value) {
8888
*/
8989
@Override
9090
public int size() {
91-
return rowAsMap.size();
91+
return this.rowAsMap.size();
9292
}
9393

9494
/*
@@ -97,7 +97,7 @@ public int size() {
9797
*/
9898
@Override
9999
public boolean isEmpty() {
100-
return rowAsMap.isEmpty();
100+
return this.rowAsMap.isEmpty();
101101
}
102102

103103
/*
@@ -106,7 +106,7 @@ public boolean isEmpty() {
106106
*/
107107
@Override
108108
public boolean containsKey(Object key) {
109-
return rowAsMap.containsKey(key);
109+
return this.rowAsMap.containsKey(key);
110110
}
111111

112112
/*
@@ -115,7 +115,7 @@ public boolean containsKey(Object key) {
115115
*/
116116
@Override
117117
public boolean containsValue(Object value) {
118-
return rowAsMap.containsValue(value);
118+
return this.rowAsMap.containsValue(value);
119119
}
120120

121121
/*
@@ -124,7 +124,7 @@ public boolean containsValue(Object value) {
124124
*/
125125
@Override
126126
public SettableValue get(Object key) {
127-
return rowAsMap.get(key);
127+
return this.rowAsMap.get(key);
128128
}
129129

130130
/*
@@ -133,7 +133,7 @@ public SettableValue get(Object key) {
133133
*/
134134
@Override
135135
public SettableValue put(String key, SettableValue value) {
136-
return rowAsMap.put(key, value);
136+
return this.rowAsMap.put(key, value);
137137
}
138138

139139
/*
@@ -142,7 +142,7 @@ public SettableValue put(String key, SettableValue value) {
142142
*/
143143
@Override
144144
public SettableValue remove(Object key) {
145-
return rowAsMap.remove(key);
145+
return this.rowAsMap.remove(key);
146146
}
147147

148148
/*
@@ -151,7 +151,7 @@ public SettableValue remove(Object key) {
151151
*/
152152
@Override
153153
public void putAll(Map<? extends String, ? extends SettableValue> m) {
154-
rowAsMap.putAll(m);
154+
this.rowAsMap.putAll(m);
155155
}
156156

157157
/*
@@ -160,7 +160,7 @@ public void putAll(Map<? extends String, ? extends SettableValue> m) {
160160
*/
161161
@Override
162162
public void clear() {
163-
rowAsMap.clear();
163+
this.rowAsMap.clear();
164164
}
165165

166166
/*
@@ -169,7 +169,7 @@ public void clear() {
169169
*/
170170
@Override
171171
public Set<String> keySet() {
172-
return rowAsMap.keySet();
172+
return this.rowAsMap.keySet();
173173
}
174174

175175
/*
@@ -178,7 +178,7 @@ public Set<String> keySet() {
178178
*/
179179
@Override
180180
public Collection<SettableValue> values() {
181-
return rowAsMap.values();
181+
return this.rowAsMap.values();
182182
}
183183

184184
/*
@@ -187,7 +187,7 @@ public Collection<SettableValue> values() {
187187
*/
188188
@Override
189189
public Set<Entry<String, SettableValue>> entrySet() {
190-
return rowAsMap.entrySet();
190+
return this.rowAsMap.entrySet();
191191
}
192192

193193
/*
@@ -207,7 +207,7 @@ public boolean equals(final Object o) {
207207

208208
OutboundRow row = (OutboundRow) o;
209209

210-
return rowAsMap.equals(row.rowAsMap);
210+
return this.rowAsMap.equals(row.rowAsMap);
211211
}
212212

213213
/*
@@ -216,7 +216,7 @@ public boolean equals(final Object o) {
216216
*/
217217
@Override
218218
public int hashCode() {
219-
return rowAsMap.hashCode();
219+
return this.rowAsMap.hashCode();
220220
}
221221

222222
/*
@@ -225,11 +225,11 @@ public int hashCode() {
225225
*/
226226
@Override
227227
public String toString() {
228-
return "OutboundRow[" + rowAsMap + "]";
228+
return "OutboundRow[" + this.rowAsMap + "]";
229229
}
230230

231231
@Override
232232
public void forEach(BiConsumer<? super String, ? super SettableValue> action) {
233-
rowAsMap.forEach(action);
233+
this.rowAsMap.forEach(action);
234234
}
235235
}

0 commit comments

Comments
 (0)