Ejemplo n.º 1
0
  public static List<String> getDestinationQueueNamesFromCounterColumns(
      String columnFamilyName, String rowName, Keyspace keyspace)
      throws CassandraDataAccessException {
    ArrayList<String> rowList = new ArrayList<String>();

    if (keyspace == null) {
      throw new CassandraDataAccessException("Can't access Data , no keyspace provided ");
    }

    if (columnFamilyName == null || rowName == null) {
      throw new CassandraDataAccessException(
          "Can't access data with columnFamily =" + columnFamilyName + " and rowName=" + rowName);
    }

    try {

      SliceCounterQuery<String, String> sliceQuery =
          HFactory.createCounterSliceQuery(keyspace, stringSerializer, stringSerializer);
      sliceQuery.setKey(rowName);
      sliceQuery.setColumnFamily(columnFamilyName);
      sliceQuery.setRange("", "", false, Integer.MAX_VALUE);

      QueryResult<CounterSlice<String>> result = sliceQuery.execute();
      CounterSlice<String> columnSlice = result.get();
      for (HCounterColumn<String> column : columnSlice.getColumns()) {
        rowList.add(column.getName());
      }
    } catch (Exception e) {
      throw new CassandraDataAccessException(
          "Error while accessing data from :" + columnFamilyName, e);
    }
    return rowList;
  }
Ejemplo n.º 2
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);
   }
 }