Search in sources :

Example 1 with CqlTemplate

use of org.springframework.data.cassandra.core.cql.CqlTemplate in project spring-data-cassandra by spring-projects.

the class CassandraCqlTemplateFactoryBean method afterPropertiesSet.

/* (non-Javadoc)
	 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(sessionFactory, "SessionFactory must not be null");
    this.template = new CqlTemplate(sessionFactory);
}
Also used : CqlTemplate(org.springframework.data.cassandra.core.cql.CqlTemplate)

Example 2 with CqlTemplate

use of org.springframework.data.cassandra.core.cql.CqlTemplate in project spring-data-cassandra by spring-projects.

the class CassandraNamespaceIntegrationTests method keyspaceShouldBeInitialized.

// DATACASS-705
@Test
void keyspaceShouldBeInitialized() {
    CqlTemplate cqlTemplate = this.applicationContext.getBean(CqlTemplate.class);
    List<Map<String, Object>> result = cqlTemplate.queryForList("SELECT * FROM mytable1");
    assertThat(result).isEmpty();
}
Also used : CqlTemplate(org.springframework.data.cassandra.core.cql.CqlTemplate) Map(java.util.Map) AbstractSpringDataEmbeddedCassandraIntegrationTest(org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with CqlTemplate

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

use of org.springframework.data.cassandra.core.cql.CqlTemplate in project spring-data-cassandra by spring-projects.

the class CassandraNamespaceIntegrationTests method mappingContextShouldCassandraTemplateConfigured.

// DATACASS-417
@Test
void mappingContextShouldCassandraTemplateConfigured() {
    CassandraTemplate cassandraTemplate = this.applicationContext.getBean(CassandraTemplate.class);
    CqlTemplate cqlTemplate = this.applicationContext.getBean(CqlTemplate.class);
    assertThat(cassandraTemplate.getCqlOperations()).isSameAs(cqlTemplate);
}
Also used : CqlTemplate(org.springframework.data.cassandra.core.cql.CqlTemplate) CassandraTemplate(org.springframework.data.cassandra.core.CassandraTemplate) AbstractSpringDataEmbeddedCassandraIntegrationTest(org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with CqlTemplate

use of org.springframework.data.cassandra.core.cql.CqlTemplate in project stream-applications by spring-cloud.

the class CassandraAppClusterConfiguration method keyspaceCreator.

@Bean
@ConditionalOnProperty("cassandra.cluster.create-keyspace")
public Object keyspaceCreator(CassandraProperties cassandraProperties, CqlSessionBuilder cqlSessionBuilder) {
    CreateKeyspaceSpecification createKeyspaceSpecification = CreateKeyspaceSpecification.createKeyspace(cassandraProperties.getKeyspaceName()).withSimpleReplication().ifNotExists();
    String createKeySpaceQuery = new CreateKeyspaceCqlGenerator(createKeyspaceSpecification).toCql();
    CqlSession systemSession = cqlSessionBuilder.withKeyspace(CqlSessionFactoryBean.CASSANDRA_SYSTEM_SESSION).build();
    CqlTemplate template = new CqlTemplate(systemSession);
    template.execute(createKeySpaceQuery);
    return null;
}
Also used : CqlTemplate(org.springframework.data.cassandra.core.cql.CqlTemplate) CreateKeyspaceSpecification(org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CreateKeyspaceCqlGenerator(org.springframework.data.cassandra.core.cql.generator.CreateKeyspaceCqlGenerator) Bean(org.springframework.context.annotation.Bean) CqlSessionFactoryBean(org.springframework.data.cassandra.config.CqlSessionFactoryBean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

CqlTemplate (org.springframework.data.cassandra.core.cql.CqlTemplate)8 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Test (org.junit.jupiter.api.Test)3 MappingCassandraConverter (org.springframework.data.cassandra.core.convert.MappingCassandraConverter)3 AbstractSpringDataEmbeddedCassandraIntegrationTest (org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 Map (java.util.Map)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 Bean (org.springframework.context.annotation.Bean)1 CqlSessionFactoryBean (org.springframework.data.cassandra.config.CqlSessionFactoryBean)1 CassandraTemplate (org.springframework.data.cassandra.core.CassandraTemplate)1 CreateKeyspaceCqlGenerator (org.springframework.data.cassandra.core.cql.generator.CreateKeyspaceCqlGenerator)1 CreateKeyspaceSpecification (org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification)1 DefaultBridgedReactiveSession (org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession)1 SimpleUserTypeResolver (org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver)1