【发布时间】:2015-01-06 01:11:04
【问题描述】:
有谁知道 Datastax 是否已经或计划发布对批处理语句的映射/注释支持?我喜欢新的映射和注释抽象,但还没有看到任何批处理语句。
【问题讨论】:
有谁知道 Datastax 是否已经或计划发布对批处理语句的映射/注释支持?我喜欢新的映射和注释抽象,但还没有看到任何批处理语句。
【问题讨论】:
您可以通过从注释和映射对象中获取语句并将它们添加到批处理中来完成此操作。
使用@Accessor 注释,您可以从访问器中获取语句,然后将其添加到批处理中
这是来自unit tests 的示例。 PostAccessor.updateCountQuery 是 @Accessor 注解接口中定义的 Statement:
@Accessor
public interface PostAccessor {
@Query("UPDATE ks.posts SET content=? WHERE user_id=? AND post_id=?")
public Statement updateContentQuery(String newContent, UUID userId, UUID postId);
}
然后可以生成该语句并在following way中使用:
BatchStatement batch = new BatchStatement();
batch.add(postAccessor.updateContentQuery("Something different", p1.getUserId(), p1.getPostId()));
batch.add(postAccessor.updateContentQuery("A different something", p2.getUserId(), p2.getPostId()));
manager.getSession().execute(batch);
对于带有 Crud 操作的 Pojos,您只需调用 'mapper.saveQuery(entity)' 以获取 Statement,然后将其添加到批处理中。
Post 来自我从中获取此信息的用户列表。
【讨论】: