com.datastax.driver.core.querybuilder.Delete Java Examples

The following examples show how to use com.datastax.driver.core.querybuilder.Delete. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraTable.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
protected Delete buildDelete(CassandraBackendEntry.Row entry) {
    List<HugeKeys> idNames = this.idColumnName();
    Delete delete = QueryBuilder.delete().from(this.table());

    if (entry.columns().isEmpty()) {
        // Delete just by id
        List<Long> idValues = this.idColumnValue(entry);
        assert idNames.size() == idValues.size();

        for (int i = 0, n = idNames.size(); i < n; i++) {
            delete.where(formatEQ(idNames.get(i), idValues.get(i)));
        }
    } else {
        // Delete just by column keys(must be id columns)
        for (HugeKeys idName : idNames) {
            // TODO: should support other filters (like containsKey)
            delete.where(formatEQ(idName, entry.column(idName)));
        }
        /*
         * TODO: delete by id + keys(like index element-ids -- it seems
         * has been replaced by eliminate() method)
         */
    }
    return delete;
}
 
Example #2
Source File: ConditionSetter.java    From scalardb with Apache License 2.0 5 votes vote down vote up
/**
 * Adds {@code DeleteIf}-specific conditions to the statement
 *
 * @param condition {@code DeleteIf} condition
 */
@Override
public void visit(DeleteIf condition) {
  Delete.Where delete = (Delete.Where) statement;

  List<ConditionalExpression> expressions = condition.getExpressions();
  Delete.Conditions cond = delete.onlyIf(createClauseWith(expressions.get(0)));
  IntStream.range(1, expressions.size())
      .forEach(
          i -> {
            cond.and(createClauseWith(expressions.get(i)));
          });
}
 
Example #3
Source File: CassandraTables.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private Delete buildDelete(Id label, Object ownerVertex,
                           Directions direction, Object sortValues,
                           Object otherVertex) {
    Delete delete = QueryBuilder.delete().from(edgesTable(direction));
    delete.where(formatEQ(HugeKeys.OWNER_VERTEX, ownerVertex));
    delete.where(formatEQ(HugeKeys.DIRECTION,
                          EdgeId.directionToCode(direction)));
    delete.where(formatEQ(HugeKeys.LABEL, label.asLong()));
    delete.where(formatEQ(HugeKeys.SORT_VALUES, sortValues));
    delete.where(formatEQ(HugeKeys.OTHER_VERTEX, otherVertex));
    return delete;
}
 
Example #4
Source File: CassandraSampleRepository.java    From newts with Apache License 2.0 5 votes vote down vote up
@Inject
public CassandraSampleRepository(CassandraSession session, @Named("samples.cassandra.time-to-live") int ttl, @Named("newtsMetricRegistry") MetricRegistry registry,
                                 SampleProcessorService processorService, ContextConfigurations contextConfigurations) {

    m_session = checkNotNull(session, "session argument");
    checkArgument(ttl >= 0, "Negative Cassandra column TTL");

    m_ttl = ttl;

    checkNotNull(registry, "metric registry argument");
    m_processorService = processorService;

    m_contextConfigurations = checkNotNull(contextConfigurations, "contextConfigurations argument");

    Select select = QueryBuilder.select().from(SchemaConstants.T_SAMPLES);
    select.where(eq(SchemaConstants.F_CONTEXT, bindMarker(SchemaConstants.F_CONTEXT)));
    select.where(eq(SchemaConstants.F_PARTITION, bindMarker(SchemaConstants.F_PARTITION)));
    select.where(eq(SchemaConstants.F_RESOURCE, bindMarker(SchemaConstants.F_RESOURCE)));

    select.where(gte(SchemaConstants.F_COLLECTED, bindMarker("start")));
    select.where(lte(SchemaConstants.F_COLLECTED, bindMarker("end")));

    m_selectStatement = m_session.prepare(select.toString());

    Delete delete = QueryBuilder.delete().from(SchemaConstants.T_SAMPLES);
    delete.where(eq(SchemaConstants.F_CONTEXT, bindMarker(SchemaConstants.F_CONTEXT)));
    delete.where(eq(SchemaConstants.F_PARTITION, bindMarker(SchemaConstants.F_PARTITION)));
    delete.where(eq(SchemaConstants.F_RESOURCE, bindMarker(SchemaConstants.F_RESOURCE)));

    m_deleteStatement = m_session.prepare(delete.toString());

    m_sampleSelectTimer = registry.timer(metricName("sample-select-timer"));
    m_measurementSelectTimer = registry.timer(metricName("measurement-select-timer"));
    m_insertTimer = registry.timer(metricName("insert-timer"));
    m_samplesInserted = registry.meter(metricName("samples-inserted"));
    m_samplesSelected = registry.meter(metricName("samples-selected"));
}
 
Example #5
Source File: CObjectCQLGenerator.java    From Rhombus with MIT License 5 votes vote down vote up
public static Statement makeCQLforDeleteUUIDFromIndex_WorkaroundForUnpreparableTimestamp(String keyspace, CDefinition def, CIndex index, UUID uuid, Map<String,Object> indexValues, Long timestamp){
	Statement ret = QueryBuilder.delete()
			.from(keyspace,makeIndexTableName(def,index))
			.using(QueryBuilder.timestamp(timestamp))
			.where(QueryBuilder.eq("id",uuid))
			.and(QueryBuilder.eq("shardid", Long.valueOf(index.getShardingStrategy().getShardKey(uuid))));
	for(String key : indexValues.keySet()){
		((Delete.Where)ret).and(QueryBuilder.eq(key,indexValues.get(key)));
	}
	return ret;
}
 
Example #6
Source File: ConditionSetter.java    From scalardb with Apache License 2.0 4 votes vote down vote up
/**
 * Adds {@code DeleteIfExists}-specific conditions to the statement
 *
 * @param condition {@code DeleteIfExists} condition
 */
@Override
public void visit(DeleteIfExists condition) {
  Delete.Where delete = (Delete.Where) statement;
  delete.ifExists();
}
 
Example #7
Source File: CassandraPerDomainMaxQuotaDao.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Delete.Where removeMaxMessageStatement() {
    return delete().column(CassandraDomainMaxQuota.MESSAGE_COUNT)
        .from(CassandraDomainMaxQuota.TABLE_NAME)
        .where(eq(CassandraDomainMaxQuota.DOMAIN, bindMarker()));
}
 
Example #8
Source File: CassandraPerDomainMaxQuotaDao.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Delete.Where removeMaxStorageStatement() {
    return delete().column(CassandraDomainMaxQuota.STORAGE)
        .from(CassandraDomainMaxQuota.TABLE_NAME)
        .where(eq(CassandraDomainMaxQuota.DOMAIN, bindMarker()));
}
 
Example #9
Source File: CassandraGlobalMaxQuotaDao.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Delete.Where removeGlobalMaxQuotaStatement() {
    return delete().all()
        .from(CassandraGlobalMaxQuota.TABLE_NAME)
        .where(eq(CassandraGlobalMaxQuota.TYPE, bindMarker(CassandraGlobalMaxQuota.TYPE)));
}
 
Example #10
Source File: CassandraPerUserMaxQuotaDao.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Delete.Where removeMaxMessageStatement() {
    return delete().column(CassandraMaxQuota.MESSAGE_COUNT)
        .from(CassandraMaxQuota.TABLE_NAME)
        .where(eq(CassandraMaxQuota.QUOTA_ROOT, bindMarker()));
}
 
Example #11
Source File: CassandraPerUserMaxQuotaDao.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Delete.Where removeMaxStorageStatement() {
    return delete().column(CassandraMaxQuota.STORAGE)
        .from(CassandraMaxQuota.TABLE_NAME)
        .where(eq(CassandraMaxQuota.QUOTA_ROOT, bindMarker()));
}
 
Example #12
Source File: IncrementalStateTest.java    From storm-cassandra-cql with Apache License 2.0 4 votes vote down vote up
private void clearState() {
    Delete deleteStatement = delete().all().from(KEYSPACE_NAME, TABLE_NAME);
    deleteStatement.where(eq(KEY_NAME, "MD"));
    clientFactory.getSession().execute(deleteStatement);
}
 
Example #13
Source File: CassandraOperations.java    From geowave with Apache License 2.0 4 votes vote down vote up
public Delete getDelete(final String table) {
  return QueryBuilder.delete().from(gwNamespace, getCassandraSafeName(table));
}