statement.setBool(paramIndex, (boolean) typeCodec.parse(paramValue)); statement.setInt(paramIndex, (int) typeCodec.parse(paramValue)); statement.setLong(paramIndex, (long) typeCodec.parse(paramValue)); statement.setFloat(paramIndex, (float) typeCodec.parse(paramValue)); statement.setDouble(paramIndex, (double) typeCodec.parse(paramValue)); statement.setBytes(paramIndex, (ByteBuffer) typeCodec.parse(paramValue)); statement.setTimestamp(paramIndex, (Date) typeCodec.parse(paramValue)); DataType secondParamType = getPrimitiveDataTypeFromString(secondParamTypeName); DataType mapType = DataType.map(firstParamType, secondParamType); statement.setMap(paramIndex, (Map) codecRegistry.codecFor(mapType).parse(paramValue)); return; statement.setSet(paramIndex, (Set) codecRegistry.codecFor(setType).parse(paramValue)); return; } else if (DataType.Name.LIST.toString().equalsIgnoreCase(mainTypeString)) { DataType listType = DataType.list(firstParamType); statement.setList(paramIndex, (List) codecRegistry.codecFor(listType).parse(paramValue)); return;
@Override public O parse(String value) throws InvalidTypeException { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : deserialize(innerCodec.parse(value)); }
@Override public NumberBox<T> parse(String value) throws InvalidTypeException { return new NumberBox<T>(numberCodec.parse(value)); }
@Override protected TupleValue parseAndSetField(String input, TupleValue target, int index) { DataType elementType = definition.getComponentTypes().get(index); TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType); target.set(index, codec.parse(input), codec.getJavaType()); return target; } }
l.add(eltCodec.parse(value.substring(idx, n))); idx = n;
@Override protected UDTValue parseAndSetField(String input, UDTValue target, String fieldName) { DataType elementType = definition.getFieldType(fieldName); TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType); target.set(fieldName, codec.parse(input), codec.getJavaType()); return target; } }
@Test(groups = "unit") public void parseFormatListTest() { String toParse = "['Foo','Bar','Foo''bar']"; List<String> toFormat = Arrays.asList("Foo", "Bar", "Foo'bar"); DataType dt = DataType.list(DataType.text()); assertEquals(codecRegistry.codecFor(dt).parse(toParse), toFormat); assertEquals(codecRegistry.codecFor(dt).format(toFormat), toParse); }
private void assertCodec(String input, Duration expected) { // serialize + deserialize ByteBuffer bytes = TypeCodec.duration().serialize(Duration.from(input), V4); Duration actual = TypeCodec.duration().deserialize(bytes, V4); assertThat(actual).isEqualTo(expected); // format + parse String format = TypeCodec.duration().format(Duration.from(input)); actual = TypeCodec.duration().parse(format); assertThat(actual).isEqualTo(expected); // parse alone actual = TypeCodec.duration().parse(input); assertThat(actual).isEqualTo(expected); } }
@SuppressWarnings("deprecation") @Test(groups = "unit") public void parseFormatTupleTest() { String toParse = "(1,'foo',1.0)"; TupleType t = new TupleType( newArrayList(DataType.cint(), DataType.text(), DataType.cfloat()), protocolVersion, codecRegistry); TupleValue toFormat = t.newValue(1, "foo", 1.0f); assertEquals(codecRegistry.codecFor(t).parse(toParse), toFormat); assertEquals(codecRegistry.codecFor(t).format(toFormat), toParse); }
@Test(groups = "unit") public void parseNativeTest() { for (DataType dt : DataType.allPrimitiveTypes()) { if (exclude(dt)) continue; for (TestValue value : primitiveTestValues(dt)) assertThat(codecRegistry.codecFor(dt).parse(value.cqlInputString)) .as("Parsing input %s to a %s", value.cqlInputString, dt) .isEqualTo(value.javaObject); } }
@SuppressWarnings("serial") @Test(groups = "unit") public void parseFormatSetTest() { String toParse = "{'Foo','Bar','Foo''bar'}"; Set<String> toFormat = new LinkedHashSet<String>() { { add("Foo"); add("Bar"); add("Foo'bar"); } }; DataType dt = DataType.set(DataType.text()); assertEquals(codecRegistry.codecFor(dt).parse(toParse), toFormat); assertEquals(codecRegistry.codecFor(dt).format(toFormat), toParse); }
@SuppressWarnings("serial") @Test(groups = "unit") public void parseFormatMapTest() { String toParse = "{'Foo':3,'Bar':42,'Foo''bar':-24}"; Map<String, Integer> toFormat = new LinkedHashMap<String, Integer>() { { put("Foo", 3); put("Bar", 42); put("Foo'bar", -24); } }; DataType dt = DataType.map(DataType.text(), DataType.cint()); assertEquals(codecRegistry.codecFor(dt).parse(toParse), toFormat); assertEquals(codecRegistry.codecFor(dt).format(toFormat), toParse); }
@Override public O parse(String value) throws InvalidTypeException { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : deserialize(innerCodec.parse(value)); }
@Override public T parse(String value) throws InvalidTypeException { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : fromString(innerCodec.parse(value)); }
} else { try { initCond = codecRegistry.codecFor(stateType).parse(rawInitCond); } catch (RuntimeException e) { LOGGER.warn(
assertEquals(codecRegistry.codecFor(udt2).parse(toParse), toFormat); assertEquals(codecRegistry.codecFor(udt2).format(toFormat), toParse);
@Override public O parse(String value) throws InvalidTypeException { return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? null : deserialize(innerCodec.parse(value)); }
@Override protected TupleValue parseAndSetField(String input, TupleValue target, int index) { DataType elementType = definition.getComponentTypes().get(index); TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType); target.set(index, codec.parse(input), codec.getJavaType()); return target; }
@Override protected UDTValue parseAndSetField(String input, UDTValue target, String fieldName) { DataType elementType = definition.getFieldType(fieldName); TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType); target.set(fieldName, codec.parse(input), codec.getJavaType()); return target; } }