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