@Override public CassandraEndpointNotification save(EndpointNotificationDto dto) { CassandraEndpointNotification endpointNotification = new CassandraEndpointNotification(dto); LOG.debug("Save endpoint notification for endpoint profile {}", Utils.encodeHexString(endpointNotification.getEndpointKeyHash())); save(new CassandraEndpointNotification(dto)); LOG.trace("Saved endpoint notification {}", endpointNotification); return endpointNotification; }
@Override public CassandraEndpointNotification findById(String id) { LOG.debug("Try to find endpoint notifications by id {}", id); CassandraEndpointNotification key = new CassandraEndpointNotification(id); Select.Where where = select().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, key.getEndpointKeyHash())) .and(eq(ET_NF_LAST_MOD_TIME_PROPERTY, key.getLastModifyTime())); LOG.debug("[{}] Execute query {}:", id, where); CassandraEndpointNotification endpointNotification = findOneByStatement(where); LOG.trace("Found endpoint notification {} by id {}:", endpointNotification, id); return endpointNotification; }
@Override public void removeById(String id) { LOG.debug("Remove endpoint notifications by id {}", id); CassandraEndpointNotification key = new CassandraEndpointNotification(id); Statement delete = delete().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, key.getEndpointKeyHash())) .and(eq(ET_NF_LAST_MOD_TIME_PROPERTY, key.getLastModifyTime())); execute(delete); LOG.debug("[{}] Execute query {}:", id, delete); }
@Test public void testDtoConversation() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 1).get(0); Assert.assertNull(notification.getId()); EndpointNotificationDto notificationDto = notification.toDto(); CassandraEndpointNotification cassandraEndpointNotification = new CassandraEndpointNotification(notificationDto); Assert.assertEquals(notificationDto, cassandraEndpointNotification.toDto()); }
protected List<CassandraEndpointNotification> generateEndpointNotification(ByteBuffer endpointKeyHash, int count) { List<CassandraEndpointNotification> savedNotifications = new ArrayList<>(); String appId = generateStringId(); if (endpointKeyHash == null) { endpointKeyHash = ByteBuffer.wrap(generateEndpointProfile(appId, null, null, null).getEndpointKeyHash()); } String schemaId = generateStringId(); for (int i = 0; i < count; i++) { CassandraEndpointNotification endpointNotification = new CassandraEndpointNotification(); endpointNotification.setEndpointKeyHash(endpointKeyHash); endpointNotification.setApplicationId(appId); endpointNotification.setSchemaId(schemaId); endpointNotification.setType(NotificationTypeDto.USER); endpointNotification.setSeqNum(100 + i); endpointNotification.setLastModifyTime(new Date(System.currentTimeMillis())); savedNotifications.add(unicastNotificationDao.save(endpointNotification)); } return savedNotifications; }