Search in sources :

Example 1 with RegularStatement

use of com.datastax.driver.core.RegularStatement in project newts by OpenNMS.

the class CassandraIndexer method recursivelyUnindexResourceElements.

private void recursivelyUnindexResourceElements(List<RegularStatement> statement, Context context, String resourceId, ConsistencyLevel writeConsistencyLevel) {
    List<String> elements = m_resourceIdSplitter.splitIdIntoElements(resourceId);
    int numElements = elements.size();
    if (numElements == 1) {
        // Tag the top level elements with _parent:_root
        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.PARENT_TERM_FIELD)).and(QueryBuilder.eq(Constants.Schema.C_TERMS_VALUE, Constants.TOP_LEVEL_PARENT_TERM_VALUE)).and(QueryBuilder.eq(Constants.Schema.C_TERMS_RESOURCE, resourceId));
        delete.setConsistencyLevel(writeConsistencyLevel);
        statement.add(delete);
    } else {
        // Construct the parent's resource id
        String parentResourceId = m_resourceIdSplitter.joinElementsToId(elements.subList(0, numElements - 1));
        // Tag the resource with its parent's id
        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.PARENT_TERM_FIELD)).and(QueryBuilder.eq(Constants.Schema.C_TERMS_VALUE, parentResourceId)).and(QueryBuilder.eq(Constants.Schema.C_TERMS_RESOURCE, resourceId));
        delete.setConsistencyLevel(writeConsistencyLevel);
        statement.add(delete);
        // Recurse
        recursivelyUnindexResourceElements(statement, context, parentResourceId, writeConsistencyLevel);
    }
}
Also used : RegularStatement(com.datastax.driver.core.RegularStatement)

Example 2 with RegularStatement

use of com.datastax.driver.core.RegularStatement in project newts by OpenNMS.

the class CassandraIndexer method definitelyUnindexResourceAttributes.

private void definitelyUnindexResourceAttributes(List<RegularStatement> statement, Context context, Resource resource, ConsistencyLevel writeConsistency) {
    if (!resource.getAttributes().isPresent()) {
        return;
    }
    for (Entry<String, String> field : resource.getAttributes().get().entrySet()) {
        // Search unindexing
        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, field.getValue())).and(QueryBuilder.eq(Constants.Schema.C_TERMS_RESOURCE, resource.getId()));
        delete.setConsistencyLevel(writeConsistency);
        statement.add(delete);
        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, field.getKey())).and(QueryBuilder.eq(Constants.Schema.C_TERMS_VALUE, field.getValue())).and(QueryBuilder.eq(Constants.Schema.C_TERMS_RESOURCE, resource.getId()));
        delete.setConsistencyLevel(writeConsistency);
        statement.add(delete);
        // Storage
        delete = QueryBuilder.delete().from(Constants.Schema.T_ATTRS).where(QueryBuilder.eq(Constants.Schema.C_ATTRS_CONTEXT, context.getId())).and(QueryBuilder.eq(Constants.Schema.C_ATTRS_RESOURCE, resource.getId())).and(QueryBuilder.eq(Constants.Schema.C_ATTRS_ATTR, field.getKey()));
        delete.setConsistencyLevel(writeConsistency);
        statement.add(delete);
    }
}
Also used : RegularStatement(com.datastax.driver.core.RegularStatement)

Example 3 with RegularStatement

use of com.datastax.driver.core.RegularStatement in project pinpoint by naver.

the class CassandraPreparedStatementCreateInterceptor method prepareAfterTrace.

@Override
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
    final boolean success = InterceptorUtils.isSuccess(throwable);
    if (success) {
        if (target instanceof DatabaseInfoAccessor) {
            // set databaseInfo to PreparedStatement only when
            // preparedStatement is generated successfully.
            DatabaseInfo databaseInfo = ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo();
            if (databaseInfo != null) {
                if (result instanceof DatabaseInfoAccessor) {
                    ((DatabaseInfoAccessor) result)._$PINPOINT$_setDatabaseInfo(databaseInfo);
                }
            }
        }
        if (result instanceof ParsingResultAccessor) {
            String sql;
            if (args[0] instanceof RegularStatement) {
                sql = ((RegularStatement) args[0]).getQueryString();
            } else {
                // we have string
                sql = (String) args[0];
            }
            ParsingResult parsingResult = traceContext.parseSql(sql);
            if (parsingResult != null) {
                ((ParsingResultAccessor) result)._$PINPOINT$_setParsingResult(parsingResult);
            } else {
                if (logger.isErrorEnabled()) {
                    logger.error("sqlParsing fail. parsingResult is null sql:{}", sql);
                }
            }
        }
    }
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 4 with RegularStatement

use of com.datastax.driver.core.RegularStatement in project cassandra-driver-mapping by valchkou.

the class SchemaSync method getScript.

public static String getScript(String keyspace, Session session, Class<?> clazz, SyncOptions syncOptions) {
    StringBuilder sb = new StringBuilder();
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(clazz);
    List<RegularStatement> statements = buildSyncStatements(keyspace, session, entityMetadata, syncOptions);
    for (RegularStatement stmt : statements) {
        sb.append(stmt.getQueryString());
        sb.append("\n");
    }
    return sb.toString();
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 5 with RegularStatement

use of com.datastax.driver.core.RegularStatement in project cassandra-driver-mapping by valchkou.

the class SchemaSync method sync.

public static synchronized void sync(String keyspace, Session session, Class<?> clazz, SyncOptions syncOptions) {
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(clazz);
    if (entityMetadata.isSynced(keyspace))
        return;
    List<RegularStatement> statements = buildSyncStatements(keyspace, session, entityMetadata, syncOptions);
    for (RegularStatement stmt : statements) {
        session.execute(stmt);
    }
    entityMetadata.markSynced(keyspace);
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) 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