Package info.archinnov.achilles.persistence

Examples of info.archinnov.achilles.persistence.Batch


    }

    @Test
    public void should_apply_interceptors_after_flush_for_batch() throws Exception {
        // Given
        final Batch batchingPM = pmf.createBatch();
        batchingPM.startBatch();

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

        // When
        batchingPM.insert(entity);

        // Then
        assertThat(entity.getName()).isEqualTo("DuyHai");
        assertThat(entity.getLabel()).isEqualTo("label");

        // When
        batchingPM.endBatch();

        // Then
        assertThat(entity.getName()).isEqualTo("prePersist");
        assertThat(entity.getLabel()).isEqualTo("postPersist : label");
    }
View Full Code Here


        entity.setId(id);
        entity.setName("name");

        final EntityWithConsistencyLevelOnClassAndField managed = manager.insert(entity);

        Batch batch = pmf.createBatch();
        batch.startBatch(ONE);
        managed.setName("changed_name");
        logAsserter.prepareLogLevel();

        batch.update(managed);

        batch.endBatch();
        logAsserter.assertConsistencyLevels(ONE);
        assertThatBatchContextHasBeenReset(batch);

        entity = manager.find(EntityWithConsistencyLevelOnClassAndField.class, entity.getId(), ONE);
        assertThat(entity.getName()).isEqualTo("changed_name");
View Full Code Here

        EntityWithConsistencyLevelOnClassAndField entity = new EntityWithConsistencyLevelOnClassAndField();
        entity.setId(RandomUtils.nextLong(0,Long.MAX_VALUE));
        entity.setName("name");
        entity.setCount(CounterBuilder.incr());

        Batch batchEm = pmf.createBatch();
        batchEm.startBatch(THREE);
        entity = batchEm.insert(entity);

        expectedEx.expect(UnavailableException.class);
        expectedEx.expectMessage("Not enough replica available for query at consistency THREE (3 required but only 1 alive)");

        entity.getCount();
View Full Code Here

        Tweet tweet3 = TweetTestBuilder.tweet().randomId().content("simple_tweet3").buid();

        manager.insert(tweet1);

        // Start batch
        Batch batch = manager.createBatch();
        batch.startBatch();

        batch.startBatch(QUORUM);

        Tweet foundTweet1 = manager.find(Tweet.class, tweet1.getId());

        assertThat(foundTweet1.getContent()).isEqualTo(tweet1.getContent());

        batch.insert(tweet2);
        batch.insert(tweet3);

        logAsserter.prepareLogLevel();

        batch.endBatch();

        logAsserter.assertConsistencyLevels(QUORUM);
        assertThatBatchContextHasBeenReset(batch);
    }
View Full Code Here

        Tweet tweet2 = TweetTestBuilder.tweet().randomId().content("simple_tweet2").buid();

        manager.insert(tweet1);

        // Start batch
        Batch batch = manager.createBatch();
        batch.startBatch();

        batch.startBatch(TWO);
        batch.insertOrUpdate(tweet2);

        try {
            batch.endBatch();
        } catch (Exception e) {
            assertThatBatchContextHasBeenReset(batch);
            exceptionCaught = true;
        }

        assertThat(exceptionCaught).isTrue();

        Thread.sleep(1000);
        logAsserter.prepareLogLevel();
        batch.insert(tweet2);
        batch.endBatch();
        logAsserter.assertConsistencyLevels(ONE);
    }
View Full Code Here

    @Test
    public void should_order_batch_operations_on_the_same_column_with_insert_and_update() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").buid();
        final Batch batch = manager.createOrderedBatch();

        //When
        batch.startBatch();

        entity = batch.insert(entity);
        entity.setLabel("label");
        batch.update(entity);

        batch.endBatch();

        //Then
        Statement statement = new SimpleStatement("SELECT label from CompleteBean where id=" + entity.getId());
        Row row = manager.getNativeSession().execute(statement).one();
        assertThat(row.getString("label")).isEqualTo("label");
View Full Code Here

    @Test
    public void should_order_batch_operations_on_the_same_column() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();
        final Batch batch = manager.createOrderedBatch();

        //When
        batch.startBatch();

        entity = batch.insert(entity);
        entity.setName("name");
        batch.update(entity);

        batch.endBatch();

        //Then
        Statement statement = new SimpleStatement("SELECT name from CompleteBean where id=" + entity.getId());
        Row row = manager.getNativeSession().execute(statement).one();
        assertThat(row.getString("name")).isEqualTo("name");
View Full Code Here

        CompleteBean entity1 = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();
        CompleteBean entity2 = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();

        manager.insert(entity2);

        final Batch batch = manager.createBatch();

        batch.startBatch();

        batch.insert(entity1);

        final Update.Where statement = update(CompleteBean.TABLE_NAME).with(set("name", bindMarker("name")))
                .where(eq("id", bindMarker("id")));

        //When
        batch.batchNativeStatement(statement,"DuyHai",entity2.getId());
        batch.endBatch();

        //Then
        Statement select = new SimpleStatement("SELECT name from CompleteBean where id=" + entity2.getId());
        Row row = manager.getNativeSession().execute(select).one();
        assertThat(row.getString("name")).isEqualTo("DuyHai");
View Full Code Here

    @Test
    public void should_batch_native_statement_with_CAS_result_listener() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();
        manager.insert(entity);
        final Batch batch = manager.createBatch();
        final Insert statement = insertInto("CompleteBean").value("id", bindMarker("id")).value("name", bindMarker("name")).ifNotExists();

        final AtomicBoolean error = new AtomicBoolean(false);
        final AtomicReference<CASResultListener.CASResult> result = new AtomicReference<>(null);

        CASResultListener listener = new CASResultListener() {
            @Override
            public void onCASSuccess() {

            }

            @Override
            public void onCASError(CASResult casResult) {
                error.getAndSet(true);
                result.getAndSet(casResult);
            }
        };

        //When
        batch.batchNativeStatementWithCASListener(statement,listener, entity.getId(),"name");
        batch.endBatch();

        //Then
        assertThat(error.get()).isTrue();
        assertThat(result.get()).isNotNull();
View Full Code Here

        //Given
        Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);
        String name = "DuyHai";
        final Insert statement = insertInto("CompleteBean").value("id", id).value("name", name).ifNotExists();

        final Batch batch = manager.createBatch();

        batch.startBatch();

        batch.batchNativeStatement(statement);

        batch.endBatch();

        //When
        final CompleteBean found = manager.find(CompleteBean.class, id);

        //Then
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.persistence.Batch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.