Search in sources :

Example 46 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project apex-malhar by apache.

the class AbstractUpsertOutputOperator method setDefaultsAndPrepareBoundStatement.

private BoundStatement setDefaultsAndPrepareBoundStatement(UpsertExecutionContext tuple) {
    UpsertExecutionContext.NullHandlingMutationStyle nullHandlingMutationStyle = tuple.getNullHandlingMutationStyle();
    if (UpsertExecutionContext.NullHandlingMutationStyle.UNDEFINED == nullHandlingMutationStyle) {
        nullHandlingMutationStyle = UpsertExecutionContext.NullHandlingMutationStyle.SET_NULL_COLUMNS;
    }
    boolean setNulls = true;
    if (nullHandlingMutationStyle != UpsertExecutionContext.NullHandlingMutationStyle.SET_NULL_COLUMNS) {
        setNulls = false;
    }
    UpsertExecutionContext.CollectionMutationStyle collectionMutationStyle = tuple.getCollectionMutationStyle();
    if ((collectionMutationStyle == null) || (collectionMutationStyle == UpsertExecutionContext.CollectionMutationStyle.UNDEFINED)) {
        tuple.setCollectionMutationStyle(UpsertExecutionContext.CollectionMutationStyle.ADD_TO_EXISTING_COLLECTION);
    }
    UpsertExecutionContext.ListPlacementStyle listPlacementStyle = tuple.getListPlacementStyle();
    if ((listPlacementStyle == null) || (listPlacementStyle == UpsertExecutionContext.ListPlacementStyle.UNDEFINED)) {
        tuple.setListPlacementStyle(UpsertExecutionContext.ListPlacementStyle.APPEND_TO_EXISTING_LIST);
    }
    PreparedStatement preparedStatement = resolvePreparedStatementForCurrentExecutionContext(tuple);
    BoundStatement stmnt = processPayloadForExecution(preparedStatement, tuple, setNulls);
    if ((tuple.isTtlOverridden()) || (connectionStateManager.isTTLSet())) {
        int ttlToUse = connectionStateManager.getDefaultTtlInSecs();
        if (tuple.isTtlOverridden()) {
            ttlToUse = tuple.getOverridingTTL();
        }
        stmnt.setInt(CassandraPreparedStatementGenerator.TTL_PARAM_NAME, ttlToUse);
    }
    if (tuple.isOverridingConsistencyLevelSet()) {
        ConsistencyLevel currentConsistencyLevel = tuple.getOverridingConsistencyLevel();
        if (currentConsistencyLevel.isSerial()) {
            stmnt.setSerialConsistencyLevel(tuple.getOverridingConsistencyLevel());
        } else {
            stmnt.setConsistencyLevel(tuple.getOverridingConsistencyLevel());
        }
    }
    LOG.debug("Executing statement " + preparedStatement.getQueryString());
    return stmnt;
}
Also used : ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 47 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project apex-malhar by apache.

the class AbstractUpsertOutputOperator method processPayloadForExecution.

/**
 * Generates a Boundstatement that can be executed for the given incoming tuple. This boundstatement is then
 * executed as a command
 * @param ps The prepared statement that was shortlisted to execute the given tuple
 * @param tuple The tuple that represents the current execution context
 * @param setNulls This represents the value whether the columns in the prepared statement need to be ignored or
 *                 considered
 * @return The boundstatement appropriately built
 */
@SuppressWarnings(value = "unchecked")
private BoundStatement processPayloadForExecution(final PreparedStatement ps, final UpsertExecutionContext tuple, final boolean setNulls) {
    BoundStatement boundStatement = ps.bind();
    Object pojoPayload = tuple.getPayload();
    for (String cassandraColName : getters.keySet()) {
        DataType dataType = columnDefinitions.get(cassandraColName);
        CassandraPojoUtils.populateBoundStatementWithValue(boundStatement, getters, dataType, cassandraColName, pojoPayload, setNulls, codecsForCassandraColumnNames);
    }
    return boundStatement;
}
Also used : DataType(com.datastax.driver.core.DataType) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 48 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project apex-malhar by apache.

the class CassandraPOJOInputOperator method fetchKeyTokenFromDB.

private Long fetchKeyTokenFromDB(Object keyValue) {
    PreparedStatement statement = store.getSession().prepare(tokenQuery);
    BoundStatement boundStatement = new BoundStatement(statement);
    boundStatement.bind(keyValue);
    ResultSet rs = store.getSession().execute(boundStatement);
    Long keyTokenValue = rs.one().getLong(0);
    return keyTokenValue;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) SetterLong(org.apache.apex.malhar.lib.util.PojoUtils.SetterLong) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement)

Aggregations

BoundStatement (com.datastax.driver.core.BoundStatement)48 ResultSet (com.datastax.driver.core.ResultSet)9 PreparedStatement (com.datastax.driver.core.PreparedStatement)6 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)5 Row (com.datastax.driver.core.Row)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 RegularStatement (com.datastax.driver.core.RegularStatement)3 Session (com.datastax.driver.core.Session)3 DriverException (com.datastax.driver.core.exceptions.DriverException)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 List (java.util.List)3 Map (java.util.Map)3 UUID (java.util.UUID)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 DataType (com.datastax.driver.core.DataType)2 Statement (com.datastax.driver.core.Statement)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)2