use of com.datastax.driver.core.PreparedStatement 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.PreparedStatement in project apex-malhar by apache.
the class CassandraPOJOOutputOperator method getUpdateCommand.
/**
* {@inheritDoc} <br/>
* If statement/query is not specified by user, insert query is constructed from fileInfo object and table name.
*/
@Override
protected PreparedStatement getUpdateCommand() {
PreparedStatement statement;
if (query == null) {
statement = prepareStatementFromFieldsAndTableName();
} else {
statement = store.getSession().prepare(query);
}
LOG.debug("Statement is: " + statement.getQueryString());
return statement;
}
use of com.datastax.driver.core.PreparedStatement in project apex-malhar by apache.
the class CassandraPreparedStatementGenerator method generatePreparedStatements.
public void generatePreparedStatements(Session session, Map<Long, PreparedStatement> preparedStatementTypes, String keyspaceName, String tableName) {
Map<Long, String> stringsWithoutPKAndExistsClauses = generatePreparedStatementsQueryStrings(keyspaceName, tableName);
String ifExistsClause = " IF EXISTS";
Map<Long, String> finalSetOfQueryStrings = new HashMap<>();
for (Long currentIndexPos : stringsWithoutPKAndExistsClauses.keySet()) {
StringBuilder aQueryStub = new StringBuilder(stringsWithoutPKAndExistsClauses.get(currentIndexPos));
buildWhereClauseForPrimaryKeys(aQueryStub);
finalSetOfQueryStrings.put(currentIndexPos + getSlotIndexForMutationContextPreparedStatement(EnumSet.of(AbstractUpsertOutputOperator.OperationContext.IF_EXISTS_CHECK_ABSENT)), aQueryStub.toString());
if (counterColumns.size() == 0) {
// IF exists cannot be used for counter column tables
finalSetOfQueryStrings.put(currentIndexPos + getSlotIndexForMutationContextPreparedStatement(EnumSet.of(AbstractUpsertOutputOperator.OperationContext.IF_EXISTS_CHECK_PRESENT)), aQueryStub.toString() + ifExistsClause);
}
}
for (Long currentIndexPos : finalSetOfQueryStrings.keySet()) {
String currentQueryStr = finalSetOfQueryStrings.get(currentIndexPos);
LOG.info("Registering query support for " + currentQueryStr);
PreparedStatement preparedStatementForThisQuery = session.prepare(currentQueryStr);
preparedStatementTypes.put(currentIndexPos, preparedStatementForThisQuery);
}
}
use of com.datastax.driver.core.PreparedStatement 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;
}
use of com.datastax.driver.core.PreparedStatement in project java-driver by datastax.
the class QueryBuilder21ExecutionTest method should_handle_contains_on_list_with_index.
@Test(groups = "short")
public void should_handle_contains_on_list_with_index() {
PreparedStatement byBuyer = session().prepare(select("id", "description", "buyers").from("products").where(contains("buyers", bindMarker("buyer"))));
ResultSet results = session().execute(byBuyer.bind().setInt("buyer", 4));
Row row = results.one();
assertThat(row).isNotNull();
assertThat(row.getInt("id")).isEqualTo(38471);
assertThat(row.getList("buyers", Integer.class)).contains(4);
}
Aggregations