@Test public void testDeletingFeedSubscriptionUntilNoneLeftForFeed() { final Long feedSubscriptionId1 = 1L; final Long feedSubscriptionId2 = 6L; final Long feedSubscriptionId3 = 8L; final Long feedId = 1L; Assert.assertTrue(feedExists(feedId)); Assert.assertEquals(3, subscriberCount(feedId)); flush(); sut.execute(feedSubscriptionId1); Assert.assertTrue(feedExists(feedId)); Assert.assertEquals(2, subscriberCount(feedId)); flush(); sut.execute(feedSubscriptionId2); Assert.assertTrue(feedExists(feedId)); Assert.assertEquals(1, subscriberCount(feedId)); flush(); sut.execute(feedSubscriptionId3); Assert.assertFalse(feedExists(feedId)); Assert.assertEquals(0, subscriberCount(feedId)); }
@Override public Boolean execute(final Long inFeedSubscriberId) { Long feedId; FeedSubscriber subscriber; subscriber = (FeedSubscriber) getEntityManager().createQuery("FROM FeedSubscriber WHERE id = :id") .setParameter("id", inFeedSubscriberId).getSingleResult(); feedId = subscriber.getFeed().getId(); getEntityManager().remove(subscriber); getEntityManager().flush(); Long subscriberCount = (Long) getEntityManager() .createQuery("SELECT COUNT(elements(feedSubscribers)) FROM Feed WHERE id = :id") .setParameter("id", feedId).getSingleResult(); if (subscriberCount == 0) { log.info("Deleting feed - no more subscribers - id: " + feedId); getEntityManager().createQuery("DELETE FROM Feed WHERE id = :id").setParameter("id", feedId) .executeUpdate(); getEntityManager().flush(); } return Boolean.TRUE; }
DeleteFeedSubscriberMapper extends BaseArgDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inFeedSubscriberId) { Long feedId; FeedSubscriber subscriber; subscriber = (FeedSubscriber) getEntityManager().createQuery("FROM FeedSubscriber WHERE id = :id") .setParameter("id", inFeedSubscriberId).getSingleResult(); feedId = subscriber.getFeed().getId(); getEntityManager().remove(subscriber); getEntityManager().flush(); Long subscriberCount = (Long) getEntityManager() .createQuery("SELECT COUNT(elements(feedSubscribers)) FROM Feed WHERE id = :id") .setParameter("id", feedId).getSingleResult(); if (subscriberCount == 0) { log.info("Deleting feed - no more subscribers - id: " + feedId); getEntityManager().createQuery("DELETE FROM Feed WHERE id = :id").setParameter("id", feedId) .executeUpdate(); getEntityManager().flush(); } return Boolean.TRUE; } }
DeleteFeedSubscriberMapper extends BaseArgDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inFeedSubscriberId) { Long feedId; FeedSubscriber subscriber; subscriber = (FeedSubscriber) getEntityManager().createQuery("FROM FeedSubscriber WHERE id = :id") .setParameter("id", inFeedSubscriberId).getSingleResult(); feedId = subscriber.getFeed().getId(); getEntityManager().remove(subscriber); getEntityManager().flush(); Long subscriberCount = (Long) getEntityManager() .createQuery("SELECT COUNT(elements(feedSubscribers)) FROM Feed WHERE id = :id") .setParameter("id", feedId).getSingleResult(); if (subscriberCount == 0) { log.info("Deleting feed - no more subscribers - id: " + feedId); getEntityManager().createQuery("DELETE FROM Feed WHERE id = :id").setParameter("id", feedId) .executeUpdate(); getEntityManager().flush(); } return Boolean.TRUE; }  }
DeleteFeedSubscriberMapper extends BaseArgDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inFeedSubscriberId) { Long feedId; FeedSubscriber subscriber; subscriber = (FeedSubscriber) getEntityManager().createQuery("FROM FeedSubscriber WHERE id = :id") .setParameter("id", inFeedSubscriberId).getSingleResult(); feedId = subscriber.getFeed().getId(); getEntityManager().remove(subscriber); getEntityManager().flush(); Long subscriberCount = (Long) getEntityManager() .createQuery("SELECT COUNT(elements(feedSubscribers)) FROM Feed WHERE id = :id") .setParameter("id", feedId).getSingleResult(); if (subscriberCount == 0) { log.info("Deleting feed - no more subscribers - id: " + feedId); getEntityManager().createQuery("DELETE FROM Feed WHERE id = :id").setParameter("id", feedId) .executeUpdate(); getEntityManager().flush(); } return Boolean.TRUE; }  @Override Boolean execute(final Long inFeedSubscriberId); }
DeleteFeedSubscriberMapper extends BaseArgDomainMapper<Long, Boolean> { @Override public Boolean execute(final Long inFeedSubscriberId) { Long feedId; FeedSubscriber subscriber; subscriber = (FeedSubscriber) getEntityManager().createQuery("FROM FeedSubscriber WHERE id = :id") .setParameter("id", inFeedSubscriberId).getSingleResult(); feedId = subscriber.getFeed().getId(); getEntityManager().remove(subscriber); getEntityManager().flush(); Long subscriberCount = (Long) getEntityManager() .createQuery("SELECT COUNT(elements(feedSubscribers)) FROM Feed WHERE id = :id") .setParameter("id", feedId).getSingleResult(); if (subscriberCount == 0) { log.info("Deleting feed - no more subscribers - id: " + feedId); getEntityManager().createQuery("DELETE FROM Feed WHERE id = :id").setParameter("id", feedId) .executeUpdate(); getEntityManager().flush(); } return Boolean.TRUE; }  @Override Boolean execute(final Long inFeedSubscriberId);  }