From 9ebb0918293196bd4edf1e88bf8d28443d252157 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Sun, 24 Nov 2013 08:32:32 +0300 Subject: [PATCH] Fix the trigger example --- .../cassandra/triggers/InvertedIndex.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java b/examples/triggers/src/org/apache/cassandra/triggers/InvertedIndex.java index a7a141bf57..a2d76446dd 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 augment(ByteBuffer key, ColumnFamily update) { - List mutations = new ArrayList(); - 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 augment(ByteBuffer key, ColumnFamily update) + { + List 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");