use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class SchemaTestUtils method createTableAndTypes.
/**
* Create a table and UDTs for {@code entityClass} if it not exists.
*
* @param entityClass must not be {@literal null}.
* @param operations must not be {@literal null}.
*/
public static void createTableAndTypes(Class<?> entityClass, CassandraOperations operations) {
CassandraMappingContext mappingContext = operations.getConverter().getMappingContext();
CassandraPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entityClass);
SchemaFactory schemaFactory = new SchemaFactory(operations.getConverter());
potentiallyCreateUdtFor(persistentEntity, operations, schemaFactory);
potentiallyCreateTableFor(persistentEntity, operations, schemaFactory);
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-boot by spring-projects.
the class CassandraDataAutoConfigurationTests method entityScanShouldSetInitialEntitySet.
@Test
@SuppressWarnings("unchecked")
void entityScanShouldSetInitialEntitySet() {
load(EntityScanConfig.class);
CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class);
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet");
assertThat(initialEntitySet).containsOnly(City.class);
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-boot by spring-projects.
the class CassandraReactiveDataAutoConfigurationTests method entityScanShouldSetInitialEntitySet.
@Test
@SuppressWarnings("unchecked")
void entityScanShouldSetInitialEntitySet() {
load(EntityScanConfig.class, "spring.data.cassandra.keyspaceName:boot_test");
CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class);
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet");
assertThat(initialEntitySet).containsOnly(City.class);
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-boot by spring-projects.
the class CassandraDataAutoConfiguration method cassandraMapping.
@Bean
@ConditionalOnMissingBean
public CassandraMappingContext cassandraMapping(BeanFactory beanFactory, CassandraCustomConversions conversions) throws ClassNotFoundException {
CassandraMappingContext context = new CassandraMappingContext();
List<String> packages = EntityScanPackages.get(beanFactory).getPackageNames();
if (packages.isEmpty() && AutoConfigurationPackages.has(beanFactory)) {
packages = AutoConfigurationPackages.get(beanFactory);
}
if (!packages.isEmpty()) {
context.setInitialEntitySet(CassandraEntityClassScanner.scan(packages));
}
context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
return context;
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class CassandraPersistentEntitySchemaCreatorUnitTests method shouldConsiderProperUdtOrdering.
// DATACASS-687
@Test
void shouldConsiderProperUdtOrdering() {
List<Class<?>> ordered = new ArrayList<>(Arrays.asList(Udt2.class, Udt1.class, RequiredByAll.class));
context = new CassandraMappingContext() {
@Override
public Collection<CassandraPersistentEntity<?>> getUserDefinedTypeEntities() {
return ordered.stream().map(this::getRequiredPersistentEntity).collect(Collectors.toList());
}
};
context.setUserTypeResolver(typeName -> {
// to be created user types isn't a good idea because they do not exist at resolution time.
throw new IllegalArgumentException(String.format("Type %s not found", typeName));
});
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(context, adminOperations);
List<CreateUserTypeSpecification> userTypeSpecifications = schemaCreator.createUserTypeSpecifications(false);
List<CqlIdentifier> collect = userTypeSpecifications.stream().map(UserTypeNameSpecification::getName).collect(Collectors.toList());
assertThat(collect).hasSize(3).startsWith(CqlIdentifier.fromCql("requiredbyall"));
}
Aggregations