use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class AbstractAuditingTests method enablesAuditingAndSetsPropertiesAccordingly.
// DATACASS-4
@Test
void enablesAuditingAndSetsPropertiesAccordingly() throws Exception {
ApplicationContext context = getApplicationContext();
CassandraMappingContext mappingContext = context.getBean(CassandraMappingContext.class);
mappingContext.getPersistentEntity(Entity.class);
EntityCallbacks callbacks = EntityCallbacks.create(context);
Entity entity = new Entity();
entity = callbacks.callback(BeforeConvertCallback.class, entity, CqlIdentifier.fromCql("entity"));
assertThat(entity.created).isNotNull();
assertThat(entity.modified).isEqualTo(entity.created);
Thread.sleep(10);
entity.id = 1L;
entity = callbacks.callback(BeforeConvertCallback.class, entity, CqlIdentifier.fromCql("entity"));
assertThat(entity.created).isNotNull();
assertThat(entity.modified).isAfter(entity.created);
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class AbstractAuditingTests method enablesReactiveAuditingAndSetsPropertiesAccordingly.
// DATACASS-4
@Test
void enablesReactiveAuditingAndSetsPropertiesAccordingly() throws Exception {
ApplicationContext context = getApplicationContext();
CassandraMappingContext mappingContext = context.getBean(CassandraMappingContext.class);
mappingContext.getPersistentEntity(Entity.class);
ReactiveEntityCallbacks callbacks = ReactiveEntityCallbacks.create(context);
Entity entity = new Entity();
entity = callbacks.callback(BeforeConvertCallback.class, entity, CqlIdentifier.fromCql("entity")).block();
assertThat(entity.created).isNotNull();
assertThat(entity.modified).isEqualTo(entity.created);
Thread.sleep(10);
entity.id = 1L;
entity = callbacks.callback(BeforeConvertCallback.class, entity, CqlIdentifier.fromCql("entity")).block();
assertThat(entity.created).isNotNull();
assertThat(entity.modified).isAfter(entity.created);
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class AbstractCassandraConfiguration method cassandraMapping.
/**
* Return the {@link MappingContext} instance to map Entities to {@link Object Java Objects}.
*
* @throws ClassNotFoundException if the Cassandra Entity class type identified by name
* cannot be found during the scan.
* @see org.springframework.data.cassandra.core.mapping.CassandraMappingContext
*/
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
CqlSession cqlSession = getRequiredSession();
UserTypeResolver userTypeResolver = new SimpleUserTypeResolver(cqlSession, CqlIdentifier.fromCql(getKeyspaceName()));
CassandraMappingContext mappingContext = new CassandraMappingContext(userTypeResolver, SimpleTupleTypeFactory.DEFAULT);
CustomConversions customConversions = requireBeanOfType(CassandraCustomConversions.class);
getBeanClassLoader().ifPresent(mappingContext::setBeanClassLoader);
mappingContext.setCodecRegistry(cqlSession.getContext().getCodecRegistry());
mappingContext.setCustomConversions(customConversions);
mappingContext.setInitialEntitySet(getInitialEntitySet());
mappingContext.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
return mappingContext;
}
use of org.springframework.data.cassandra.core.mapping.CassandraMappingContext in project spring-data-cassandra by spring-projects.
the class MappingCassandraConverterMappedTupleUnitTests method setUp.
@BeforeEach
void setUp() {
this.mappingContext = new CassandraMappingContext();
this.mappingCassandraConverter = new MappingCassandraConverter(mappingContext);
this.mappingCassandraConverter.afterPropertiesSet();
}
Aggregations