Datastax 驱动程序映射 API
Datastax Driver Mapping API
有谁知道 Datastax 是否已经或正在计划发布 mapping/annotation 对批处理语句的支持?我喜欢新的映射和注释抽象,但还没有看到任何批处理语句。
您可以通过从注释和映射对象中获取语句并将它们添加到批处理中来完成此操作。
使用@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)' 来获取一个语句,然后将其添加到一个批处理中。
Post 来自我从中获得此信息的用户列表。
有谁知道 Datastax 是否已经或正在计划发布 mapping/annotation 对批处理语句的支持?我喜欢新的映射和注释抽象,但还没有看到任何批处理语句。
您可以通过从注释和映射对象中获取语句并将它们添加到批处理中来完成此操作。
使用@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)' 来获取一个语句,然后将其添加到一个批处理中。
Post 来自我从中获得此信息的用户列表。