Search in sources :

Example 6 with Delete

use of com.datastax.driver.core.querybuilder.Delete in project gora by apache.

the class CassandraQueryFactory method getDeleteByQuery.

/**
 * This method returns CQL Qeury for DeleteByQuery method.
 * refer: http://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlDelete.html
 *
 * @param mapping        Cassandra Mapping {@link CassandraMapping}
 * @param cassandraQuery Cassandra Query {@link CassandraQuery}
 * @param objects        field values
 * @return CQL Query
 */
static String getDeleteByQuery(CassandraMapping mapping, Query cassandraQuery, List<Object> objects) {
    String[] columns = null;
    if (cassandraQuery.getFields() != null) {
        columns = getColumnNames(mapping, Arrays.asList(cassandraQuery.getFields()));
    }
    Delete delete;
    if (columns != null) {
        delete = QueryBuilder.delete(columns).from(mapping.getKeySpace().getName(), mapping.getCoreName());
    } else {
        delete = QueryBuilder.delete().from(mapping.getKeySpace().getName(), mapping.getCoreName());
    }
    return processQuery(cassandraQuery, delete, mapping, objects);
}
Also used : Delete(com.datastax.driver.core.querybuilder.Delete)

Example 7 with Delete

use of com.datastax.driver.core.querybuilder.Delete in project gora by apache.

the class CassandraQueryFactory method getDeleteDataQuery.

/**
 * This method return the CQL query to delete a persistent in the table.
 * refer : http://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlDelete.html
 *
 * @param mapping Cassandra Mapping {@link CassandraMapping}
 * @param fields  filed list to be deleted
 * @return CQL Query
 */
static String getDeleteDataQuery(CassandraMapping mapping, List<String> fields) {
    String[] columnNames = getColumnNames(mapping, fields);
    String[] objects = new String[fields.size()];
    Arrays.fill(objects, "?");
    Delete delete = QueryBuilder.delete().from(mapping.getKeySpace().getName(), mapping.getCoreName());
    return processKeys(columnNames, delete);
}
Also used : Delete(com.datastax.driver.core.querybuilder.Delete)

Example 8 with Delete

use of com.datastax.driver.core.querybuilder.Delete in project incubator-hugegraph by apache.

the class CassandraTable method buildDelete.

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;
}
Also used : Delete(com.datastax.driver.core.querybuilder.Delete) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Aggregations

Delete (com.datastax.driver.core.querybuilder.Delete)8 CassandraUtils.generateDelete (org.apache.camel.utils.cassandra.CassandraUtils.generateDelete)3 BuiltStatement (com.datastax.driver.core.querybuilder.BuiltStatement)2 Select (com.datastax.driver.core.querybuilder.Select)2 HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)1 ArrayList (java.util.ArrayList)1