Datastax Driver Mapping API

时间:2015-01-06 01:11:05

标签: datastax-java-driver

有人知道Datastax是否已经或正在计划发布批处理语句的映射/注释支持?我很喜欢新的地图和注释抽象,但没有看到任何批处理语句。

1 个答案:

答案 0 :(得分:6)

您可以通过从中获取语句并将其添加到批处理来为注释和映射对象完成此操作。

使用@Accessor注释,您可以从Accessor获取语句,然后将其添加到批处理

以下是unit tests的示例。 PostAccessor.updateCountQuery是@Accessor带注释的接口中定义的语句:

@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