Package info.archinnov.achilles.persistence

Examples of info.archinnov.achilles.persistence.Batch


    private PersistenceManager manager = resource.getPersistenceManager();

    @Test
    public void should_execute_native_batch() {
        // create persistence manager -- pm
        Batch batch = manager.createBatch();
        batch.startBatch();

        RegularStatement statement = QueryBuilder.insertInto(ValuelessEntity.TABLE_NAME).value("id", 234L);
        batch.batchNativeStatement(statement);

        ValuelessEntity entity = new ValuelessEntity(123L);
        batch.insert(entity);

        batch.endBatch();
    }
View Full Code Here


    @Test
    public void should_not_order_batch_statements_for_insert() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().buid();
        Batch batch = manager.createBatch();

        //When
        batch.startBatch();

        entity.setName("name3");
        batch.insert(entity);
        entity.setName("name1");
        batch.insert(entity);

        batch.endBatch();
        //Then

        CompleteBean actual = manager.find(CompleteBean.class, entity.getId());

        assertThat(actual.getName()).isEqualTo("name3");
View Full Code Here

    @Test
    public void should_not_order_batch_statements_for_update() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().buid();
        Batch batch = manager.createBatch();

        CompleteBean managed = manager.insert(entity);

        //When
        batch.startBatch();

        managed.setName("name3");
        batch.update(managed);
        managed.setName("name1");
        batch.update(managed);

        batch.endBatch();

        //Then
        manager.refresh(managed);

        assertThat(managed.getName()).isEqualTo("name3");
View Full Code Here

    }

    @Test
    public void should_batch_counters() throws Exception {
        // Start batch
        Batch batch = manager.createBatch();
        batch.startBatch();

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

        entity = batch.insert(entity);

        entity.setLabel("label");

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

        entity.getVersion().incr(10L);
        batch.update(entity);

        final RegularStatement selectLabel = select("label").from("CompleteBean").where(eq("id", entity.getId()));
        Map<String, Object> result = manager.nativeQuery(selectLabel).first();
        assertThat(result).isNull();

        RegularStatement selectCounter = select("counter_value").from("achilles_counter_table")
                .where(eq("fqcn", CompleteBean.class.getCanonicalName()))
                .and(eq("primary_key", entity.getId().toString()))
                .and(eq("property_name", "version"));

        result = manager.nativeQuery(selectCounter).first();
        assertThat(result).isNull();

        // Flush
        batch.endBatch();

        Row row = manager.getNativeSession().execute(selectLabel).one();
        assertThat(row.getString("label")).isEqualTo("label");

        result = manager.nativeQuery(selectCounter).first();
View Full Code Here

        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
        Batch batch = manager.createBatch();
        batch.startBatch();

        batch.insert(bean);
        batch.insert(tweet1);
        batch.insert(tweet2);
        batch.insert(user);

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

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

        // Flush
        batch.endBatch();

        final ResultSet resultSet = manager.getNativeSession().execute("SELECT id,favoriteTweets,followers,friends,age_in_years,name,welcomeTweet,label,preferences FROM CompleteBean WHERE id=:id", bean.getId());
        assertThat(resultSet.all()).hasSize(1);

        foundBean = manager.find(CompleteBean.class, bean.getId());
View Full Code Here

        Tweet tweet = TweetTestBuilder.tweet().randomId().content("simple_tweet").creator(user).buid();

        user = manager.insert(user);

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

        boolean exceptionCaught = false;

        try {
            batch.insert(tweet, OptionsBuilder.withConsistency(ConsistencyLevel.EACH_QUORUM));
        } catch (AchillesException e) {
            exceptionCaught = true;
            batch.cleanBatch();
            assertThatBatchContextHasBeenReset(batch);

            assertThat(manager.find(Tweet.class, tweet.getId())).isNull();
        }

        // batch should reinit batch context
        batch.insertOrUpdate(user);
        batch.endBatch();

        User foundUser = manager.find(User.class, user.getId());
        assertThat(foundUser.getFirstname()).isEqualTo("firstname");
        assertThat(foundUser.getLastname()).isEqualTo("lastname");

        batch.insert(tweet);
        batch.endBatch();

        Tweet foundTweet = manager.find(Tweet.class, tweet.getId());
        assertThat(foundTweet.getContent()).isEqualTo("simple_tweet");
        assertThat(foundTweet.getCreator().getId()).isEqualTo(foundUser.getId());
        assertThat(foundTweet.getCreator().getFirstname()).isEqualTo("firstname");
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.