Skip to content

Commit dcdd968

Browse files
committed
#73 - hacking - prepared various single bindings.
1 parent 2804726 commit dcdd968

File tree

1 file changed

+91
-6
lines changed
  • src/main/java/org/springframework/data/r2dbc/function

1 file changed

+91
-6
lines changed

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

+91-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import io.r2dbc.spi.Statement;
1919
import lombok.Value;
2020

21-
import org.springframework.data.r2dbc.domain.SettableValue;
22-
2321
import java.util.List;
2422

23+
import org.springframework.data.r2dbc.domain.SettableValue;
24+
2525
/**
2626
* @author Jens Schauder
2727
*/
@@ -35,20 +35,105 @@ public Bindings(List<SingleBinding> bindings) {
3535

3636

3737
@Value
38-
static public abstract class SingleBinding<T> {
38+
public static abstract class SingleBinding<T> {
3939

4040
T identifier;
4141
SettableValue value;
4242

4343
public abstract void bindTo(Statement statement);
4444

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
4569
public boolean isIndexed() {
46-
return (identifier instanceof Number);
70+
return false;
4771
}
72+
}
4873

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;
51114
}
52115
}
53116

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+
54139
}

0 commit comments

Comments
 (0)