|
18 | 18 |
|
19 | 19 | import io.netty.util.collection.IntObjectHashMap; |
20 | 20 | import io.netty.util.collection.IntObjectMap; |
| 21 | +import io.vertx.core.VertxException; |
| 22 | +import io.vertx.core.buffer.Buffer; |
21 | 23 | import io.vertx.core.internal.logging.Logger; |
22 | 24 | import io.vertx.core.internal.logging.LoggerFactory; |
23 | 25 | import io.vertx.core.json.JsonArray; |
24 | 26 | import io.vertx.core.json.JsonObject; |
25 | | -import io.vertx.pgclient.data.Box; |
26 | | -import io.vertx.pgclient.data.Circle; |
27 | | -import io.vertx.pgclient.data.Inet; |
28 | | -import io.vertx.pgclient.data.Line; |
29 | | -import io.vertx.pgclient.data.LineSegment; |
30 | | -import io.vertx.pgclient.data.Money; |
31 | | -import io.vertx.pgclient.data.Cidr; |
| 27 | +import io.vertx.pgclient.data.*; |
32 | 28 | import io.vertx.sqlclient.Tuple; |
33 | 29 | import io.vertx.sqlclient.data.Numeric; |
34 | | -import io.vertx.pgclient.data.Interval; |
35 | | -import io.vertx.pgclient.data.Path; |
36 | | -import io.vertx.pgclient.data.Point; |
37 | | -import io.vertx.pgclient.data.Polygon; |
38 | | -import io.vertx.core.buffer.Buffer; |
| 30 | +import io.vertx.sqlclient.internal.TupleInternal; |
39 | 31 |
|
40 | 32 | import java.sql.JDBCType; |
41 | 33 | import java.time.*; |
42 | 34 | import java.util.HashMap; |
43 | 35 | import java.util.Map; |
| 36 | +import java.util.Objects; |
44 | 37 | import java.util.UUID; |
45 | 38 |
|
46 | 39 | /** |
@@ -155,11 +148,11 @@ <T> DataType(int id, boolean supportsBinary, Class<T> type, JDBCType jdbcType) { |
155 | 148 | <T> DataType(int id, boolean supportsBinary, Class<T> encodingType, Class<?> decodingType, JDBCType jdbcType, ParamExtractor<T> paramExtractor) { |
156 | 149 | this.id = id; |
157 | 150 | this.supportsBinary = supportsBinary; |
158 | | - this.encodingType = encodingType; |
| 151 | + this.encodingType = Objects.requireNonNull(encodingType); |
159 | 152 | this.decodingType = decodingType; |
160 | 153 | this.jdbcType = jdbcType; |
161 | 154 | this.array = decodingType.isArray(); |
162 | | - this.paramExtractor = paramExtractor; |
| 155 | + this.paramExtractor = paramExtractor != null ? paramExtractor : new DefaultParamExtractor<>(encodingType); |
163 | 156 | } |
164 | 157 |
|
165 | 158 | static DataType valueOf(int oid) { |
@@ -231,4 +224,23 @@ static DataType lookup(Class<?> type) { |
231 | 224 | encodingTypeToDataType.put(Circle.class, CIRCLE); |
232 | 225 | encodingTypeToDataType.put(Circle[].class, CIRCLE_ARRAY); |
233 | 226 | } |
| 227 | + |
| 228 | + private static class DefaultParamExtractor<T> implements ParamExtractor<T> { |
| 229 | + static final RuntimeException FAILURE = new VertxException("ignored", true); |
| 230 | + |
| 231 | + final Class<T> encodingType; |
| 232 | + |
| 233 | + DefaultParamExtractor(Class<T> encodingType) { |
| 234 | + this.encodingType = encodingType; |
| 235 | + } |
| 236 | + |
| 237 | + @Override |
| 238 | + public T get(TupleInternal tuple, int idx) { |
| 239 | + Object value = tuple.getValue(idx); |
| 240 | + if (value != null && encodingType.isAssignableFrom(value.getClass())) { |
| 241 | + return encodingType.cast(value); |
| 242 | + } |
| 243 | + throw FAILURE; |
| 244 | + } |
| 245 | + } |
234 | 246 | } |
0 commit comments