17
17
package io .r2dbc .mssql ;
18
18
19
19
import io .r2dbc .mssql .codec .Encoded ;
20
+ import io .r2dbc .mssql .codec .RpcDirection ;
20
21
import io .r2dbc .mssql .util .Assert ;
21
22
import reactor .util .annotation .Nullable ;
22
23
34
35
*/
35
36
class Binding {
36
37
37
- private final Map <String , Encoded > parameters = new LinkedHashMap <>();
38
+ private final Map <String , RpcParameter > parameters = new LinkedHashMap <>();
39
+
40
+ private boolean hasOutParameters = false ;
38
41
39
42
@ Nullable
40
43
private volatile String formalRepresentation ;
@@ -43,28 +46,41 @@ class Binding {
43
46
* Add a {@link Encoded encoded parameter} to the binding.
44
47
*
45
48
* @param name the name of the {@link Encoded encoded parameter}
49
+ * @param direction the direction of the encoded parameter
46
50
* @param parameter the {@link Encoded encoded parameter}
47
51
* @return this {@link Binding}
48
52
*/
49
- public Binding add (String name , Encoded parameter ) {
53
+ public Binding add (String name , RpcDirection direction , Encoded parameter ) {
50
54
51
55
Assert .requireNonNull (name , "Name must not be null" );
56
+ Assert .requireNonNull (direction , "RpcDirection must not be null" );
52
57
Assert .requireNonNull (parameter , "Parameter must not be null" );
53
58
54
59
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
+ }
57
64
return this ;
58
65
}
59
66
67
+ /**
68
+ * Returns parameter names of the return values.
69
+ *
70
+ * @return
71
+ */
72
+ boolean hasOutParameters () {
73
+ return this .hasOutParameters ;
74
+ }
75
+
60
76
/**
61
77
* Clear/release binding values.
62
78
*/
63
79
void clear () {
64
80
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 ();
68
84
}
69
85
});
70
86
@@ -84,15 +100,19 @@ public String getFormalParameters() {
84
100
}
85
101
86
102
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 ();
88
104
89
- for (Map .Entry <String , Encoded > entry : entries ) {
105
+ for (Map .Entry <String , RpcParameter > entry : entries ) {
90
106
91
107
if (builder .length () != 0 ) {
92
108
builder .append (',' );
93
109
}
94
110
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
+ }
96
116
}
97
117
98
118
formalRepresentation = builder .toString ();
@@ -109,14 +129,14 @@ public String getFormalParameters() {
109
129
*
110
130
* @param action The action to be performed for each bound parameter.
111
131
*/
112
- public void forEach (BiConsumer <String , Encoded > action ) {
132
+ public void forEach (BiConsumer <String , RpcParameter > action ) {
113
133
114
134
Assert .requireNonNull (action , "Action must not be null" );
115
135
116
136
this .parameters .forEach (action );
117
137
}
118
138
119
- public Map <String , Encoded > getParameters () {
139
+ Map <String , RpcParameter > getParameters () {
120
140
return this .parameters ;
121
141
}
122
142
@@ -164,4 +184,17 @@ public String toString() {
164
184
return sb .toString ();
165
185
}
166
186
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
+
167
200
}
0 commit comments