IntToBooleanCodec() { super(TypeCodec.cint(), Boolean.class); }
IntToBigDecimalCodec() { super(TypeCodec.cint(), BigDecimal.class); }
IntToLocalDateCodec() { super(TypeCodec.cint(), LocalDate.class); }
IntToUUIDCodec() { super(TypeCodec.cint(), UUID.class); }
IntToByteBufferCodec() { super(TypeCodec.cint(), ByteBuffer.class); }
IntToFloatCodec() { super(TypeCodec.cint(), Float.class); }
IntToDateCodec() { super(TypeCodec.cint(), Date.class); }
IntToStringCodec() { super(TypeCodec.cint(), String.class); }
IntToInetAddressCodec() { super(TypeCodec.cint(), InetAddress.class); }
IntToLongCodec() { super(TypeCodec.cint(), Long.class); }
IntToShortCodec() { super(TypeCodec.cint(), Short.class); }
IntToBigIntegerCodec() { super(TypeCodec.cint(), BigInteger.class); }
IntToDoubleCodec() { super(TypeCodec.cint(), Double.class); }
@Override public String deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException { Integer i = TypeCodec.cint().deserialize(bytes, protocolVersion); return i == null ? null : Integer.toString(i); }
@Override public ByteBuffer serialize(MyInt value, ProtocolVersion protocolVersion) throws InvalidTypeException { return TypeCodec.cint().serialize(value.i, protocolVersion); }
@Override public ByteBuffer serialize(String value, ProtocolVersion protocolVersion) throws InvalidTypeException { return TypeCodec.cint() .serialize(value == null ? null : Integer.parseInt(value), protocolVersion); }
@Override public MyInt deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException { return new MyInt(TypeCodec.cint().deserialize(bytes, protocolVersion)); }
@Test(groups = "short") public void should_create_token_from_partition_key() { Metadata metadata = cluster().getMetadata(); Row row = session().execute("SELECT token(i) FROM foo WHERE i = 1").one(); Token expected = row.getToken(0); ProtocolVersion protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); assertThat(metadata.newToken(TypeCodec.cint().serialize(1, protocolVersion))) .isEqualTo(expected); }
@Override public Cluster.Builder createClusterBuilder() { return Cluster.builder() .withCodecRegistry( new CodecRegistry() .register( new NumberBoxCodec<Integer>(TypeCodec.cint()), new NumberBoxCodec<Long>(TypeCodec.bigint()), new NumberBoxCodec<Float>(TypeCodec.cfloat()), new NumberBoxCodec<Double>(TypeCodec.cdouble()), new NumberBoxCodec<BigInteger>(TypeCodec.varint()), new NumberBoxCodec<BigDecimal>(TypeCodec.decimal()))); }
/** Ensures that primitive types are correctly handled and wrapped when necessary. */ @Test(groups = "unit") public void should_wrap_primitive_types() { assertThat(TypeCodec.cboolean()).accepts(Boolean.class).accepts(Boolean.TYPE).accepts(true); assertThat(TypeCodec.cint()).accepts(Integer.class).accepts(Integer.TYPE).accepts(42); assertThat(TypeCodec.bigint()).accepts(Long.class).accepts(Long.TYPE).accepts(42L); assertThat(TypeCodec.cfloat()).accepts(Float.class).accepts(Float.TYPE).accepts(42.0F); assertThat(TypeCodec.cdouble()).accepts(Double.class).accepts(Double.TYPE).accepts(42.0D); }