mirror of https://github.com/apache/cassandra
Fix the trigger example
This commit is contained in:
parent
e44d5d4f36
commit
9ebb091829
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in New Issue