use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_resolve_tuple_dependency.
@Test
public void should_resolve_tuple_dependency() {
UserDefinedTypeParser parser = new UserDefinedTypeParser(new DataTypeCqlNameParser(), context);
Map<CqlIdentifier, UserDefinedType> types = parser.parse(KEYSPACE_ID, mockTypeRow("ks", "a", ImmutableList.of("b"), ImmutableList.of("frozen<tuple<int, frozen<b>>>")), mockTypeRow("ks", "b", ImmutableList.of("i"), ImmutableList.of("int")));
assertThat(types).hasSize(2);
UserDefinedType aType = types.get(CqlIdentifier.fromInternal("a"));
UserDefinedType bType = types.get(CqlIdentifier.fromInternal("b"));
assertThat(((TupleType) aType.getFieldTypes().get(0)).getComponentTypes().get(1)).isEqualTo(bType);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class DefaultUdtValueTest method should_format_to_string.
@Test
public void should_format_to_string() {
UserDefinedType type = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("t"), DataTypes.TEXT).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).withField(CqlIdentifier.fromInternal("d"), DataTypes.DOUBLE).build();
UdtValue udt = type.newValue().setString("t", "foobar").setDouble("d", 3.14);
assertThat(udt.getFormattedContents()).isEqualTo("{t:'foobar',i:NULL,d:3.14}");
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class DefaultUdtValueTest method should_equate_instances_with_different_protocol_versions.
@Test
public void should_equate_instances_with_different_protocol_versions() {
UserDefinedType type1 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("t"), DataTypes.TEXT).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).withField(CqlIdentifier.fromInternal("d"), DataTypes.DOUBLE).build();
type1.attach(attachmentPoint);
// create an idential type, but with a different attachment point
UserDefinedType type2 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("t"), DataTypes.TEXT).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).withField(CqlIdentifier.fromInternal("d"), DataTypes.DOUBLE).build();
type2.attach(v3AttachmentPoint);
UdtValue udt1 = type1.newValue().setString("t", "some text string").setInt("i", 42).setDouble("d", 3.14);
UdtValue udt2 = type2.newValue().setString("t", "some text string").setInt("i", 42).setDouble("d", 3.14);
assertThat(udt1).isEqualTo(udt2);
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class DefaultUdtValueTest method newInstance.
@Override
protected UdtValue newInstance(List<DataType> dataTypes, AttachmentPoint attachmentPoint) {
UserDefinedTypeBuilder builder = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type"));
for (int i = 0; i < dataTypes.size(); i++) {
builder.withField(CqlIdentifier.fromInternal("field" + i), dataTypes.get(i));
}
UserDefinedType userDefinedType = builder.build();
userDefinedType.attach(attachmentPoint);
return userDefinedType.newValue();
}
use of com.datastax.oss.driver.api.core.type.UserDefinedType in project java-driver by datastax.
the class ImmutableEntityIT method setup.
@BeforeClass
public static void setup() {
CqlSession session = SESSION_RULE.session();
for (String query : createStatements(CCM_RULE)) {
session.execute(SimpleStatement.builder(query).setExecutionProfile(SESSION_RULE.slowProfile()).build());
}
UserDefinedType dimensions2d = session.getKeyspace().flatMap(ks -> session.getMetadata().getKeyspace(ks)).flatMap(ks -> ks.getUserDefinedType("dimensions2d")).orElseThrow(AssertionError::new);
session.execute("INSERT INTO product2d (id, description, dimensions) VALUES (?, ?, ?)", PRODUCT_2D_ID, "2D product", dimensions2d.newValue(12, 34));
InventoryMapper mapper = InventoryMapper.builder(session).build();
dao = mapper.immutableProductDao(SESSION_RULE.keyspace());
}
Aggregations