public void removeFriends(String from_uname, List<String> to_unames) { Mutator<String> mutator = cassandra.getMutator(); for (String uname : to_unames) { mutator .addDeletion(from_uname, FRIENDS, uname, SE) .addDeletion(uname, FOLLOWERS, from_uname, SE); mutator.decrementCounter(from_uname, MISC_COUNTS, "friends", 1); mutator.decrementCounter(uname, MISC_COUNTS, "followers", 1); } mutator.execute(); }
/** * Decrement counter by 1 * * @param rawID raw name * @param columnFamily column family name * @param columnName name of column * @param keyspace keyspace * @throws CassandraDataAccessException */ public static void decrementCounter( String columnName, String columnFamily, String rawID, Keyspace keyspace, long decrementBy) throws CassandraDataAccessException { try { Mutator<String> mutator = HFactory.createMutator(keyspace, StringSerializer.get()); mutator.decrementCounter(rawID, columnFamily, columnName, decrementBy); mutator.execute(); } catch (Exception e) { throw new CassandraDataAccessException("Error while accessing:" + columnFamily, e); } }
public void removeCounterRow(K key) { SliceCounterQuery<K, N> query = HFactory.createCounterSliceQuery(keyspace, keySerializer, columnNameSerializer) .setColumnFamily(columnFamily) .setKey(key); AchillesCounterSliceIterator<K, N> iterator = new AchillesCounterSliceIterator<K, N>( policy, columnFamily, query, (N) null, (N) null, false, DEFAULT_LENGTH); Mutator<K> mutator = HFactory.createMutator(keyspace, keySerializer); while (iterator.hasNext()) { HCounterColumn<N> counterCol = iterator.next(); mutator.decrementCounter(key, columnFamily, counterCol.getName(), counterCol.getValue()); } this.executeMutator(mutator); }
public void removeCounter(K key, N name) { Mutator<K> mutator = buildMutator(); Long currentValue = this.getCounterValue(key, name); mutator.decrementCounter(key, columnFamily, name, currentValue); this.executeMutator(mutator); }