use of org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification in project spring-data-cassandra by spring-projects.
the class MappingCassandraConverterTupleIntegrationTests method setUp.
@BeforeEach
void setUp() {
if (initialized.compareAndSet(false, true)) {
this.session.execute("DROP TYPE IF EXISTS address;");
this.session.execute("DROP TABLE IF EXISTS person;");
CassandraMappingContext mappingContext = converter.getMappingContext();
SchemaFactory schemaFactory = new SchemaFactory(converter);
CreateUserTypeSpecification createAddress = schemaFactory.getCreateUserTypeSpecificationFor(mappingContext.getRequiredPersistentEntity(AddressUserType.class));
this.session.execute(CreateUserTypeCqlGenerator.toCql(createAddress));
String ddl = //
"CREATE TABLE person (id text, " + "tuplevalue tuple<text,int>," + //
"mapoftuples map<text, frozen<tuple<address, list<text>, text>>>, " + //
"mapoftuplevalues map<text, frozen<tuple<text, int>>>, " + //
"mappedtuple frozen<tuple<address, list<text>, text>>, " + //
"mappedtuplewithvalue frozen<tuple<address, list<text>, text>>, " + //
"mappedtuples list<frozen<tuple<address, list<text>, text>>>, " + "PRIMARY KEY (id));";
this.session.execute(ddl);
} else {
this.session.execute("TRUNCATE person;");
}
}
use of org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification in project spring-data-cassandra by spring-projects.
the class CreateUserTypeCqlGeneratorIntegrationTests method createUserTypeIfNotExists.
// DATACASS-172
@Test
void createUserTypeIfNotExists() {
CreateUserTypeSpecification spec = //
CreateUserTypeSpecification.createType("address").ifNotExists().field("zip", //
DataTypes.ASCII).field("city", DataTypes.TEXT);
session.execute(toCql(spec));
KeyspaceMetadata keyspace = session.getMetadata().getKeyspace(session.getKeyspace().get()).get();
UserDefinedType address = keyspace.getUserDefinedType("address").get();
assertThat(address.getFieldNames()).contains(CqlIdentifier.fromCql("zip"), CqlIdentifier.fromCql("city"));
}
use of org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification in project spring-data-cassandra by spring-projects.
the class CreateUserTypeCqlGeneratorIntegrationTests method createNestedUserType.
// DATACASS-172, DATACASS-424
@Test
void createNestedUserType() {
CreateUserTypeSpecification addressSpec = //
CreateUserTypeSpecification.createType("address").ifNotExists().field("zip", //
DataTypes.ASCII).field("city", DataTypes.TEXT);
session.execute(toCql(addressSpec));
KeyspaceMetadata keyspace = session.getMetadata().getKeyspace(session.getKeyspace().get()).get();
UserDefinedType address = keyspace.getUserDefinedType("address").get();
CreateUserTypeSpecification personSpec = //
CreateUserTypeSpecification.createType("person").ifNotExists().field("address", //
address.copy(true)).field("city", DataTypes.TEXT);
session.execute(toCql(personSpec));
}
use of org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification in project spring-data-cassandra by spring-projects.
the class CreateUserTypeCqlGeneratorUnitTests method createMultiFieldUserType.
// DATACASS-172
@Test
void createMultiFieldUserType() {
CreateUserTypeSpecification spec = //
CreateUserTypeSpecification.createType(//
"address").field("zip", //
DataTypes.ASCII).field("city", DataTypes.TEXT);
assertThat(toCql(spec)).isEqualTo("CREATE TYPE address (zip ascii, city text);");
}
use of org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification in project spring-data-cassandra by spring-projects.
the class SchemaTestUtils method potentiallyCreateUdtFor.
private static void potentiallyCreateUdtFor(CassandraPersistentEntity<?> persistentEntity, CassandraOperations operations, SchemaFactory schemaFactory) {
if (persistentEntity.isUserDefinedType()) {
CreateUserTypeSpecification udtspec = schemaFactory.getCreateUserTypeSpecificationFor(persistentEntity).ifNotExists();
operations.getCqlOperations().execute(CreateUserTypeCqlGenerator.toCql(udtspec));
} else {
for (CassandraPersistentProperty property : persistentEntity) {
if (!property.isEntity()) {
continue;
}
if (property.isEmbedded()) {
potentiallyCreateUdtFor(new EmbeddedEntityOperations(operations.getConverter().getMappingContext()).getEntity(property), operations, schemaFactory);
} else {
potentiallyCreateUdtFor(operations.getConverter().getMappingContext().getRequiredPersistentEntity(property), operations, schemaFactory);
}
}
}
}
Aggregations