Skip to content

Commit 823d7b6

Browse files
committed
Add support for return value consumption through Result.map(…).
Signed-off-by: Mark Paluch <mpaluch@vmware.com> [#199]
1 parent 53a179c commit 823d7b6

19 files changed

+1344
-389
lines changed

src/main/java/io/r2dbc/mssql/Binding.java

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.r2dbc.mssql;
1818

1919
import io.r2dbc.mssql.codec.Encoded;
20+
import io.r2dbc.mssql.codec.RpcDirection;
2021
import io.r2dbc.mssql.util.Assert;
2122
import reactor.util.annotation.Nullable;
2223

@@ -34,7 +35,9 @@
3435
*/
3536
class Binding {
3637

37-
private final Map<String, Encoded> parameters = new LinkedHashMap<>();
38+
private final Map<String, RpcParameter> parameters = new LinkedHashMap<>();
39+
40+
private boolean hasOutParameters = false;
3841

3942
@Nullable
4043
private volatile String formalRepresentation;
@@ -43,28 +46,41 @@ class Binding {
4346
* Add a {@link Encoded encoded parameter} to the binding.
4447
*
4548
* @param name the name of the {@link Encoded encoded parameter}
49+
* @param direction the direction of the encoded parameter
4650
* @param parameter the {@link Encoded encoded parameter}
4751
* @return this {@link Binding}
4852
*/
49-
public Binding add(String name, Encoded parameter) {
53+
public Binding add(String name, RpcDirection direction, Encoded parameter) {
5054

5155
Assert.requireNonNull(name, "Name must not be null");
56+
Assert.requireNonNull(direction, "RpcDirection must not be null");
5257
Assert.requireNonNull(parameter, "Parameter must not be null");
5358

5459
this.formalRepresentation = null;
55-
this.parameters.put(name, parameter);
56-
60+
this.parameters.put(name, new RpcParameter(direction, parameter));
61+
if (direction == RpcDirection.OUT) {
62+
this.hasOutParameters = true;
63+
}
5764
return this;
5865
}
5966

67+
/**
68+
* Returns parameter names of the return values.
69+
*
70+
* @return
71+
*/
72+
boolean hasOutParameters() {
73+
return this.hasOutParameters;
74+
}
75+
6076
/**
6177
* Clear/release binding values.
6278
*/
6379
void clear() {
6480

65-
this.parameters.forEach((s, encoded) -> {
66-
while (encoded.refCnt() > 0) {
67-
encoded.release();
81+
this.parameters.forEach((s, parameter) -> {
82+
while (parameter.encoded.refCnt() > 0) {
83+
parameter.encoded.release();
6884
}
6985
});
7086

@@ -84,15 +100,19 @@ public String getFormalParameters() {
84100
}
85101

86102
StringBuilder builder = new StringBuilder(this.parameters.size() * 16);
87-
Set<Map.Entry<String, Encoded>> entries = this.parameters.entrySet();
103+
Set<Map.Entry<String, RpcParameter>> entries = this.parameters.entrySet();
88104

89-
for (Map.Entry<String, Encoded> entry : entries) {
105+
for (Map.Entry<String, RpcParameter> entry : entries) {
90106

91107
if (builder.length() != 0) {
92108
builder.append(',');
93109
}
94110

95-
builder.append('@').append(entry.getKey()).append(' ').append(entry.getValue().getFormalType());
111+
builder.append('@').append(entry.getKey()).append(' ').append(entry.getValue().encoded.getFormalType());
112+
113+
if (entry.getValue().rpcDirection == RpcDirection.OUT) {
114+
builder.append(" OUTPUT");
115+
}
96116
}
97117

98118
formalRepresentation = builder.toString();
@@ -109,14 +129,14 @@ public String getFormalParameters() {
109129
*
110130
* @param action The action to be performed for each bound parameter.
111131
*/
112-
public void forEach(BiConsumer<String, Encoded> action) {
132+
public void forEach(BiConsumer<String, RpcParameter> action) {
113133

114134
Assert.requireNonNull(action, "Action must not be null");
115135

116136
this.parameters.forEach(action);
117137
}
118138

119-
public Map<String, Encoded> getParameters() {
139+
Map<String, RpcParameter> getParameters() {
120140
return this.parameters;
121141
}
122142

@@ -164,4 +184,17 @@ public String toString() {
164184
return sb.toString();
165185
}
166186

187+
public static class RpcParameter {
188+
189+
final RpcDirection rpcDirection;
190+
191+
final Encoded encoded;
192+
193+
public RpcParameter(RpcDirection rpcDirection, Encoded encoded) {
194+
this.rpcDirection = rpcDirection;
195+
this.encoded = encoded;
196+
}
197+
198+
}
199+
167200
}

0 commit comments

Comments
 (0)