deletePath(rowKey, path, null);
}
@Override
public void deletePath(K rowKey, Path path, BatchContext batchContext) {
Batch batch = validateAndGetBatch(batchContext);
validateArgs(rowKey, path);
// converting from a string and back normalizes the path, e.g. makes sure ends with the delimiter character
String start = path.toString();
String finish = getFinishString(start);
// would like to just do a delete with a where clause, but unfortunately Cassandra can't do that in CQL (either)
// with >= and <=
// Since the path column is in the primary key, we need to just delete whole rows.
Object[] args = {rowKey,start,finish};
ResultSet resultSet = session.execute(readForDeleteQuery.bind(args));
if (resultSet.isExhausted()) {
// not found
return;
}
Delete deleteStatement = delete().from(tableName);
deleteStatement
.using(timestamp(getCurrentMicros()))
.where(eq(partitionKeyColumnName, rowKey))
.and(eq(pathColumnName, bindMarker()));
batch = batchContext == null ? batch() : batch;
List<Object> bindArguments = batchContext == null ?
new ArrayList<Object>() :
((CqlBatchContext)batchContext).getBindArguments();
for (Row row : resultSet) {
String pathToDelete = row.getString(0);
batch.add(deleteStatement);
bindArguments.add(pathToDelete);
}
if (batchContext == null) {
BoundStatement query = session.prepare(batch.getQueryString()).bind(bindArguments.toArray());
query.setConsistencyLevel(defaultConsistencyLevel);
session.execute(query);
}
}