/** * Delete the entry from wall. * * @param followEntry */ public void deleteEntry(String username, String id) { try { // find name of super column using reverse mapping from id to time UUID uuid = UUIDUtil.fromString(id); final byte[] idAsBytes = UUIDUtil.toBytes(uuid); byte[] timeUUIDAsBytes = getTimeUUIDFromID(username, idAsBytes); if (timeUUIDAsBytes == null) { throw new TrendOceanException("Can not find time uuid " + username + ":" + id); } // delete super column from wall cf Mutator mutator = Pelops.createMutator(TRENDOCEAN_POOL, TRENDOCEAN_KEYSPACE); mutator.deleteColumn(username, WALL_CF, timeUUIDAsBytes); // also delete from reverse mapping from id to time mutator.deleteColumn(username, ID_TO_TIMEUUID_CF, idAsBytes); mutator.execute(ConsistencyLevel.QUORUM); } catch (Exception ex) { logger.error("Can not delete follow entry", username + ":" + id, ex); throw new TrendOceanException(ex); } }
/** Add a new comment entry for a user. */ public void addNotification( String username, String relatedUser, String questionId, long answerCount, NotificationType notificationType) { try { Mutator mutator = Pelops.createMutator(TRENDOCEAN_POOL, TRENDOCEAN_KEYSPACE); byte[] timeUUIDBytes = UUIDUtil.toBytes(UUIDUtil.getTimeUUID()); UUID id = UUIDUtil.getRandomUUID(); byte[] idAsBytes = UUIDUtil.toBytes(id); // add new notification if (notificationType == NotificationType.COMMENT || notificationType == NotificationType.LIKE || notificationType == NotificationType.MENTION) { mutator.writeSubColumns( username, WALL_CF, timeUUIDBytes, mutator.newColumnList( mutator.newColumn("_id", idAsBytes), mutator.newColumn("_type", toBytes(notificationType.getId())), mutator.newColumn("questionId", toBytes(questionId)), mutator.newColumn("relatedUser", relatedUser))); } else if (notificationType == NotificationType.NEW_FOLLOWER || notificationType == NotificationType.FOLLOW_REQUEST_ACCEPT) { mutator.writeSubColumns( username, WALL_CF, timeUUIDBytes, mutator.newColumnList( mutator.newColumn("_id", idAsBytes), mutator.newColumn("_type", toBytes(notificationType.getId())), mutator.newColumn("relatedUser", relatedUser))); } else if (notificationType == NotificationType.ANSWER_COUNT) { mutator.writeSubColumns( username, WALL_CF, timeUUIDBytes, mutator.newColumnList( mutator.newColumn("_id", idAsBytes), mutator.newColumn("_type", toBytes(notificationType.getId())), mutator.newColumn("questionId", toBytes(questionId)), mutator.newColumn("answerCount", toBytes(answerCount)))); } // write reverse mapping for delete mutator.writeColumn(username, ID_TO_TIMEUUID_CF, mutator.newColumn(idAsBytes, timeUUIDBytes)); mutator.execute(ConsistencyLevel.QUORUM); } catch (Exception ex) { logger.error("Can not add follow entry", username + ":" + questionId, ex); throw new TrendOceanException(ex); } }