@Test public void testFindNotificationsByTopicIdAndVersionAndStartSecNum() throws Exception { String topicId = UUID.randomUUID().toString(); List<NotificationDto> expectedList = new ArrayList<>(); expectedList.addAll(generateNotifications(topicId, null, null, 7, NotificationTypeDto.USER)); List<CassandraNotification> foundList = notificationDao.findNotificationsByTopicIdAndVersionAndStartSecNum(topicId, 3, 0, 1); Assert.assertEquals(3, foundList.size()); for (int i = 0; i < foundList.size(); i++) { CassandraNotification notification = foundList.get(i); Assert.assertEquals(NotificationTypeDto.USER, notification.getType()); Assert.assertEquals(topicId, notification.getTopicId()); Assert.assertTrue(3 < notification.getSeqNum()); } }
@Override public CassandraNotification findById(String id) { LOG.debug("Try to find notification by id {}", id); CassandraNotification nf = new CassandraNotification(id); Where query = select().from(getColumnFamilyName()) .where(eq(NF_TOPIC_ID_PROPERTY, nf.getTopicId())) .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, nf.getType().name())) .and(eq(NF_VERSION_PROPERTY, nf.getNfVersion())) .and(eq(NF_SEQ_NUM_PROPERTY, nf.getSeqNum())); LOG.trace("Execute query {}", query); nf = findOneByStatement(query); LOG.trace("Found notification {} by id {}", nf, id); return nf; }
@Override public void removeById(String id) { LOG.debug("Remove notification by id {}", id); CassandraNotification nf = new CassandraNotification(id); Delete.Where deleteQuery = delete().from(getColumnFamilyName()) .where(eq(NF_TOPIC_ID_PROPERTY, nf.getTopicId())) .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, nf.getType().name())) .and(eq(NF_VERSION_PROPERTY, nf.getNfVersion())) .and(eq(NF_SEQ_NUM_PROPERTY, nf.getSeqNum())); LOG.trace("Remove notification by id {}", deleteQuery); execute(deleteQuery); }