Package info.archinnov.achilles.type.Options

Examples of info.archinnov.achilles.type.Options.CASCondition


public class OptionsTest {

    @Test
    public void should_duplicate_without_ttl_and_timestamp() throws Exception {
        final CASCondition CASCondition = new CASCondition("name", "John");
        Options options = OptionsBuilder.withConsistency(EACH_QUORUM).withTtl(10)
                .withTimestamp(100L).ifNotExists().ifConditions(CASCondition);

        Options newOptions = options.duplicateWithoutTtlAndTimestamp();
View Full Code Here


    @Test
    public void should_encode_CAS_condition_value() throws Exception {
        //Given
        PropertyMeta nameMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        CASCondition casCondition = spy(new CASCondition("name", "DuyHai"));

        when(meta.getAllMetasExceptCounters()).thenReturn(asList(nameMeta));
        when(nameMeta.getCQL3ColumnName()).thenReturn("name");
        when(nameMeta.getPropertyName()).thenReturn("name");
        when(nameMeta.forTranscoding().encodeToCassandra("DuyHai")).thenReturn("DuyHai");
View Full Code Here

    @Test
    public void should_bind_for_remove_entry_from_map_with_cas_condition() throws Exception {
        //Given
        Long primaryKey = RandomUtils.nextLong(0,Long.MAX_VALUE);
        final CASCondition CASCondition = new CASCondition("name", "John");


        when(context.getPrimaryKey()).thenReturn(primaryKey);
        when(context.hasCasConditions()).thenReturn(true);
        when(context.getCasConditions()).thenReturn(asList(CASCondition));
View Full Code Here

        //Given

        Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);
        Object[] boundValues = new Object[] { "whatever" };
        CompleteBean entity = builder().id(id).buid();
        final CASCondition casCondition = new CASCondition("name", "DuyHai");
        final Pair<Assignments, Object[]> updateClauseAndBoundValues = Pair.create(update(), boundValues);
        final Pair<Where, Object[]> whereClauseAndBoundValues = Pair.create(QueryBuilder.update("table").with(set("name", "DuyHai")).where(QueryBuilder.eq("id",11L)), boundValues);

        when(context.getEntity()).thenReturn(entity);
        when(context.getEntityMeta()).thenReturn(entityMeta);
View Full Code Here

        when(ageMeta.forStatementGeneration().prepareUpdateField(isA(Assignments.class))).thenReturn(assignments);
        when(idMeta.forStatementGeneration().prepareCommonWhereClauseForUpdate(assignments, false)).thenReturn(assignments.where(eq("id", bindMarker("id"))));
        when(session.prepare(queryCaptor.capture())).thenReturn(ps);

        PreparedStatement actual = generator.prepareUpdateFields(session, meta, asList(nameMeta, ageMeta),
                ifConditions(new CASCondition("name", "John")).withTimestamp(100L));

        assertThat(actual).isSameAs(ps);

        assertThat(conditionsCaptor.getValue().getQueryString()).isEqualTo("UPDATE ks.table IF name=:name;");
        assertThat(queryCaptor.getValue()).isEqualTo("UPDATE ks.table USING TTL :ttl AND TIMESTAMP :timestamp WHERE id=:id;");
View Full Code Here

        when(session.prepare(regularStatementCaptor.capture())).thenReturn(ps);

        //When
        final PreparedStatement actual = generator.prepareCollectionAndMapUpdate(session, meta, changeSet,
                ifConditions(new CASCondition("name", "John")).withTimestamp(100L));

        //Then
        assertThat(actual).isSameAs(ps);
        assertThat(regularStatementCaptor.getValue().getQueryString()).isEqualTo("UPDATE ks.table USING TTL :ttl AND TIMESTAMP :timestamp;");
        assertThat(conditionsCaptor.getValue().getQueryString()).isEqualTo("UPDATE ks.table IF name=:name;");
View Full Code Here

        final EntityWithEnum entityWithEnum = new EntityWithEnum(10L, "John", EACH_QUORUM);
        final EntityWithEnum managed = manager.insert(entityWithEnum);
        managed.setName("Helen");

        //When
        manager.insertOrUpdate(managed, ifConditions(new CASCondition("name", "John"), new CASCondition("consistency_level", EACH_QUORUM)));

        //Then
        final EntityWithEnum found = manager.find(EntityWithEnum.class, 10L);

        assertThat(found).isNotNull();
View Full Code Here

        final CompleteBean managed = manager.insert(entity);
        managed.setName("Helen");
        managed.getFriends().add("George");

        //When
        manager.update(managed, ifConditions(new CASCondition("age_in_years", 32L)));

        //Then
        final CompleteBean found = manager.find(CompleteBean.class, primaryKey);

        assertThat(found).isNotNull();
View Full Code Here

        AchillesLightWeightTransactionException casException = null;
        managed.setName("Helen");

        //When
        try {
            manager.update(managed, ifConditions(new CASCondition("name", "name"), new CASCondition("consistency_level", EACH_QUORUM)));
        } catch (AchillesLightWeightTransactionException ace) {
            casException = ace;
        }

        assertThat(casException).isNotNull();
View Full Code Here

        Map<String, Object> expectedCurrentValues = ImmutableMap.<String, Object>of("[applied]", false, "consistency_level", EACH_QUORUM.name(), "name", "John");
        managed.setName("Helen");

        //When
        manager.update(managed,
                ifConditions(new CASCondition("name", "name"), new CASCondition("consistency_level", EACH_QUORUM))
                        .casResultListener(listener));

        final CASResult casResult = atomicCASResult.get();
        assertThat(casResult).isNotNull();
        assertThat(casResult.operation()).isEqualTo(UPDATE);
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.type.Options.CASCondition

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.