valchkou / cassandra-driver-mapping

JPA addon for DataStax Java Driver for Cassandra
58 stars 24 forks source link

Delete does not take any options #71

Open jalger98 opened 9 years ago

jalger98 commented 9 years ago

There is no way to provide options to the delete methods of the MappingSession or BatchExecutor. Delete should take options like the WriteOptions supported for the save methods. We could use the timestamp and consistencyLevel options immediately. retryPolicy would be nice too.

jalger98 commented 9 years ago

Adding a timestamp option to the BatchExecutor BatchOptions would also be helpful.

valchkou commented 9 years ago

I will take a look at it

jalger98 commented 9 years ago

Awesome, thanks!

jalger98 commented 9 years ago

I was able to modify the logic of the buildDelete method in the MappingBuilder as a simple proof of the logic being there. However, your current "master" branch has 2.2.0-rc2 which does not support the format that code I'm about to suggest. It is written with the syntax for cassandra-driver-core version 2.1.3. Obviously, you'd have to update the signature to support passing in the options instead of the hardcoded version below but this seems to confirm that it could be retrofitted fairly easily.

public static <T> Delete buildDelete(EntityTypeMetadata entityMetadata, List<String> pkCols, Object[] values, String keyspace) {
    String table = entityMetadata.getTableName();
    Delete delete = QueryBuilder.delete().from(keyspace, table);

    // Apply the timestamp here.
    delete.using(timestamp(System.currentTimeMillis()*1000));

    for (int i = 0; i < values.length; i++) {
        delete.where(eq(pkCols.get(i), values[i]));
    }
    return delete;
}