示例#1
0
 /**
  * @param keyspace name of key space
  * @param columnFamily column family name
  * @param key key value
  * @param cloumnName column name
  * @return long count value
  * @throws CassandraDataAccessException
  */
 public static long getCountValue(
     Keyspace keyspace, String columnFamily, String cloumnName, String key)
     throws CassandraDataAccessException {
   try {
     CounterQuery<String, String> query =
         HFactory.createCounterColumnQuery(keyspace, stringSerializer, stringSerializer);
     query.setColumnFamily(columnFamily).setKey(key).setName(cloumnName);
     HCounterColumn<String> counter = query.execute().get();
     return counter.getValue();
   } catch (Exception e) {
     throw new CassandraDataAccessException("Error while accessing:" + columnFamily, e);
   }
 }
示例#2
0
  /**
   * remove allocated raw-column space for counter
   *
   * @param cfName column family name
   * @param counterRowName name of row
   * @param queueColumn name of column
   * @param keyspace key space name
   * @throws CassandraDataAccessException
   */
  public static void removeCounterColumn(
      String cfName, String counterRowName, String queueColumn, Keyspace keyspace)
      throws CassandraDataAccessException {
    try {
      Mutator<String> mutator = HFactory.createMutator(keyspace, StringSerializer.get());
      mutator.deleteCounter(counterRowName, cfName, queueColumn, stringSerializer);
      mutator.execute();
      CounterQuery<String, String> counter =
          new ThriftCounterColumnQuery<String, String>(
              keyspace, stringSerializer, stringSerializer);

      counter.setColumnFamily(cfName).setKey(counterRowName).setName(queueColumn);
    } catch (Exception e) {
      throw new CassandraDataAccessException("Error while accessing:" + cfName, e);
    }
  }