Search in sources :

Example 1 with CassandraTemplate

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

the class CustomConversionIntegrationTests method shouldApplyCustomReadConverterIfOnlyReadIsCustomized.

// DATACASS-607
@Test
void shouldApplyCustomReadConverterIfOnlyReadIsCustomized() {
    MappingCassandraConverter converter = createConverter(converters -> {
        converters.add(new PersonReadConverter());
    });
    cassandraOperations = new CassandraTemplate(session, converter);
    cassandraOperations.getCqlOperations().execute("INSERT INTO employee (id, people) VALUES('employee-id', {'{\"firstname\":\"Apu\",\"lastname\":\"Nahasapeemapetilon\"}'})");
    Employee employee = cassandraOperations.selectOne("SELECT id, people FROM employee", Employee.class);
    assertThat(employee.getId()).isEqualTo("employee-id");
    assertThat(employee.getPeople()).isNotNull().hasSize(1);
    assertThat(employee.getPeople()).extracting(Person::getFirstname).contains("Apu");
}
Also used : CassandraTemplate(org.springframework.data.cassandra.core.CassandraTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with CassandraTemplate

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

the class CompositeKeyCrudIntegrationTests method setUp.

@BeforeEach
void setUp() {
    operations = new CassandraTemplate(session);
    SchemaTestUtils.potentiallyCreateTableFor(CorrelationEntity.class, operations);
    SchemaTestUtils.truncate(CorrelationEntity.class, operations);
    Map<String, String> map1 = new HashMap<>(2);
    map1.put("v", "1");
    map1.put("labels", "1,2,3");
    Map<String, String> map2 = new HashMap<>(2);
    map2.put("v", "1");
    map2.put("labels", "4,5,6");
    correlationEntity1 = new CorrelationEntity("a", "b", "c", new Date(1), "d", map1);
    correlationEntity2 = new CorrelationEntity("a", "b", "c", new Date(2), "e", map2);
}
Also used : HashMap(java.util.HashMap) CassandraTemplate(org.springframework.data.cassandra.core.CassandraTemplate) CorrelationEntity(org.springframework.data.cassandra.repository.forcequote.compositeprimarykey.entity.CorrelationEntity) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CassandraTemplate

use of org.springframework.data.cassandra.core.CassandraTemplate 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 4 with CassandraTemplate

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

the class CassandraApplication method main.

public static void main(String[] args) {
    CqlSession cqlSession = CqlSession.builder().withKeyspace("mykeyspace").build();
    CassandraOperations template = new CassandraTemplate(cqlSession);
    Person jonDoe = template.insert(newPerson("Jon Doe", 40));
    LOG.info(template.selectOne(Query.query(Criteria.where("id").is(jonDoe.getId())), Person.class).getId());
    template.truncate(Person.class);
    cqlSession.close();
}
Also used : CassandraOperations(org.springframework.data.cassandra.core.CassandraOperations) CassandraTemplate(org.springframework.data.cassandra.core.CassandraTemplate) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 5 with CassandraTemplate

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

the class CassandraDataAutoConfigurationTests method defaultConversions.

@Test
void defaultConversions() {
    load();
    CassandraTemplate template = this.context.getBean(CassandraTemplate.class);
    assertThat(template.getConverter().getConversionService().canConvert(Person.class, String.class)).isFalse();
}
Also used : CassandraTemplate(org.springframework.data.cassandra.core.CassandraTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

CassandraTemplate (org.springframework.data.cassandra.core.CassandraTemplate)12 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Test (org.junit.jupiter.api.Test)4 User (org.springframework.data.cassandra.domain.User)3 TypeWithMapId (org.springframework.data.cassandra.domain.TypeWithMapId)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 CassandraOperations (org.springframework.data.cassandra.core.CassandraOperations)1 ReactiveCassandraTemplate (org.springframework.data.cassandra.core.ReactiveCassandraTemplate)1 CqlTemplate (org.springframework.data.cassandra.core.cql.CqlTemplate)1 DefaultBridgedReactiveSession (org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession)1 CorrelationEntity (org.springframework.data.cassandra.repository.forcequote.compositeprimarykey.entity.CorrelationEntity)1 AbstractSpringDataEmbeddedCassandraIntegrationTest (org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest)1