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);
}
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();
}
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);
}
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);
}
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;
}
Aggregations