コード例 #1
0
ファイル: BatchModeIT.java プロジェクト: nnguyen07/Achilles
  @Test
  public void should_batch_counters() throws Exception {
    // Start batch
    CQLBatchingEntityManager batchEm = emf.createBatchingEntityManager();
    batchEm.startBatch();

    CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").buid();

    entity = batchEm.merge(entity);

    entity.setLabel("label");

    Tweet welcomeTweet = TweetTestBuilder.tweet().randomId().content("welcomeTweet").buid();
    entity.setWelcomeTweet(welcomeTweet);

    entity.getVersion().incr(10L);
    batchEm.merge(entity);

    Row result = session.execute("SELECT label from CompleteBean where id=" + entity.getId()).one();
    assertThat(result).isNull();

    result =
        session
            .execute(
                "SELECT counter_value from achilles_counter_table where fqcn='"
                    + CompleteBean.class.getCanonicalName()
                    + "' and primary_key='"
                    + entity.getId()
                    + "' and property_name='version'")
            .one();
    assertThat(result.getLong("counter_value")).isEqualTo(10L);

    // Flush
    batchEm.endBatch();

    result = session.execute("SELECT label from CompleteBean where id=" + entity.getId()).one();
    assertThat(result.getString("label")).isEqualTo("label");

    result =
        session
            .execute(
                "SELECT counter_value from achilles_counter_table where fqcn='"
                    + CompleteBean.class.getCanonicalName()
                    + "' and primary_key='"
                    + entity.getId()
                    + "' and property_name='version'")
            .one();
    assertThat(result.getLong("counter_value")).isEqualTo(10L);
    assertThatBatchContextHasBeenReset(batchEm);
  }
コード例 #2
0
ファイル: BatchModeIT.java プロジェクト: nnguyen07/Achilles
  @Test
  public void should_batch_several_entities() throws Exception {
    CompleteBean bean = CompleteBeanTestBuilder.builder().randomId().name("name").buid();
    Tweet tweet1 = TweetTestBuilder.tweet().randomId().content("tweet1").buid();
    Tweet tweet2 = TweetTestBuilder.tweet().randomId().content("tweet2").buid();

    // Start batch
    CQLBatchingEntityManager batchEm = emf.createBatchingEntityManager();
    batchEm.startBatch();

    batchEm.merge(bean);
    batchEm.merge(tweet1);
    batchEm.merge(tweet2);
    batchEm.merge(user);

    CompleteBean foundBean = batchEm.find(CompleteBean.class, bean.getId());
    Tweet foundTweet1 = batchEm.find(Tweet.class, tweet1.getId());
    Tweet foundTweet2 = batchEm.find(Tweet.class, tweet2.getId());
    User foundUser = batchEm.find(User.class, user.getId());

    assertThat(foundBean).isNull();
    assertThat(foundTweet1).isNull();
    assertThat(foundTweet2).isNull();
    assertThat(foundUser).isNull();

    // Flush
    batchEm.endBatch();

    foundBean = batchEm.find(CompleteBean.class, bean.getId());
    foundTweet1 = batchEm.find(Tweet.class, tweet1.getId());
    foundTweet2 = batchEm.find(Tweet.class, tweet2.getId());
    foundUser = batchEm.find(User.class, user.getId());

    assertThat(foundBean.getName()).isEqualTo("name");
    assertThat(foundTweet1.getContent()).isEqualTo("tweet1");
    assertThat(foundTweet2.getContent()).isEqualTo("tweet2");
    assertThat(foundUser.getFirstname()).isEqualTo("fn");
    assertThat(foundUser.getLastname()).isEqualTo("ln");
    assertThatBatchContextHasBeenReset(batchEm);
  }