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