Search in sources :

Example 1 with SimpleUserTypeResolver

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

the class CassandraTemplate method newConverter.

private static MappingCassandraConverter newConverter(CqlSession session) {
    MappingCassandraConverter converter = new MappingCassandraConverter();
    converter.setUserTypeResolver(new SimpleUserTypeResolver(session));
    converter.setCodecRegistry(session.getContext().getCodecRegistry());
    converter.afterPropertiesSet();
    return converter;
}
Also used : SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter)

Example 2 with SimpleUserTypeResolver

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

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

the class CassandraTemplateIntegrationTests method setUp.

@BeforeEach
void setUp() {
    MappingCassandraConverter converter = new MappingCassandraConverter();
    converter.setUserTypeResolver(new SimpleUserTypeResolver(session, CqlIdentifier.fromCql(keyspace)));
    converter.afterPropertiesSet();
    cassandraVersion = CassandraVersion.get(session);
    template = new CassandraTemplate(new CqlTemplate(session), converter);
    prepareTemplate(template);
    SchemaTestUtils.potentiallyCreateTableFor(User.class, template);
    SchemaTestUtils.potentiallyCreateTableFor(UserToken.class, template);
    SchemaTestUtils.potentiallyCreateTableFor(BookReference.class, template);
    SchemaTestUtils.potentiallyCreateTableFor(TimeClass.class, template);
    SchemaTestUtils.potentiallyCreateTableFor(TypeWithCompositeKey.class, template);
    SchemaTestUtils.potentiallyCreateTableFor(WithNullableEmbeddedType.class, template);
    SchemaTestUtils.potentiallyCreateTableFor(WithEmptyEmbeddedType.class, template);
    SchemaTestUtils.potentiallyCreateTableFor(WithPrefixedNullableEmbeddedType.class, template);
    SchemaTestUtils.createTableAndTypes(OuterWithNullableEmbeddedType.class, template);
    SchemaTestUtils.createTableAndTypes(OuterWithPrefixedNullableEmbeddedType.class, template);
    SchemaTestUtils.createTableAndTypes(WithMappedUdtList.class, template);
    SchemaTestUtils.truncate(User.class, template);
    SchemaTestUtils.truncate(UserToken.class, template);
    SchemaTestUtils.truncate(BookReference.class, template);
    SchemaTestUtils.truncate(TypeWithCompositeKey.class, template);
    SchemaTestUtils.truncate(WithNullableEmbeddedType.class, template);
    SchemaTestUtils.truncate(WithEmptyEmbeddedType.class, template);
    SchemaTestUtils.truncate(WithPrefixedNullableEmbeddedType.class, template);
    SchemaTestUtils.truncate(OuterWithNullableEmbeddedType.class, template);
    SchemaTestUtils.truncate(OuterWithPrefixedNullableEmbeddedType.class, template);
    SchemaTestUtils.truncate(WithMappedUdtList.class, template);
}
Also used : CqlTemplate(org.springframework.data.cassandra.core.cql.CqlTemplate) SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with SimpleUserTypeResolver

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

the class CassandraTemplateProducer method createCassandraOperations.

@Produces
@ApplicationScoped
public CassandraOperations createCassandraOperations(CqlSession session) throws Exception {
    CassandraMappingContext mappingContext = new CassandraMappingContext();
    mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(session));
    mappingContext.afterPropertiesSet();
    MappingCassandraConverter cassandraConverter = new MappingCassandraConverter(mappingContext);
    cassandraConverter.afterPropertiesSet();
    return new CassandraAdminTemplate(session, cassandraConverter);
}
Also used : CassandraAdminTemplate(org.springframework.data.cassandra.core.CassandraAdminTemplate) SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) CassandraMappingContext(org.springframework.data.cassandra.core.mapping.CassandraMappingContext) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 5 with SimpleUserTypeResolver

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

the class CassandraDataAutoConfiguration method cassandraConverter.

@Bean
@ConditionalOnMissingBean
public CassandraConverter cassandraConverter(CassandraMappingContext mapping, CassandraCustomConversions conversions) {
    MappingCassandraConverter converter = new MappingCassandraConverter(mapping);
    converter.setCodecRegistry(this.session.getContext().getCodecRegistry());
    converter.setCustomConversions(conversions);
    converter.setUserTypeResolver(new SimpleUserTypeResolver(this.session));
    return converter;
}
Also used : SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) SessionFactoryFactoryBean(org.springframework.data.cassandra.config.SessionFactoryFactoryBean)

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