Package info.archinnov.achilles.internal.metadata.holder

Examples of info.archinnov.achilles.internal.metadata.holder.PropertyMetaStatementGenerator


        Map<CQLQueryType, Map<String, PreparedStatement>> clusteredCounterPSMap = new HashMap<>();
        Map<String, PreparedStatement> incrStatementPerCounter = new HashMap<>();
        Map<String, PreparedStatement> decrStatementPerCounter = new HashMap<>();
        Map<String, PreparedStatement> selectStatementPerCounter = new HashMap<>();

        final PropertyMetaStatementGenerator statementGenerator = idMeta.forStatementGeneration();

        for (PropertyMeta counterMeta : meta.getAllCounterMetas()) {
            final String propertyName = counterMeta.getPropertyName();
            final String cql3ColumnName = counterMeta.getCQL3ColumnName();
            final boolean staticColumn = counterMeta.structure().isStaticColumn();

            RegularStatement incrementStatement = prepareWhereClauseForCounterUpdate(statementGenerator, update(keyspaceName,tableName).with(incr(cql3ColumnName, bindMarker(cql3ColumnName))), staticColumn, noOptions());
            RegularStatement decrementStatement = prepareWhereClauseForCounterUpdate(statementGenerator, update(keyspaceName,tableName).with(decr(cql3ColumnName, bindMarker(cql3ColumnName))), staticColumn, noOptions());

            RegularStatement selectStatement = statementGenerator.generateWhereClauseForSelect(Optional.fromNullable(counterMeta), select(cql3ColumnName).from(keyspaceName,tableName));

            incrStatementPerCounter.put(propertyName, session.prepare(incrementStatement));
            decrStatementPerCounter.put(propertyName, session.prepare(decrementStatement));
            selectStatementPerCounter.put(propertyName, session.prepare(selectStatement));
        }
        clusteredCounterPSMap.put(INCR, incrStatementPerCounter);
        clusteredCounterPSMap.put(DECR, decrStatementPerCounter);

        RegularStatement selectStatement = statementGenerator.generateWhereClauseForSelect(Optional.<PropertyMeta>absent(), select().from(keyspaceName,tableName));
        selectStatementPerCounter.put(SELECT_ALL.name(), session.prepare(selectStatement));
        clusteredCounterPSMap.put(SELECT, selectStatementPerCounter);

        RegularStatement deleteStatement = statementGenerator.generateWhereClauseForDelete(false, delete().from(keyspaceName,tableName));
        clusteredCounterPSMap.put(DELETE, of(DELETE_ALL.name(), session.prepare(deleteStatement)));

        return clusteredCounterPSMap;
    }
View Full Code Here


    }

    @Test
    public void should_prepare_clustered_counter_queries() throws Exception {
        PropertyMeta counterMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMetaStatementGenerator statementGenerator = mock(PropertyMetaStatementGenerator.class, RETURNS_DEEP_STUBS);

        when(meta.getAllCounterMetas()).thenReturn(asList(counterMeta));
        when(counterMeta.forStatementGeneration()).thenReturn(statementGenerator);
        when(counterMeta.getPropertyName()).thenReturn("countProperty");
        when(counterMeta.getCQL3ColumnName()).thenReturn("count");
        when(counterMeta.structure().isStaticColumn()).thenReturn(false);


        when(statementGenerator.prepareCommonWhereClauseForUpdate(update("table").with(incr("count", bindMarker("count"))), false))
                .thenReturn(update("table").where());
        when(statementGenerator.prepareCommonWhereClauseForUpdate(update("table").with(decr("count", bindMarker("count"))), false))
                .thenReturn(update("table").where());
        when(statementGenerator.generateWhereClauseForSelect(Optional.fromNullable(counterMeta), select("count").from("table")))
                .thenReturn(select("count").from("table").where(eq("id", bindMarker("id"))));
        when(statementGenerator.generateWhereClauseForSelect(Optional.<PropertyMeta>absent(), select().from("table")))
                .thenReturn(select().from("table"));
        when(statementGenerator.generateWhereClauseForDelete(false, delete().from("table")))
                .thenReturn(delete().from("table"));


        PreparedStatement incrPs = mock(PreparedStatement.class);
        PreparedStatement decrPs = mock(PreparedStatement.class);
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.internal.metadata.holder.PropertyMetaStatementGenerator

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.