如何使用cassandra触发器执行删除操作?

时间:2015-10-18 07:11:02

标签: java triggers cassandra cassandra-2.0

我在一个Key Space中有两个Column Family。这些列族具有相同的模式和数据。当在第一个上执行删除操作时,我想删除具有相同主键的第二行。 以下是我在ITrigger增强方法上所尝试的内容

@Override
public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) {
    List<Mutation> mutations = new ArrayList<>(update.getColumnCount());
    String indexKeySpace = properties.getProperty("keyspace");
    String indexColumnFamily = properties.getProperty("table");
    if (!update.deletionInfo().isLive()) {
        Mutation mutation = new Mutation(indexKeySpace, key);
        mutation.delete(indexColumnFamily, System.currentTimeMillis());
        mutations.add(mutation);
    }
    return mutations;
}

1 个答案:

答案 0 :(得分:3)

我解决了这个问题:D
这是工作代码

@Override
public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) {
    List<Mutation> mutations = new ArrayList<>(update.getColumnCount());
    String indexKeySpace = properties.getProperty("keyspace");
    String indexColumnFamily = properties.getProperty("table");
    if (!update.deletionInfo().isLive()) {
        CFMetaData cfMetaData = Schema.instance.getCFMetaData(indexKeySpace, indexColumnFamily);
        for (ColumnDefinition columnDefinition : cfMetaData.allColumns()) {
            Mutation mutation = new Mutation(indexKeySpace, key);
            mutation.delete(indexColumnFamily, CellNames.simpleSparse(columnDefinition.name), System.currentTimeMillis());
            mutations.add(mutation);
        }
    }
    return mutations;
}