gor*_*ysc 2 datastax-java-driver
有没有人知道Datastax是否已经或正计划发布批处理语句的映射/注释支持?我喜欢新的映射和注释抽象,但没有看到任何批处理语句.
您可以通过从它们获取语句并将它们添加到批处理来为注释和映射对象完成此操作.
使用@Accessor注释,您可以从Accessor获取语句,然后将其添加到批处理中
这是单元测试的一个例子.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);
}
Run Code Online (Sandbox Code Playgroud)
然后可以按以下方式生成和使用该语句:
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);
Run Code Online (Sandbox Code Playgroud)
对于具有Crud操作的Pojos,您可以简单地调用'mapper.saveQuery(entity)'来获取Statement,然后将其添加到批处理中.
从我从中获取此信息的用户列表发布.
| 归档时间: |
|
| 查看次数: |
1738 次 |
| 最近记录: |