[英]How can I examine the query string generated by Spring Data Cassandra Mapper
If I annotate a class with annotations from com.datastax.driver.mapping.annotations
, I can write a test along the lines of: 如果我使用
com.datastax.driver.mapping.annotations
注释注释类,我可以按以下方式编写测试:
MappingManager manager = new MappingManager(session);
Mapper<MyAnnotatedClass> mapper = manager.mapper(MyAnnotatedClass.class);
MyAnnotatedClass entity = ...;
RegularStatement saveQuery = (RegularStatement) mapper.saveQuery(entity);
assertEquals("...", saveQuery.getQueryString());
However I have entity classes annotated with org.springframework.data.cassandra.mapping
annotations. 但是,我有使用
org.springframework.data.cassandra.mapping
注释注释的实体类。 I've been unable to find an Spring equivalent to Mapper
's saveQuery()
, getQuery()
and deleteQuery()
. 我一直无法找到一个与
Mapper
的saveQuery()
, getQuery()
和deleteQuery()
相当的Spring。
How can I write (ideally lightweight at runtime) tests regarding the CQL generated from Spring Data Cassandra-annotated entity classes? 如何编写(在运行时理想的轻量级)测试有关从Spring Data Cassandra注释的实体类生成的CQL?
With Spring Data for Apache Cassandra 1.5, you can write the following code to create Statement
s: 使用Spring Data for Apache Cassandra 1.5,您可以编写以下代码来创建
Statement
:
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());
Note: Spring Data for Apache Cassandra 1.5 uses BATCH
statements for inserts, that's going to change with the release 2.0. 注意:Apache Cassandra 1.5的Spring Data使用
BATCH
语句进行插入,随着2.0版的发布而改变。
CassandraTemplate
and CassandraConverter
are the key classes involved in query creation for version 1.5. CassandraTemplate
和CassandraConverter
是1.5版查询创建中涉及的关键类。 In Spring Data 2.0, things are going to change a bit as 2.0 is going to ship with additional Query
and Update
types for partial entity updates. 在Spring Data 2.0中,事情会发生一些变化,因为2.0将为部分实体更新提供额外的
Query
和Update
类型。 So query creation moves from CassandraTemplate.create…Query(…)
to QueryUtils.create…Query(…)
. 因此,查询创建从
CassandraTemplate.create…Query(…)
到QueryUtils.create…Query(…)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.