Search in sources :

Example 1 with UserTypeResolver

use of org.springframework.data.cassandra.core.mapping.UserTypeResolver in project spring-data-cassandra by spring-projects.

the class AbstractCassandraConfiguration method cassandraConverter.

/**
 * Creates a {@link CassandraConverter} using the configured {@link #cassandraMapping()}.
 *
 * Will apply all specified {@link #customConversions()}.
 *
 * @return {@link CassandraConverter} used to convert Java and Cassandra value types during the mapping process.
 * @see #cassandraMapping()
 * @see #customConversions()
 */
@Bean
public CassandraConverter cassandraConverter() {
    CqlSession cqlSession = getRequiredSession();
    UserTypeResolver userTypeResolver = new SimpleUserTypeResolver(cqlSession, CqlIdentifier.fromCql(getKeyspaceName()));
    MappingCassandraConverter converter = new MappingCassandraConverter(requireBeanOfType(CassandraMappingContext.class));
    converter.setCodecRegistry(cqlSession.getContext().getCodecRegistry());
    converter.setUserTypeResolver(userTypeResolver);
    converter.setCustomConversions(requireBeanOfType(CassandraCustomConversions.class));
    return converter;
}
Also used : CassandraCustomConversions(org.springframework.data.cassandra.core.convert.CassandraCustomConversions) SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) UserTypeResolver(org.springframework.data.cassandra.core.mapping.UserTypeResolver) SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) CqlSession(com.datastax.oss.driver.api.core.CqlSession) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) Bean(org.springframework.context.annotation.Bean)

Example 2 with UserTypeResolver

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

CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 Bean (org.springframework.context.annotation.Bean)2 CassandraCustomConversions (org.springframework.data.cassandra.core.convert.CassandraCustomConversions)2 CassandraMappingContext (org.springframework.data.cassandra.core.mapping.CassandraMappingContext)2 SimpleUserTypeResolver (org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver)2 UserTypeResolver (org.springframework.data.cassandra.core.mapping.UserTypeResolver)2 MappingCassandraConverter (org.springframework.data.cassandra.core.convert.MappingCassandraConverter)1 CustomConversions (org.springframework.data.convert.CustomConversions)1