首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查Spring Data Cassandra Mapper生成的查询字符串

问如何检查Spring Data Cassandra Mapper生成的查询字符串
EN

Stack Overflow用户
提问于 2017-07-21 20:59:42
回答 1查看 472关注 0票数 1

如果我用来自com.datastax.driver.mapping.annotations的注解来注释一个类,我可以像下面这样写一个测试:

代码语言:javascript
复制
MappingManager manager = new MappingManager(session);
Mapper<MyAnnotatedClass> mapper = manager.mapper(MyAnnotatedClass.class);

MyAnnotatedClass entity = ...;

RegularStatement saveQuery = (RegularStatement) mapper.saveQuery(entity);

assertEquals("...", saveQuery.getQueryString());

但是,我有用org.springframework.data.cassandra.mapping注解的实体类。我一直找不到一个与Mapper的saveQuery()、getQuery()和deleteQuery()相当的Spring。

如何编写关于从Spring Data Cassandra注释的实体类生成的CQL的测试(理想情况下在运行时是轻量级的)?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-21 21:24:17

使用Spring Data for Apache Cassandra 1.5,您可以编写以下代码来创建Statement:

代码语言:javascript
复制
CassandraTemplate template = …

Person person = …

CqlIdentifier tableName = template.getTableName(Person.class);

Insert insert = CassandraTemplate.createInsertQuery(tableName.toCql(), person, 
                    new WriteOptions(), template.getConverter());

Delete delete = CassandraTemplate.createDeleteQuery(tableName.toCql(), person,
                    new WriteOptions(), template.getConverter());

Update update = CassandraTemplate.createUpdateQuery(tableName.toCql(), person, 
                    new WriteOptions(), template.getConverter());

注意: Apache Cassandra 1.5的Spring数据使用BATCH语句进行插入,这将随着2.0版的发布而改变。

CassandraTemplate和CassandraConverter是创建1.5版查询所涉及的关键类。在Spring data2.0中,事情将发生一些变化,因为2.0将为部分实体更新提供额外的Query和Update类型。因此,查询创建从CassandraTemplate.create…Query(…)转移到QueryUtils.create…Query(…)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45238351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档