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;
}
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;
}
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;
}
Aggregations