Exemplo n.º 1
0
  @Test
  public void should_set_lazy_field() throws Exception {
    bean = em.find(CompleteBean.class, bean.getId());

    bean.setLabel("newLabel");

    assertThat(bean.getLabel()).isEqualTo("newLabel");
  }
Exemplo n.º 2
0
  @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);
  }