Счетчик Ахиллеса Кассандры всегда нулевой

1

Я использую библиотеку Achilles для отображения объектов в Java. Ахиллес поддерживает счетчики Cassandra (ссылка), но проблема в том, что когда я делаю запрос select, значение поля типа Counter равно null.

Вот моя модель:

@Entity(table = "watchs_per_segment")
public class WatchsPerSegment {

    @EmbeddedId
    private Key key;

    @Column

    private Counter morning;
    @Column
    private Counter noon;
    @Column
    private Counter afternoon;
    @Column
    private Counter accesspt;
    @Column
    private Counter night;


    public WatchsPerSegment()
    {

    }


    public WatchsPerSegment(Key key, Counter morning, Counter noon,
            Counter afternoon, Counter accesspt, Counter night) {
        this.key = key;
        this.morning = morning;
        this.noon = noon;
        this.afternoon = afternoon;
        this.accesspt = accesspt;
        this.night = night;
    }
  //getters and setters


    public static class Key {
        @PartitionKey
        private String segment;

        @ClusteringColumn(value = 1, reversed = true)
        private Date day;

        @ClusteringColumn(2)
        private boolean afterreco;

        public Key() {
        }

        public Key(String segment, Date day, boolean afterreco) {
            this.segment = segment;
            this.day = day;
            this.afterreco = afterreco;
        }

        //getter and setter

}

Запрос:

     List<WatchsPerSegment> watchs = manager
     .sliceQuery(WatchsPerSegment.class).forSelect()
     .withPartitionComponents("253")
     .fromClusterings(new Date(2014, 11, 07), true).get();

Я напечатал результат, и все счетчики были пустыми:

WatchsPerSegment [key=Key [segment=253, day=Thu Nov 07 00:00:00 CET 2014, afterreco=true], morning=null, noon=null, afternoon=null, accesspt=null, night=null]

Это ошибка Ахиллеса или проблема с моей моделью?

  • 1
    Не видя вашего запроса, схемы или каких-либо подробностей, вам будет сложно ответить.
  • 0
    Вы правы, я обновил свой вопрос
Теги:
cassandra

1 ответ

0

Вам нужно вызвать команду CQL UPDATE, чтобы включить данные счетчика.

Счетчик CQL - это специальный тип столбца. Чтобы счетчик работал, нужно соблюдать определенные правила. Это псевдокод....

//construct key object
Key key = new Key();

// use the key obejct to update a record
// it is ok that this key is new. C* will upsert a record
WatchsPerSegment countRec=cqlDao.findReference(WatchsPerSegment.class, key);
countRec.getNoon().incr();  // increase noon counter
cqlDao.update(countRec);    // this is upsert

// now you can get the counter
WatchsPerSegment counter = cqlDao.find(WatchsPerSegment.class, key);
Long id=counter.getNoon().get();
// id is the counter value

Ещё вопросы

Сообщество Overcoder
Наверх
Меню