Search in sources :

Example 26 with CassandraMappingContext

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);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) BeforeConvertCallback(org.springframework.data.cassandra.core.mapping.event.BeforeConvertCallback) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) ReactiveEntityCallbacks(org.springframework.data.mapping.callback.ReactiveEntityCallbacks) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) Test(org.junit.jupiter.api.Test)

Example 27 with CassandraMappingContext

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);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ReactiveEntityCallbacks(org.springframework.data.mapping.callback.ReactiveEntityCallbacks) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) Test(org.junit.jupiter.api.Test)

Example 28 with CassandraMappingContext

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;
}
Also used : SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) UserTypeResolver(org.springframework.data.cassandra.core.mapping.UserTypeResolver) SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) CustomConversions(org.springframework.data.convert.CustomConversions) CassandraCustomConversions(org.springframework.data.cassandra.core.convert.CassandraCustomConversions) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Bean(org.springframework.context.annotation.Bean)

Example 29 with CassandraMappingContext

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();
}
Also used : CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CassandraMappingContext (org.springframework.data.cassandra.core.mapping.CassandraMappingContext)29 BeforeEach (org.junit.jupiter.api.BeforeEach)10 Test (org.junit.jupiter.api.Test)8 MappingCassandraConverter (org.springframework.data.cassandra.core.convert.MappingCassandraConverter)8 SimpleUserTypeResolver (org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver)5 ArrayList (java.util.ArrayList)4 Bean (org.springframework.context.annotation.Bean)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ReactiveEntityCallbacks (org.springframework.data.mapping.callback.ReactiveEntityCallbacks)3 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 Collection (java.util.Collection)2 Set (java.util.Set)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 SessionFactoryFactoryBean (org.springframework.data.cassandra.config.SessionFactoryFactoryBean)2 CassandraAdminTemplate (org.springframework.data.cassandra.core.CassandraAdminTemplate)2 SchemaFactory (org.springframework.data.cassandra.core.convert.SchemaFactory)2 CreateUserTypeSpecification (org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification)2 UserTypeResolver (org.springframework.data.cassandra.core.mapping.UserTypeResolver)2