use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class MultipackageScanningUnitTests method before.
@BeforeEach
void before() throws ClassNotFoundException {
CassandraMappingContext context = new CassandraMappingContext();
context.setInitialEntitySet(CassandraEntityClassScanner.scan(pkg + ".first", pkg + ".second"));
context.initialize();
this.context = context;
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class CassandraConfig method mappingContext.
@Bean
public CassandraMappingContext mappingContext(CqlSession cqlSession) {
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(cqlSession));
return mappingContext;
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class NamingStrategyConfiguration method configurationMethod.
public void configurationMethod() {
// tag::method[]
CassandraMappingContext context = new CassandraMappingContext();
// default naming strategy
context.setNamingStrategy(NamingStrategy.INSTANCE);
// snake_case converted to upper case (SNAKE_CASE)
context.setNamingStrategy(NamingStrategy.SNAKE_CASE.transform(String::toUpperCase));
// end::method[]
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class CassandraOperationsProducer method createCassandraOperations.
@Produces
@ApplicationScoped
public CassandraOperations createCassandraOperations(CqlSession session) throws Exception {
CassandraMappingContext mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(session, CqlIdentifier.fromCql(KEYSPACE_NAME)));
mappingContext.setInitialEntitySet(Collections.singleton(User.class));
mappingContext.afterPropertiesSet();
MappingCassandraConverter cassandraConverter = new MappingCassandraConverter(mappingContext);
CassandraAdminTemplate cassandraTemplate = new CassandraAdminTemplate(session, cassandraConverter);
CreateKeyspaceSpecification createKeyspaceSpecification = CreateKeyspaceSpecification.createKeyspace(KEYSPACE_NAME).ifNotExists();
cassandraTemplate.getCqlOperations().execute(CreateKeyspaceCqlGenerator.toCql(createKeyspaceSpecification));
cassandraTemplate.getCqlOperations().execute("USE " + KEYSPACE_NAME);
CassandraPersistentEntitySchemaDropper schemaDropper = new CassandraPersistentEntitySchemaDropper(mappingContext, cassandraTemplate);
schemaDropper.dropTables(false);
schemaDropper.dropUserTypes(false);
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(mappingContext, cassandraTemplate);
schemaCreator.createUserTypes(false);
schemaCreator.createTables(false);
for (CassandraPersistentEntity<?> entity : cassandraTemplate.getConverter().getMappingContext().getTableEntities()) {
cassandraTemplate.truncate(entity.getType());
}
return cassandraTemplate;
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class CassandraNamespaceIntegrationTests method mappingContextShouldHaveUserTypeResolverConfigured.
// DATACASS-172
@Test
void mappingContextShouldHaveUserTypeResolverConfigured() {
CassandraMappingContext mappingContext = this.applicationContext.getBean(CassandraMappingContext.class);
SimpleUserTypeResolver userTypeResolver = (SimpleUserTypeResolver) ReflectionTestUtils.getField(mappingContext, "userTypeResolver");
assertThat(userTypeResolver).isNotNull();
}
Aggregations