Search in sources :

Example 6 with RegularStatement

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;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 7 with RegularStatement

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;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 8 with RegularStatement

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;
}
Also used : RegularStatement(com.datastax.driver.core.RegularStatement) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) Statement(com.datastax.driver.core.Statement) List(java.util.List) StatementGenerator(org.opennms.newts.cassandra.search.support.StatementGenerator)

Example 9 with RegularStatement

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);
    }
}
Also used : RegularStatement(com.datastax.driver.core.RegularStatement)

Example 10 with RegularStatement

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();
    }
}
Also used : ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) Timer(com.codahale.metrics.Timer) RegularStatement(com.datastax.driver.core.RegularStatement)

Aggregations

RegularStatement (com.datastax.driver.core.RegularStatement)15 BoundStatement (com.datastax.driver.core.BoundStatement)2 Cluster (com.datastax.driver.core.Cluster)2 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)2 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 ResultSet (com.datastax.driver.core.ResultSet)2 Statement (com.datastax.driver.core.Statement)2 TableMetadata (com.datastax.driver.core.TableMetadata)2 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)2 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)2 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)2 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)2 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)2 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Timer (com.codahale.metrics.Timer)1 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)1 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)1