Updated Branches: refs/heads/cassandra-2.0 e44d5d4f3 -> 9ebb09182
Fix the trigger example Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/9ebb0918 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/9ebb0918 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/9ebb0918 Branch: refs/heads/cassandra-2.0 Commit: 9ebb0918293196bd4edf1e88bf8d28443d252157 Parents: e44d5d4 Author: Aleksey Yeschenko <alek...@apache.org> Authored: Sun Nov 24 08:32:32 2013 +0300 Committer: Aleksey Yeschenko <alek...@apache.org> Committed: Sun Nov 24 08:32:32 2013 +0300 ---------------------------------------------------------------------- .../cassandra/triggers/InvertedIndex.java | 27 +++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/9ebb0918/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java ---------------------------------------------------------------------- diff --git a/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java b/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java index a7a141b..a2d7644 100644 --- a/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java +++ b/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java @@ -27,32 +27,41 @@ import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.RowMutation; import org.apache.cassandra.io.util.FileUtils; -public class InvertedIndex implements ITrigger { +public class InvertedIndex implements ITrigger +{ private static final Logger logger = LoggerFactory.getLogger(InvertedIndex.class); private Properties properties = loadProperties(); - public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update) { - List<RowMutation> mutations = new ArrayList<RowMutation>(); - for (ByteBuffer name : update.getColumnNames()) { - RowMutation mutation = new RowMutation(properties.getProperty("keyspace"), update.getColumn(name).value()); - mutation.add(properties.getProperty("columnfamily"), name, key, System.currentTimeMillis()); + public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update) + { + List<RowMutation> mutations = new ArrayList<>(); + for (Column cell : update) + { + RowMutation mutation = new RowMutation(properties.getProperty("keyspace"), cell.value()); + mutation.add(properties.getProperty("columnfamily"), cell.name(), key, System.currentTimeMillis()); mutations.add(mutation); } return mutations; } - private static Properties loadProperties() { + private static Properties loadProperties() + { Properties properties = new Properties(); InputStream stream = InvertedIndex.class.getClassLoader().getResourceAsStream("InvertedIndex.properties"); try { properties.load(stream); - } catch (Exception e) { + } + catch (Exception e) + { throw new RuntimeException(e); - } finally { + } + finally + { FileUtils.closeQuietly(stream); } logger.info("loaded property file, InvertedIndex.properties");