private static boolean checkWasApplied( List<ByteBuffer> firstRow, ColumnDefinitions metadata, ProtocolVersion protocolVersion) { // If the column is not present or not a boolean, we assume the query // was not a conditional statement, and therefore return true. if (firstRow == null) return true; int[] is = metadata.findAllIdx("[applied]"); if (is == null) return true; int i = is[0]; if (!DataType.cboolean().equals(metadata.getType(i))) return true; // Otherwise return the value of the column ByteBuffer value = firstRow.get(i); if (value == null || value.remaining() == 0) return false; return TypeCodec.cboolean().deserializeNoBoxing(value, protocolVersion); } }
@DataProvider public static Object[][] value() { return new Object[][] { {ByteBuffer.allocate(0), TypeCodec.blob()}, {Boolean.TRUE, TypeCodec.cboolean()}, {(short) 42, TypeCodec.smallInt()}, {(byte) 42, TypeCodec.tinyInt()}, {42, TypeCodec.cint()}, {42L, TypeCodec.bigint()}, {42D, TypeCodec.cdouble()}, {42F, TypeCodec.cfloat()}, {new BigInteger("1234"), TypeCodec.varint()}, {new BigDecimal("123.45"), TypeCodec.decimal()}, {"foo", TypeCodec.varchar()}, {new Date(42), TypeCodec.timestamp()}, {LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()}, {UUID.randomUUID(), TypeCodec.uuid()}, {mock(InetAddress.class), TypeCodec.inet()}, {Duration.from("1mo2d3h"), TypeCodec.duration()} }; }
protected boolean compose_boolean(ProtocolVersion protocolVersion, int argIndex, ByteBuffer value) { assert value != null && value.remaining() > 0; return (boolean) UDHelper.deserialize(TypeCodec.cboolean(), protocolVersion, value); } }
protected boolean compose_boolean(ProtocolVersion protocolVersion, int argIndex, ByteBuffer value) { assert value != null && value.remaining() > 0; return (boolean) UDHelper.deserialize(TypeCodec.cboolean(), protocolVersion, value); } }
protected boolean compose_boolean(ProtocolVersion protocolVersion, int argIndex, ByteBuffer value) { assert value != null && value.remaining() > 0; return (boolean) UDHelper.deserialize(TypeCodec.cboolean(), protocolVersion, value); } }
@DataProvider public static Object[][] cqlAndValue() { return new Object[][] { {DataType.blob(), ByteBuffer.allocate(0), TypeCodec.blob()}, {DataType.cboolean(), true, TypeCodec.cboolean()}, {DataType.smallint(), (short) 42, TypeCodec.smallInt()}, {DataType.tinyint(), (byte) 42, TypeCodec.tinyInt()}, {DataType.cint(), 42, TypeCodec.cint()}, {DataType.bigint(), 42L, TypeCodec.bigint()}, {DataType.counter(), 42L, TypeCodec.counter()}, {DataType.cdouble(), 42D, TypeCodec.cdouble()}, {DataType.cfloat(), 42F, TypeCodec.cfloat()}, {DataType.varint(), new BigInteger("1234"), TypeCodec.varint()}, {DataType.decimal(), new BigDecimal("123.45"), TypeCodec.decimal()}, {DataType.varchar(), "foo", TypeCodec.varchar()}, {DataType.ascii(), "foo", TypeCodec.ascii()}, {DataType.timestamp(), new Date(42), TypeCodec.timestamp()}, {DataType.date(), LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()}, {DataType.time(), 42L, TypeCodec.time()}, {DataType.uuid(), UUID.randomUUID(), TypeCodec.uuid()}, {DataType.timeuuid(), UUID.randomUUID(), TypeCodec.timeUUID()}, {DataType.inet(), mock(InetAddress.class), TypeCodec.inet()}, {DataType.duration(), Duration.from("1mo2d3h"), TypeCodec.duration()} }; }
/** 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); }
private static boolean checkWasApplied(List<ByteBuffer> firstRow, ColumnDefinitions metadata, ProtocolVersion protocolVersion) { // If the column is not present or not a boolean, we assume the query // was not a conditional statement, and therefore return true. if (firstRow == null) return true; int[] is = metadata.findAllIdx("[applied]"); if (is == null) return true; int i = is[0]; if (!DataType.cboolean().equals(metadata.getType(i))) return true; // Otherwise return the value of the column ByteBuffer value = firstRow.get(i); if (value == null || value.remaining() == 0) return false; return TypeCodec.cboolean().deserializeNoBoxing(value, protocolVersion); } }
private static boolean checkWasApplied(List<ByteBuffer> firstRow, ColumnDefinitions metadata, ProtocolVersion protocolVersion) { // If the column is not present or not a boolean, we assume the query // was not a conditional statement, and therefore return true. if (firstRow == null) return true; int[] is = metadata.findAllIdx("[applied]"); if (is == null) return true; int i = is[0]; if (!DataType.cboolean().equals(metadata.getType(i))) return true; // Otherwise return the value of the column ByteBuffer value = firstRow.get(i); if (value == null || value.remaining() == 0) return false; return TypeCodec.cboolean().deserializeNoBoxing(value, protocolVersion); } }
private static boolean checkWasApplied(List<ByteBuffer> firstRow, ColumnDefinitions metadata, ProtocolVersion protocolVersion) { // If the column is not present or not a boolean, we assume the query // was not a conditional statement, and therefore return true. if (firstRow == null) return true; int[] is = metadata.findAllIdx("[applied]"); if (is == null) return true; int i = is[0]; if (!DataType.cboolean().equals(metadata.getType(i))) return true; // Otherwise return the value of the column ByteBuffer value = firstRow.get(i); if (value == null || value.remaining() == 0) return false; return TypeCodec.cboolean().deserializeNoBoxing(value, protocolVersion); } }
@DataProvider public static Object[][] cql() { return new Object[][] { {DataType.blob(), TypeCodec.blob()}, {DataType.cboolean(), TypeCodec.cboolean()}, {DataType.smallint(), TypeCodec.smallInt()}, {DataType.tinyint(), TypeCodec.tinyInt()}, {DataType.cint(), TypeCodec.cint()}, {DataType.bigint(), TypeCodec.bigint()}, {DataType.counter(), TypeCodec.counter()}, {DataType.cdouble(), TypeCodec.cdouble()}, {DataType.cfloat(), TypeCodec.cfloat()}, {DataType.varint(), TypeCodec.varint()}, {DataType.decimal(), TypeCodec.decimal()}, {DataType.varchar(), TypeCodec.varchar()}, {DataType.ascii(), TypeCodec.ascii()}, {DataType.timestamp(), TypeCodec.timestamp()}, {DataType.date(), TypeCodec.date()}, {DataType.time(), TypeCodec.time()}, {DataType.uuid(), TypeCodec.uuid()}, {DataType.timeuuid(), TypeCodec.timeUUID()}, {DataType.inet(), TypeCodec.inet()}, {DataType.duration(), TypeCodec.duration()} }; }
@DataProvider public static Object[][] cqlAndJava() { return new Object[][] { {DataType.blob(), ByteBuffer.class, TypeCodec.blob()}, {DataType.cboolean(), Boolean.class, TypeCodec.cboolean()}, {DataType.smallint(), Short.class, TypeCodec.smallInt()}, {DataType.tinyint(), Byte.class, TypeCodec.tinyInt()}, {DataType.cint(), Integer.class, TypeCodec.cint()}, {DataType.bigint(), Long.class, TypeCodec.bigint()}, {DataType.counter(), Long.class, TypeCodec.counter()}, {DataType.cdouble(), Double.class, TypeCodec.cdouble()}, {DataType.cfloat(), Float.class, TypeCodec.cfloat()}, {DataType.varint(), BigInteger.class, TypeCodec.varint()}, {DataType.decimal(), BigDecimal.class, TypeCodec.decimal()}, {DataType.varchar(), String.class, TypeCodec.varchar()}, {DataType.ascii(), String.class, TypeCodec.ascii()}, {DataType.timestamp(), Date.class, TypeCodec.timestamp()}, {DataType.date(), LocalDate.class, TypeCodec.date()}, {DataType.time(), Long.class, TypeCodec.time()}, {DataType.uuid(), UUID.class, TypeCodec.uuid()}, {DataType.timeuuid(), UUID.class, TypeCodec.timeUUID()}, {DataType.inet(), InetAddress.class, TypeCodec.inet()}, {DataType.duration(), Duration.class, TypeCodec.duration()} }; }
@DataProvider public static Object[][] value() { return new Object[][] { {ByteBuffer.allocate(0), TypeCodec.blob()}, {Boolean.TRUE, TypeCodec.cboolean()}, {(short) 42, TypeCodec.smallInt()}, {(byte) 42, TypeCodec.tinyInt()}, {42, TypeCodec.cint()}, {42L, TypeCodec.bigint()}, {42D, TypeCodec.cdouble()}, {42F, TypeCodec.cfloat()}, {new BigInteger("1234"), TypeCodec.varint()}, {new BigDecimal("123.45"), TypeCodec.decimal()}, {"foo", TypeCodec.varchar()}, {new Date(42), TypeCodec.timestamp()}, {LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()}, {UUID.randomUUID(), TypeCodec.uuid()}, {mock(InetAddress.class), TypeCodec.inet()}, {Duration.from("1mo2d3h"), TypeCodec.duration()} }; }
break; case "boolean": typeCodec = TypeCodec.cboolean(); break; case "counter":
@DataProvider public static Object[][] cqlAndValue() { return new Object[][] { {DataType.blob(), ByteBuffer.allocate(0), TypeCodec.blob()}, {DataType.cboolean(), true, TypeCodec.cboolean()}, {DataType.smallint(), (short) 42, TypeCodec.smallInt()}, {DataType.tinyint(), (byte) 42, TypeCodec.tinyInt()}, {DataType.cint(), 42, TypeCodec.cint()}, {DataType.bigint(), 42L, TypeCodec.bigint()}, {DataType.counter(), 42L, TypeCodec.counter()}, {DataType.cdouble(), 42D, TypeCodec.cdouble()}, {DataType.cfloat(), 42F, TypeCodec.cfloat()}, {DataType.varint(), new BigInteger("1234"), TypeCodec.varint()}, {DataType.decimal(), new BigDecimal("123.45"), TypeCodec.decimal()}, {DataType.varchar(), "foo", TypeCodec.varchar()}, {DataType.ascii(), "foo", TypeCodec.ascii()}, {DataType.timestamp(), new Date(42), TypeCodec.timestamp()}, {DataType.date(), LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()}, {DataType.time(), 42L, TypeCodec.time()}, {DataType.uuid(), UUID.randomUUID(), TypeCodec.uuid()}, {DataType.timeuuid(), UUID.randomUUID(), TypeCodec.timeUUID()}, {DataType.inet(), mock(InetAddress.class), TypeCodec.inet()}, {DataType.duration(), Duration.from("1mo2d3h"), TypeCodec.duration()} }; }
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.bigint())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.blob())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cboolean())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cdouble())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cfloat()));
/** 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); }
this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.bigint())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.blob())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cboolean())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cdouble())); this.cluster.getConfiguration().getCodecRegistry().register(new OptionalCodec<>(TypeCodec.cfloat()));
@DataProvider public static Object[][] cql() { return new Object[][] { {DataType.blob(), TypeCodec.blob()}, {DataType.cboolean(), TypeCodec.cboolean()}, {DataType.smallint(), TypeCodec.smallInt()}, {DataType.tinyint(), TypeCodec.tinyInt()}, {DataType.cint(), TypeCodec.cint()}, {DataType.bigint(), TypeCodec.bigint()}, {DataType.counter(), TypeCodec.counter()}, {DataType.cdouble(), TypeCodec.cdouble()}, {DataType.cfloat(), TypeCodec.cfloat()}, {DataType.varint(), TypeCodec.varint()}, {DataType.decimal(), TypeCodec.decimal()}, {DataType.varchar(), TypeCodec.varchar()}, {DataType.ascii(), TypeCodec.ascii()}, {DataType.timestamp(), TypeCodec.timestamp()}, {DataType.date(), TypeCodec.date()}, {DataType.time(), TypeCodec.time()}, {DataType.uuid(), TypeCodec.uuid()}, {DataType.timeuuid(), TypeCodec.timeUUID()}, {DataType.inet(), TypeCodec.inet()}, {DataType.duration(), TypeCodec.duration()} }; }
@DataProvider public static Object[][] cqlAndJava() { return new Object[][] { {DataType.blob(), ByteBuffer.class, TypeCodec.blob()}, {DataType.cboolean(), Boolean.class, TypeCodec.cboolean()}, {DataType.smallint(), Short.class, TypeCodec.smallInt()}, {DataType.tinyint(), Byte.class, TypeCodec.tinyInt()}, {DataType.cint(), Integer.class, TypeCodec.cint()}, {DataType.bigint(), Long.class, TypeCodec.bigint()}, {DataType.counter(), Long.class, TypeCodec.counter()}, {DataType.cdouble(), Double.class, TypeCodec.cdouble()}, {DataType.cfloat(), Float.class, TypeCodec.cfloat()}, {DataType.varint(), BigInteger.class, TypeCodec.varint()}, {DataType.decimal(), BigDecimal.class, TypeCodec.decimal()}, {DataType.varchar(), String.class, TypeCodec.varchar()}, {DataType.ascii(), String.class, TypeCodec.ascii()}, {DataType.timestamp(), Date.class, TypeCodec.timestamp()}, {DataType.date(), LocalDate.class, TypeCodec.date()}, {DataType.time(), Long.class, TypeCodec.time()}, {DataType.uuid(), UUID.class, TypeCodec.uuid()}, {DataType.timeuuid(), UUID.class, TypeCodec.timeUUID()}, {DataType.inet(), InetAddress.class, TypeCodec.inet()}, {DataType.duration(), Duration.class, TypeCodec.duration()} }; }