use of com.datastax.driver.core.RegularStatement in project camel by apache.
the class CassandraProducer method executePreparedStatement.
/**
* Execute CQL as PreparedStatement
*/
private ResultSet executePreparedStatement(Session session, Object messageCql, Object[] cqlParams) {
ResultSet resultSet;
PreparedStatement lPreparedStatement;
if (messageCql == null) {
// URI CQL
lPreparedStatement = this.preparedStatement;
} else if (messageCql instanceof String) {
// Message CQL
lPreparedStatement = getEndpoint().prepareStatement((String) messageCql);
} else if (messageCql instanceof RegularStatement) {
// Message Statement
lPreparedStatement = getEndpoint().getSession().prepare((RegularStatement) messageCql);
} else {
throw new IllegalArgumentException("Invalid " + CassandraConstants.CQL_QUERY + " header");
}
if (isEmpty(cqlParams)) {
resultSet = session.execute(lPreparedStatement.bind());
} else {
resultSet = session.execute(lPreparedStatement.bind(cqlParams));
}
return resultSet;
}
use of com.datastax.driver.core.RegularStatement in project camel by apache.
the class CassandraProducer method executeStatement.
/**
* Execute CQL as is
*/
private ResultSet executeStatement(Session session, Object messageCql, Object[] cqlParams) {
ResultSet resultSet;
String cql = null;
RegularStatement statement = null;
if (messageCql == null) {
// URI CQL
cql = getEndpoint().getCql();
} else if (messageCql instanceof String) {
// Message CQL
cql = (String) messageCql;
} else if (messageCql instanceof RegularStatement) {
// Message Statement
statement = (RegularStatement) messageCql;
} else {
throw new IllegalArgumentException("Invalid " + CassandraConstants.CQL_QUERY + " header");
}
if (statement != null) {
resultSet = session.execute(statement);
} else if (isEmpty(cqlParams)) {
resultSet = session.execute(cql);
} else {
resultSet = session.execute(cql, cqlParams);
}
return resultSet;
}
use of com.datastax.driver.core.RegularStatement in project newts by OpenNMS.
the class CassandraIndexer method toStatements.
private List<Statement> toStatements(Set<StatementGenerator> generators) {
List<Statement> statementsToExecute = Lists.newArrayList();
Map<String, List<Statement>> statementsByKey = Maps.newHashMap();
for (StatementGenerator generator : generators) {
Statement statement = generator.toStatement().setConsistencyLevel(m_contextConfigurations.getWriteConsistency(generator.getContext()));
String key = generator.getKey();
if (key == null) {
// Don't try batching these
statementsToExecute.add(statement);
continue;
}
// Group these by key
List<Statement> statementsForKey = statementsByKey.get(key);
if (statementsForKey == null) {
statementsForKey = Lists.newArrayList();
statementsByKey.put(key, statementsForKey);
}
statementsForKey.add(statement);
}
// Consolidate the grouped statements into batches
for (List<Statement> statementsForKey : statementsByKey.values()) {
for (List<Statement> partition : Lists.partition(statementsForKey, m_options.getMaxBatchSize())) {
statementsToExecute.add(unloggedBatch(partition.toArray(new RegularStatement[partition.size()])));
}
}
return statementsToExecute;
}
use of com.datastax.driver.core.RegularStatement in project newts by OpenNMS.
the class CassandraIndexer method definitelyUnindexResource.
private void definitelyUnindexResource(List<RegularStatement> statement, Context context, Resource resource, ConsistencyLevel writeConsistencyLevel) {
for (String s : m_resourceIdSplitter.splitIdIntoElements(resource.getId())) {
RegularStatement delete = QueryBuilder.delete().from(Constants.Schema.T_TERMS).where(QueryBuilder.eq(Constants.Schema.C_TERMS_CONTEXT, context.getId())).and(QueryBuilder.eq(Constants.Schema.C_TERMS_FIELD, Constants.DEFAULT_TERM_FIELD)).and(QueryBuilder.eq(Constants.Schema.C_TERMS_VALUE, s)).and(QueryBuilder.eq(Constants.Schema.C_TERMS_RESOURCE, resource.getId()));
delete.setConsistencyLevel(writeConsistencyLevel);
statement.add(delete);
}
if (m_options.isHierarchicalIndexingEnabled()) {
recursivelyUnindexResourceElements(statement, context, resource.getId(), writeConsistencyLevel);
}
}
use of com.datastax.driver.core.RegularStatement in project newts by OpenNMS.
the class CassandraIndexer method delete.
@Override
public void delete(final Context context, final Resource resource) {
final Timer.Context ctx = m_deleteTimer.time();
final ConsistencyLevel writeConsistency = m_contextConfigurations.getWriteConsistency(context);
final List<RegularStatement> statements = Lists.newArrayList();
definitelyUnindexResource(statements, context, resource, writeConsistency);
definitelyUnindexResourceAttributes(statements, context, resource, writeConsistency);
definitelyRemoveMetricName(statements, context, resource, writeConsistency);
try {
if (!statements.isEmpty()) {
m_session.execute(batch(statements.toArray(new RegularStatement[statements.size()])));
}
m_cache.delete(context, resource);
} finally {
ctx.stop();
}
}
Aggregations