kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 51386aeba86021b590812970e07e63a7dadf6c3d96ef36252b951f7de80302c4 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-11-19 17:29 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-12-03 18:22 +01:00 |
| Parents | 9e8f5a07be4b |
10 files changed
modified changelog/README.md +1 −0
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | control connection. |
| 10 | 10 | - [improvement] JAVA-1003: Change default consistency level to LOCAL_ONE (amends JAVA-926). |
| 11 | 11 | - [improvement] JAVA-863: Idempotence propagation in prepared statements. |
| 12 | +- [improvement] JAVA-996: Make CodecRegistry available to ProtocolDecoder. | |
| 12 | 13 | |
| 13 | 14 | Merged from 2.1 branch: |
| 14 | 15 |
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedResultSet.java +0 −6
| @@ -77,12 +77,6 @@ | ||
| 77 | 77 | // this explicitly because MultiPage implementation don't support info == null. |
| 78 | 78 | assert r.metadata.pagingState == null || info != null; |
| 79 | 79 | |
| 80 | - // if this is an internal call, it doesn't matter which codecRegistry will be used | |
| 81 | - CodecRegistry codecRegistry = session == null ? | |
| 82 | - CodecRegistry.DEFAULT_INSTANCE : | |
| 83 | - session.getCluster().getConfiguration().getCodecRegistry(); | |
| 84 | - columnDefs.setCodecRegistry(codecRegistry); | |
| 85 | - | |
| 86 | 80 | return r.metadata.pagingState == null |
| 87 | 81 | ? new SinglePage(columnDefs, tokenFactory, protocolVersion, r.data, info) |
| 88 | 82 | : new MultiPage(columnDefs, tokenFactory, protocolVersion, r.data, info, r.metadata.pagingState, session, statement); |
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedRow.java +3 −4
| @@ -16,11 +16,9 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import java.nio.ByteBuffer; |
| 19 | -import java.util.*; | |
| 19 | +import java.util.List; | |
| 20 | 20 | import java.util.regex.Pattern; |
| 21 | 21 | |
| 22 | -import com.google.common.base.Joiner; | |
| 23 | - | |
| 24 | 22 | import com.datastax.driver.core.exceptions.DriverInternalError; |
| 25 | 23 | |
| 26 | 24 | /** |
| @@ -75,7 +73,7 @@ | ||
| 75 | 73 | |
| 76 | 74 | @Override |
| 77 | 75 | protected CodecRegistry getCodecRegistry() { |
| 78 | - return metadata.getCodecRegistry(); | |
| 76 | + return metadata.codecRegistry; | |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 79 | @Override |
| @@ -102,6 +100,7 @@ | ||
| 102 | 100 | return getToken(metadata.getFirstIdx(name)); |
| 103 | 101 | } |
| 104 | 102 | |
| 103 | + @Override | |
| 105 | 104 | public Token getPartitionKeyToken() { |
| 106 | 105 | int i = 0; |
| 107 | 106 | for (ColumnDefinitions.Definition column : metadata) { |
modified driver-core/src/main/java/com/datastax/driver/core/ColumnDefinitions.java +4 −52
| @@ -55,15 +55,16 @@ | ||
| 55 | 55 | */ |
| 56 | 56 | public class ColumnDefinitions implements Iterable<ColumnDefinitions.Definition> { |
| 57 | 57 | |
| 58 | - static final ColumnDefinitions EMPTY = new ColumnDefinitions(new Definition[0]); | |
| 58 | + static final ColumnDefinitions EMPTY = new ColumnDefinitions(new Definition[0], CodecRegistry.DEFAULT_INSTANCE); | |
| 59 | 59 | |
| 60 | 60 | private final Definition[] byIdx; |
| 61 | 61 | private final Map<String, int[]> byName; |
| 62 | - private volatile CodecRegistry codecRegistry; | |
| 62 | + final CodecRegistry codecRegistry; | |
| 63 | 63 | |
| 64 | - ColumnDefinitions(Definition[] defs) { | |
| 64 | + ColumnDefinitions(Definition[] defs, CodecRegistry codecRegistry) { | |
| 65 | 65 | |
| 66 | 66 | this.byIdx = defs; |
| 67 | + this.codecRegistry = codecRegistry; | |
| 67 | 68 | this.byName = new HashMap<String, int[]>(defs.length); |
| 68 | 69 | |
| 69 | 70 | for (int i = 0; i < defs.length; i++) { |
| @@ -278,55 +279,6 @@ | ||
| 278 | 279 | return getAllIdx(name)[0]; |
| 279 | 280 | } |
| 280 | 281 | |
| 281 | - CodecRegistry getCodecRegistry() { | |
| 282 | - // this method should only be called after this field is set | |
| 283 | - assert codecRegistry != null; | |
| 284 | - return codecRegistry; | |
| 285 | - } | |
| 286 | - | |
| 287 | - void setCodecRegistry(CodecRegistry codecRegistry) { | |
| 288 | - for (Definition definition : byIdx) { | |
| 289 | - propagateCodecRegistry(definition.type, codecRegistry); | |
| 290 | - } | |
| 291 | - this.codecRegistry = codecRegistry; | |
| 292 | - } | |
| 293 | - | |
| 294 | - /** | |
| 295 | - * Propagate a CodecRegistry instance to a given type and its child types, if any. | |
| 296 | - * <p> | |
| 297 | - * By the time CQL types are decoded from response messages, the codec registry is not available; | |
| 298 | - * This method manually sets a CodecRegistry on all CQL types that require it, | |
| 299 | - * and thus should be called immediately after a response is decoded | |
| 300 | - * into either a prepared statement or a result set. | |
| 301 | - * | |
| 302 | - * @param cqlType The decodec {@link DataType cqlType}. | |
| 303 | - * @param codecRegistry The {@link CodecRegistry} instance to use. | |
| 304 | - */ | |
| 305 | - static void propagateCodecRegistry(DataType cqlType, CodecRegistry codecRegistry) { | |
| 306 | - // user types | |
| 307 | - if(cqlType instanceof UserType) { | |
| 308 | - UserType userType = (UserType)cqlType; | |
| 309 | - userType.setCodecRegistry(codecRegistry); | |
| 310 | - for (UserType.Field field : userType.byIdx) { | |
| 311 | - propagateCodecRegistry(field.getType(), codecRegistry); | |
| 312 | - } | |
| 313 | - } | |
| 314 | - // tuples | |
| 315 | - else if(cqlType instanceof TupleType) { | |
| 316 | - TupleType tupleType = (TupleType)cqlType; | |
| 317 | - tupleType.setCodecRegistry(codecRegistry); | |
| 318 | - for (DataType componentType : tupleType.getComponentTypes()) { | |
| 319 | - propagateCodecRegistry(componentType, codecRegistry); | |
| 320 | - } | |
| 321 | - } | |
| 322 | - // collections | |
| 323 | - else if(cqlType.isCollection()) { | |
| 324 | - for (DataType inner : cqlType.getTypeArguments()) { | |
| 325 | - propagateCodecRegistry(inner, codecRegistry); | |
| 326 | - } | |
| 327 | - } | |
| 328 | - } | |
| 329 | - | |
| 330 | 282 | /** |
| 331 | 283 | * A column definition. |
| 332 | 284 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +9 −2
| @@ -135,7 +135,8 @@ | ||
| 135 | 135 | bootstrap.handler( |
| 136 | 136 | new Initializer(this, protocolVersion, protocolOptions.getCompression().compressor(), protocolOptions.getSSLOptions(), |
| 137 | 137 | factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds(), |
| 138 | - factory.configuration.getNettyOptions())); | |
| 138 | + factory.configuration.getNettyOptions(), | |
| 139 | + factory.configuration.getCodecRegistry())); | |
| 139 | 140 | |
| 140 | 141 | ChannelFuture future = bootstrap.connect(address); |
| 141 | 142 | |
| @@ -1282,18 +1283,24 @@ | ||
| 1282 | 1283 | private final SSLOptions sslOptions; |
| 1283 | 1284 | private final NettyOptions nettyOptions; |
| 1284 | 1285 | private final ChannelHandler idleStateHandler; |
| 1286 | + private final CodecRegistry codecRegistry; | |
| 1285 | 1287 | |
| 1286 | - public Initializer(Connection connection, ProtocolVersion protocolVersion, FrameCompressor compressor, SSLOptions sslOptions, int heartBeatIntervalSeconds, NettyOptions nettyOptions) { | |
| 1288 | + public Initializer(Connection connection, ProtocolVersion protocolVersion, FrameCompressor compressor, SSLOptions sslOptions, int heartBeatIntervalSeconds, NettyOptions nettyOptions, CodecRegistry codecRegistry) { | |
| 1287 | 1289 | this.connection = connection; |
| 1288 | 1290 | this.protocolVersion = protocolVersion; |
| 1289 | 1291 | this.compressor = compressor; |
| 1290 | 1292 | this.sslOptions = sslOptions; |
| 1291 | 1293 | this.nettyOptions = nettyOptions; |
| 1294 | + this.codecRegistry = codecRegistry; | |
| 1292 | 1295 | this.idleStateHandler = new IdleStateHandler(0, 0, heartBeatIntervalSeconds); |
| 1293 | 1296 | } |
| 1294 | 1297 | |
| 1295 | 1298 | @Override |
| 1296 | 1299 | protected void initChannel(SocketChannel channel) throws Exception { |
| 1300 | + | |
| 1301 | + // set the codec registry so that it can be accessed by ProtocolDecoder | |
| 1302 | + channel.attr(Message.CODEC_REGISTRY_ATTRIBUTE_KEY).set(codecRegistry); | |
| 1303 | + | |
| 1297 | 1304 | ChannelPipeline pipeline = channel.pipeline(); |
| 1298 | 1305 | |
| 1299 | 1306 | if (sslOptions != null) { |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultPreparedStatement.java +0 −2
| @@ -56,8 +56,6 @@ | ||
| 56 | 56 | |
| 57 | 57 | ColumnDefinitions defs = msg.metadata.columns; |
| 58 | 58 | |
| 59 | - defs.setCodecRegistry(cluster.getConfiguration().getCodecRegistry()); | |
| 60 | - | |
| 61 | 59 | ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); |
| 62 | 60 | |
| 63 | 61 | if (defs.size() == 0) { |
modified driver-core/src/main/java/com/datastax/driver/core/Message.java +7 −2
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | import io.netty.channel.ChannelHandlerContext; |
| 24 | 24 | import io.netty.handler.codec.MessageToMessageDecoder; |
| 25 | 25 | import io.netty.handler.codec.MessageToMessageEncoder; |
| 26 | +import io.netty.util.AttributeKey; | |
| 26 | 27 | import org.slf4j.Logger; |
| 27 | 28 | import org.slf4j.LoggerFactory; |
| 28 | 29 | |
| @@ -36,13 +37,15 @@ | ||
| 36 | 37 | |
| 37 | 38 | protected static final Logger logger = LoggerFactory.getLogger(Message.class); |
| 38 | 39 | |
| 40 | + static AttributeKey<CodecRegistry> CODEC_REGISTRY_ATTRIBUTE_KEY = AttributeKey.newInstance("com.datastax.driver.core.CodecRegistry"); | |
| 41 | + | |
| 39 | 42 | public interface Coder<R extends Request> { |
| 40 | 43 | public void encode(R request, ByteBuf dest, ProtocolVersion version); |
| 41 | 44 | public int encodedSize(R request, ProtocolVersion version); |
| 42 | 45 | } |
| 43 | 46 | |
| 44 | 47 | public interface Decoder<R extends Response> { |
| 45 | - public R decode(ByteBuf body, ProtocolVersion version); | |
| 48 | + public R decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry); | |
| 46 | 49 | } |
| 47 | 50 | |
| 48 | 51 | private volatile int streamId; |
| @@ -240,7 +243,9 @@ | ||
| 240 | 243 | List<String> warnings = hasWarnings ? CBUtil.readStringList(frame.body) : Collections.<String>emptyList(); |
| 241 | 244 | |
| 242 | 245 | try { |
| 243 | - Response response = Response.Type.fromOpcode(frame.header.opcode).decoder.decode(frame.body, frame.header.version); | |
| 246 | + CodecRegistry codecRegistry = ctx.channel().attr(CODEC_REGISTRY_ATTRIBUTE_KEY).get(); | |
| 247 | + assert codecRegistry != null; | |
| 248 | + Response response = Response.Type.fromOpcode(frame.header.opcode).decoder.decode(frame.body, frame.header.version, codecRegistry); | |
| 244 | 249 | response |
| 245 | 250 | .setTracingId(tracingId) |
| 246 | 251 | .setWarnings(warnings) |
modified driver-core/src/main/java/com/datastax/driver/core/Responses.java +34 −29
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | |
| 40 | 40 | public static final Message.Decoder<Error> decoder = new Message.Decoder<Error>() { |
| 41 | 41 | @Override |
| 42 | - public Error decode(ByteBuf body, ProtocolVersion version) { | |
| 42 | + public Error decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 43 | 43 | ExceptionCode code = ExceptionCode.fromValue(body.readInt()); |
| 44 | 44 | String msg = CBUtil.readString(body); |
| 45 | 45 | Object infos = null; |
| @@ -138,7 +138,7 @@ | ||
| 138 | 138 | public static class Ready extends Message.Response { |
| 139 | 139 | |
| 140 | 140 | public static final Message.Decoder<Ready> decoder = new Message.Decoder<Ready>() { |
| 141 | - public Ready decode(ByteBuf body, ProtocolVersion version) { | |
| 141 | + public Ready decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 142 | 142 | // TODO: Would it be cool to return a singleton? Check we don't need to |
| 143 | 143 | // set the streamId or something |
| 144 | 144 | return new Ready(); |
| @@ -158,7 +158,7 @@ | ||
| 158 | 158 | public static class Authenticate extends Message.Response { |
| 159 | 159 | |
| 160 | 160 | public static final Message.Decoder<Authenticate> decoder = new Message.Decoder<Authenticate>() { |
| 161 | - public Authenticate decode(ByteBuf body, ProtocolVersion version) { | |
| 161 | + public Authenticate decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 162 | 162 | String authenticator = CBUtil.readString(body); |
| 163 | 163 | return new Authenticate(authenticator); |
| 164 | 164 | } |
| @@ -180,7 +180,7 @@ | ||
| 180 | 180 | public static class Supported extends Message.Response { |
| 181 | 181 | |
| 182 | 182 | public static final Message.Decoder<Supported> decoder = new Message.Decoder<Supported>() { |
| 183 | - public Supported decode(ByteBuf body, ProtocolVersion version) { | |
| 183 | + public Supported decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 184 | 184 | return new Supported(CBUtil.readStringToStringListMap(body)); |
| 185 | 185 | } |
| 186 | 186 | }; |
| @@ -216,9 +216,9 @@ | ||
| 216 | 216 | public static abstract class Result extends Message.Response { |
| 217 | 217 | |
| 218 | 218 | public static final Message.Decoder<Result> decoder = new Message.Decoder<Result>() { |
| 219 | - public Result decode(ByteBuf body, ProtocolVersion version) { | |
| 219 | + public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 220 | 220 | Kind kind = Kind.fromId(body.readInt()); |
| 221 | - return kind.subDecoder.decode(body, version); | |
| 221 | + return kind.subDecoder.decode(body, version, codecRegistry); | |
| 222 | 222 | } |
| 223 | 223 | }; |
| 224 | 224 | |
| @@ -273,7 +273,7 @@ | ||
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | public static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 276 | - public Result decode(ByteBuf body, ProtocolVersion version) { | |
| 276 | + public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 277 | 277 | return new Void(); |
| 278 | 278 | } |
| 279 | 279 | }; |
| @@ -293,7 +293,7 @@ | ||
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | public static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 296 | - public Result decode(ByteBuf body, ProtocolVersion version) { | |
| 296 | + public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 297 | 297 | return new SetKeyspace(CBUtil.readString(body)); |
| 298 | 298 | } |
| 299 | 299 | }; |
| @@ -347,11 +347,11 @@ | ||
| 347 | 347 | this.pkIndices = pkIndices; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - public static Metadata decode(ByteBuf body, ProtocolVersion protocolVersion) { | |
| 351 | - return decode(body, false, protocolVersion); | |
| 350 | + public static Metadata decode(ByteBuf body, ProtocolVersion protocolVersion, CodecRegistry codecRegistry) { | |
| 351 | + return decode(body, false, protocolVersion, codecRegistry); | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - public static Metadata decode(ByteBuf body, boolean withPkIndices, ProtocolVersion protocolVersion) { | |
| 354 | + public static Metadata decode(ByteBuf body, boolean withPkIndices, ProtocolVersion protocolVersion, CodecRegistry codecRegistry) { | |
| 355 | 355 | |
| 356 | 356 | // flags & column count |
| 357 | 357 | EnumSet<Flag> flags = Flag.deserialize(body.readInt()); |
| @@ -387,13 +387,11 @@ | ||
| 387 | 387 | String ksName = globalTablesSpec ? globalKsName : CBUtil.readString(body); |
| 388 | 388 | String cfName = globalTablesSpec ? globalCfName : CBUtil.readString(body); |
| 389 | 389 | String name = CBUtil.readString(body); |
| 390 | - // will set the appropriate CodecRegistry instance later | |
| 391 | - // when the message will be decoded into either a PreparedStatement or a ResultSet | |
| 392 | - DataType type = DataType.decode(body, protocolVersion, CodecRegistry.DEFAULT_INSTANCE); | |
| 390 | + DataType type = DataType.decode(body, protocolVersion, codecRegistry); | |
| 393 | 391 | defs[i] = new ColumnDefinitions.Definition(ksName, cfName, name, type); |
| 394 | 392 | } |
| 395 | 393 | |
| 396 | - return new Metadata(columnCount, new ColumnDefinitions(defs), state, pkIndices); | |
| 394 | + return new Metadata(columnCount, new ColumnDefinitions(defs, codecRegistry), state, pkIndices); | |
| 397 | 395 | } |
| 398 | 396 | |
| 399 | 397 | @Override |
| @@ -415,9 +413,9 @@ | ||
| 415 | 413 | } |
| 416 | 414 | |
| 417 | 415 | public static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 418 | - public Result decode(ByteBuf body, ProtocolVersion version) { | |
| 416 | + public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 419 | 417 | |
| 420 | - Metadata metadata = Metadata.decode(body, version); | |
| 418 | + Metadata metadata = Metadata.decode(body, version, codecRegistry); | |
| 421 | 419 | |
| 422 | 420 | int rowCount = body.readInt(); |
| 423 | 421 | int columnCount = metadata.columnCount; |
| @@ -457,11 +455,18 @@ | ||
| 457 | 455 | } else { |
| 458 | 456 | sb.append(" | "); |
| 459 | 457 | if (metadata.columns != null) { |
| 460 | - sb.append(metadata.columns.getType(i)); | |
| 458 | + DataType dataType = metadata.columns.getType(i); | |
| 459 | + sb.append(dataType); | |
| 461 | 460 | sb.append(" "); |
| 461 | + TypeCodec<Object> codec = metadata.columns.codecRegistry.codecFor(dataType); | |
| 462 | + Object o = codec.deserialize(v, version); | |
| 463 | + String s = codec.format(o); | |
| 464 | + if (s.length() > 100) | |
| 465 | + s = s.substring(0, 100) + "..."; | |
| 466 | + sb.append(s); | |
| 467 | + } else { | |
| 468 | + sb.append(Bytes.toHexString(v)); | |
| 462 | 469 | } |
| 463 | - // cannot deserialize without the right CodecRegistry instance | |
| 464 | - sb.append(Bytes.toHexString(v)); | |
| 465 | 470 | } |
| 466 | 471 | } |
| 467 | 472 | sb.append('\n'); |
| @@ -474,22 +479,22 @@ | ||
| 474 | 479 | public static class Prepared extends Result { |
| 475 | 480 | |
| 476 | 481 | public static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 477 | - public Result decode(ByteBuf body, ProtocolVersion version) { | |
| 482 | + public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 478 | 483 | MD5Digest id = MD5Digest.wrap(CBUtil.readBytes(body)); |
| 479 | 484 | boolean withPkIndices = version.compareTo(V4) >= 0; |
| 480 | - Rows.Metadata metadata = Rows.Metadata.decode(body, withPkIndices, version); | |
| 481 | - Rows.Metadata resultMetadata = decodeResultMetadata(body, version); | |
| 485 | + Rows.Metadata metadata = Rows.Metadata.decode(body, withPkIndices, version, codecRegistry); | |
| 486 | + Rows.Metadata resultMetadata = decodeResultMetadata(body, version, codecRegistry); | |
| 482 | 487 | return new Prepared(id, metadata, resultMetadata); |
| 483 | 488 | } |
| 484 | 489 | |
| 485 | - private Metadata decodeResultMetadata(ByteBuf body, ProtocolVersion version) { | |
| 490 | + private Metadata decodeResultMetadata(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 486 | 491 | switch (version) { |
| 487 | 492 | case V1: |
| 488 | 493 | return Rows.Metadata.EMPTY; |
| 489 | 494 | case V2: |
| 490 | 495 | case V3: |
| 491 | 496 | case V4: |
| 492 | - return Rows.Metadata.decode(body, version); | |
| 497 | + return Rows.Metadata.decode(body, version, codecRegistry); | |
| 493 | 498 | default: |
| 494 | 499 | throw version.unsupported(); |
| 495 | 500 | } |
| @@ -524,7 +529,7 @@ | ||
| 524 | 529 | public final List<String> targetSignature; |
| 525 | 530 | |
| 526 | 531 | public static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 527 | - public Result decode(ByteBuf body, ProtocolVersion version) | |
| 532 | + public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) | |
| 528 | 533 | { |
| 529 | 534 | // Note: the CREATE KEYSPACE/TABLE/TYPE SCHEMA_CHANGE response is different from the SCHEMA_CHANGE EVENT type |
| 530 | 535 | Change change; |
| @@ -575,7 +580,7 @@ | ||
| 575 | 580 | public static class Event extends Message.Response { |
| 576 | 581 | |
| 577 | 582 | public static final Message.Decoder<Event> decoder = new Message.Decoder<Event>() { |
| 578 | - public Event decode(ByteBuf body, ProtocolVersion version) { | |
| 583 | + public Event decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 579 | 584 | return new Event(ProtocolEvent.deserialize(body, version)); |
| 580 | 585 | } |
| 581 | 586 | }; |
| @@ -596,7 +601,7 @@ | ||
| 596 | 601 | public static class AuthChallenge extends Message.Response { |
| 597 | 602 | |
| 598 | 603 | public static final Message.Decoder<AuthChallenge> decoder = new Message.Decoder<AuthChallenge>() { |
| 599 | - public AuthChallenge decode(ByteBuf body, ProtocolVersion version) { | |
| 604 | + public AuthChallenge decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 600 | 605 | ByteBuffer b = CBUtil.readValue(body); |
| 601 | 606 | if (b == null) |
| 602 | 607 | return new AuthChallenge(null); |
| @@ -618,7 +623,7 @@ | ||
| 618 | 623 | public static class AuthSuccess extends Message.Response { |
| 619 | 624 | |
| 620 | 625 | public static final Message.Decoder<AuthSuccess> decoder = new Message.Decoder<AuthSuccess>() { |
| 621 | - public AuthSuccess decode(ByteBuf body, ProtocolVersion version) { | |
| 626 | + public AuthSuccess decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { | |
| 622 | 627 | ByteBuffer b = CBUtil.readValue(body); |
| 623 | 628 | if (b == null) |
| 624 | 629 | return new AuthSuccess(null); |
modified driver-core/src/test/java/com/datastax/driver/core/ColumnDefinitionsTest.java +3 −3
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | new ColumnDefinitions.Definition("ks", "cf", "aColumn", DataType.text()), |
| 30 | 30 | new ColumnDefinitions.Definition("ks", "cf", "fOO", DataType.text()), |
| 31 | 31 | new ColumnDefinitions.Definition("ks", "cf", "anotherColumn", DataType.text()) |
| 32 | - }); | |
| 32 | + }, CodecRegistry.DEFAULT_INSTANCE); | |
| 33 | 33 | |
| 34 | 34 | assertTrue(defs.contains("foo")); |
| 35 | 35 | assertTrue(defs.contains("fOO")); |
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | new ColumnDefinitions.Definition("ks", "cf", "with \" quote", DataType.text()), |
| 44 | 44 | new ColumnDefinitions.Definition("ks", "cf", "\"in quote\"", DataType.text()), |
| 45 | 45 | new ColumnDefinitions.Definition("ks", "cf", "in quote", DataType.cint()), |
| 46 | - }); | |
| 46 | + }, CodecRegistry.DEFAULT_INSTANCE); | |
| 47 | 47 | |
| 48 | 48 | assertTrue(defs.getType("foo").equals(DataType.text())); |
| 49 | 49 | assertTrue(defs.getType("Foo").equals(DataType.text())); |
| @@ -64,7 +64,7 @@ | ||
| 64 | 64 | new ColumnDefinitions.Definition("ks", "cf1", "column", DataType.text()), |
| 65 | 65 | new ColumnDefinitions.Definition("ks", "cf2", "column", DataType.cint()), |
| 66 | 66 | new ColumnDefinitions.Definition("ks", "cf3", "column", DataType.cfloat()) |
| 67 | - }); | |
| 67 | + }, CodecRegistry.DEFAULT_INSTANCE); | |
| 68 | 68 | |
| 69 | 69 | assertTrue(defs.getType("column").equals(DataType.text())); |
| 70 | 70 | } |
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +2 −5
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | definition(INDEX_TYPE, text()), |
| 52 | 52 | definition(VALIDATOR, text()), |
| 53 | 53 | definition(INDEX_OPTIONS, text()) |
| 54 | - }); | |
| 54 | + }, CodecRegistry.DEFAULT_INSTANCE); | |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Column definitions for indexes table (post-3.0 layout). |
| @@ -60,7 +60,7 @@ | ||
| 60 | 60 | definition(IndexMetadata.NAME, text()), |
| 61 | 61 | definition(IndexMetadata.KIND, text()), |
| 62 | 62 | definition(IndexMetadata.OPTIONS, map(text(), text())) |
| 63 | - }); | |
| 63 | + }, CodecRegistry.DEFAULT_INSTANCE); | |
| 64 | 64 | |
| 65 | 65 | private static final TypeCodec<Map<String, String>> MAP_CODEC = TypeCodec.map(TypeCodec.varchar(), TypeCodec.varchar()); |
| 66 | 66 | |
| @@ -70,9 +70,6 @@ | ||
| 70 | 70 | @BeforeClass(groups = { "short", "long" }) |
| 71 | 71 | public void beforeClass() { |
| 72 | 72 | super.beforeClass(); |
| 73 | - CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); | |
| 74 | - legacyColumnDefs.setCodecRegistry(codecRegistry); | |
| 75 | - indexColumnDefs.setCodecRegistry(codecRegistry); | |
| 76 | 73 | protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); |
| 77 | 74 | } |
| 78 | 75 |