18
18
import io .r2dbc .spi .Statement ;
19
19
import lombok .Value ;
20
20
21
- import org .springframework .data .r2dbc .domain .SettableValue ;
22
-
23
21
import java .util .List ;
24
22
23
+ import org .springframework .data .r2dbc .domain .SettableValue ;
24
+
25
25
/**
26
26
* @author Jens Schauder
27
27
*/
@@ -35,20 +35,105 @@ public Bindings(List<SingleBinding> bindings) {
35
35
36
36
37
37
@ Value
38
- static public abstract class SingleBinding <T > {
38
+ public static abstract class SingleBinding <T > {
39
39
40
40
T identifier ;
41
41
SettableValue value ;
42
42
43
43
public abstract void bindTo (Statement statement );
44
44
45
+ public abstract boolean isIndexed ();
46
+
47
+ public final boolean isNamed () {
48
+ return !isIndexed ();
49
+ }
50
+ }
51
+
52
+ public static class NamedSingleBinding <T > extends SingleBinding <T >{
53
+
54
+ public NamedSingleBinding (T identifier , SettableValue value ) {
55
+ super (identifier , value );
56
+ }
57
+
58
+ @ Override
59
+ public void bindTo (Statement statement ) {
60
+
61
+ if (getValue ().isEmpty ()) {
62
+ statement .bindNull (getIdentifier (), getValue ().getType ());
63
+ }
64
+
65
+ statement .bind (getIdentifier (), getValue ());
66
+ }
67
+
68
+ @ Override
45
69
public boolean isIndexed () {
46
- return ( identifier instanceof Number ) ;
70
+ return false ;
47
71
}
72
+ }
48
73
49
- public boolean isNamed () {
50
- return !isIndexed ();
74
+ public static class IndexedSingleBinding extends SingleBinding <Integer >{
75
+
76
+ public IndexedSingleBinding (Integer identifier , SettableValue value ) {
77
+ super (identifier , value );
78
+ }
79
+
80
+ @ Override
81
+ public void bindTo (Statement statement ) {
82
+
83
+ if (getValue ().isEmpty ()) {
84
+ statement .bindNull ((int )getIdentifier (), getValue ().getType ());
85
+ }
86
+
87
+ statement .bind ((int )getIdentifier (), getValue ());
88
+ }
89
+ @ Override
90
+ public boolean isIndexed () {
91
+ return true ;
92
+ }
93
+ }
94
+
95
+ public static class NamedExpandedSingleBinding <T > extends SingleBinding <T >{
96
+
97
+ public NamedExpandedSingleBinding (T identifier , SettableValue value ) {
98
+ super (identifier , value );
99
+ }
100
+
101
+ @ Override
102
+ public void bindTo (Statement statement ) {
103
+
104
+ if (getValue ().isEmpty ()) {
105
+ statement .bindNull (getIdentifier (), getValue ().getType ());
106
+ }
107
+
108
+ statement .bind (getIdentifier (), getValue ());
109
+ }
110
+
111
+ @ Override
112
+ public boolean isIndexed () {
113
+ return false ;
51
114
}
52
115
}
53
116
117
+ public static class IndexedExpandedSingleBinding extends SingleBinding <Integer >{
118
+
119
+ public IndexedExpandedSingleBinding (Integer identifier , SettableValue value ) {
120
+ super (identifier , value );
121
+ }
122
+
123
+ @ Override
124
+ public void bindTo (Statement statement ) {
125
+
126
+ if (getValue ().isEmpty ()) {
127
+ statement .bindNull ((int )getIdentifier (), getValue ().getType ());
128
+ }
129
+
130
+ statement .bind ((int )getIdentifier (), getValue ());
131
+ }
132
+ @ Override
133
+ public boolean isIndexed () {
134
+ return true ;
135
+ }
136
+ }
137
+
138
+
54
139
}
0 commit comments