Exemplo 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;
  }
Exemplo n.º 2
0
  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);
  }
Exemplo n.º 3
0
  public List<HCounterColumn<N>> findCounterColumnsRange(
      K key, N startName, N endName, int count, boolean reverse) {
    this.policy.loadConsistencyLevelForRead(columnFamily);

    List<HCounterColumn<N>> result;
    try {
      result =
          HFactory.createCounterSliceQuery(keyspace, keySerializer, columnNameSerializer)
              .setColumnFamily(columnFamily)
              .setKey(key)
              .setRange(startName, endName, reverse, count)
              .execute()
              .get()
              .getColumns();
    } catch (Throwable throwable) {
      throw new RuntimeException(throwable);
    } finally {
      this.policy.reinitDefaultConsistencyLevel();
    }
    return result;
  }