【问题标题】:Datastax Driver Mapping APIDatastax 驱动程序映射 API
【发布时间】:2015-01-06 01:11:04
【问题描述】:

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

【问题讨论】:

    标签: datastax-java-driver


    【解决方案1】:

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

    使用@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 来自我从中获取此信息的用户列表。

    【讨论】:

      猜你喜欢
      • 2015-09-27
      • 2016-01-02
      • 2014-10-06
      • 2020-11-23
      • 2020-11-14
      • 2016-02-27
      • 2017-01-20
      • 2017-01-26
      • 2017-03-28
      相关资源
      最近更新 更多