Search in sources :

Example 11 with SimpleUserTypeResolver

use of org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver 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)

Aggregations

SimpleUserTypeResolver (org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver)11 MappingCassandraConverter (org.springframework.data.cassandra.core.convert.MappingCassandraConverter)8 CassandraMappingContext (org.springframework.data.cassandra.core.mapping.CassandraMappingContext)6 Bean (org.springframework.context.annotation.Bean)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)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 CassandraCustomConversions (org.springframework.data.cassandra.core.convert.CassandraCustomConversions)2 UserTypeResolver (org.springframework.data.cassandra.core.mapping.UserTypeResolver)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 CqlSessionFactoryBean (org.springframework.data.cassandra.config.CqlSessionFactoryBean)1 CassandraPersistentEntitySchemaCreator (org.springframework.data.cassandra.core.CassandraPersistentEntitySchemaCreator)1 CassandraPersistentEntitySchemaDropper (org.springframework.data.cassandra.core.CassandraPersistentEntitySchemaDropper)1 CqlTemplate (org.springframework.data.cassandra.core.cql.CqlTemplate)1 CreateKeyspaceSpecification (org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification)1