@SuppressWarnings("unchecked") @Test public void testExecute() { List<GroupFollower> gf = getEntityManager().createQuery( "FROM GroupFollower gf WHERE gf.pk.followerId=:followerId").setParameter("followerId", fordId) .getResultList(); assertEquals(3, gf.size()); assertEquals(1, gf.get(0).getFollowingId()); assertEquals(2, gf.get(1).getFollowingId()); assertEquals(3, gf.get(2).getFollowingId()); getEntityManager().createQuery("UPDATE VERSIONED Person SET groupsCount = followingGroup.size WHERE id = :id") .setParameter("id", fordId).executeUpdate(); Integer fordGroupCount = (Integer) getEntityManager().createQuery( "SELECT p.groupsCount FROM Person p WHERE p.id = :id").setParameter("id", fordId).getResultList() .get(0); assertEquals(3, fordGroupCount.intValue()); List<GroupFollower> burnsGf = getEntityManager().createQuery( "FROM GroupFollower gf WHERE gf.pk.followerId=:followerId").setParameter("followerId", burnsId) .getResultList(); assertEquals(1, burnsGf.size()); getEntityManager().createQuery("UPDATE VERSIONED Person SET groupsCount = followingGroup.size WHERE id = :id") .setParameter("id", burnsId).executeUpdate(); Integer burnsGroupCount = (Integer) getEntityManager().createQuery( "SELECT p.groupsCount FROM Person p WHERE p.id = :id").setParameter("id", burnsId).getResultList().get( 0); assertEquals(1, burnsGroupCount.intValue()); List<Long> followerIds = sut.execute(groupId); getEntityManager().flush(); getEntityManager().clear(); assertEquals(3, followerIds.size()); assertTrue(followerIds.contains(burnsId)); assertTrue(followerIds.contains(smithersId)); assertTrue(followerIds.contains(fordId)); gf = getEntityManager().createQuery("FROM GroupFollower gf WHERE gf.pk.followerId=:followerId").setParameter( "followerId", fordId).getResultList(); assertEquals(2, gf.size()); assertEquals(2, gf.get(0).getFollowingId()); assertEquals(3, gf.get(1).getFollowingId()); fordGroupCount = (Integer) getEntityManager() .createQuery("SELECT p.groupsCount FROM Person p WHERE p.id = :id").setParameter("id", fordId) .getResultList().get(0); assertEquals(2, fordGroupCount.intValue()); burnsGf = getEntityManager().createQuery("FROM GroupFollower gf WHERE gf.pk.followerId=:followerId") .setParameter("followerId", burnsId).getResultList(); assertEquals(0, burnsGf.size()); burnsGroupCount = (Integer) getEntityManager().createQuery( "SELECT p.groupsCount FROM Person p WHERE p.id = :id").setParameter("id", burnsId).getResultList().get( 0); assertEquals(0, burnsGroupCount.intValue()); }
@SuppressWarnings("unchecked") @Override public List<Long> execute(final Long inRequest) { List<Long> followerIds = getEntityManager().createQuery( "SELECT gf1.pk.followerId FROM GroupFollower gf1 " + "WHERE gf1.pk.followingId=:followingId") .setParameter("followingId", inRequest).getResultList(); getEntityManager().createQuery( "UPDATE VERSIONED Person SET groupsCount = followingGroup.size - 1 WHERE id IN " + "(SELECT gf3.pk.followerId FROM GroupFollower gf3 WHERE gf3.pk.followingId=:followingId)") .setParameter("followingId", inRequest).executeUpdate(); getEntityManager().createQuery("DELETE FROM GroupFollower WHERE followingId=:followingId") .setParameter("followingId", inRequest).executeUpdate(); return followerIds; }
RemoveGroupFollowers extends BaseArgDomainMapper<Long, List<Long>> { @SuppressWarnings("unchecked") @Override public List<Long> execute(final Long inRequest) { List<Long> followerIds = getEntityManager().createQuery( "SELECT gf1.pk.followerId FROM GroupFollower gf1 " + "WHERE gf1.pk.followingId=:followingId") .setParameter("followingId", inRequest).getResultList(); getEntityManager().createQuery( "UPDATE VERSIONED Person SET groupsCount = followingGroup.size - 1 WHERE id IN " + "(SELECT gf3.pk.followerId FROM GroupFollower gf3 WHERE gf3.pk.followingId=:followingId)") .setParameter("followingId", inRequest).executeUpdate(); getEntityManager().createQuery("DELETE FROM GroupFollower WHERE followingId=:followingId") .setParameter("followingId", inRequest).executeUpdate(); return followerIds; } }
RemoveGroupFollowers extends BaseArgDomainMapper<Long, List<Long>> { @SuppressWarnings("unchecked") @Override public List<Long> execute(final Long inRequest) { List<Long> followerIds = getEntityManager().createQuery( "SELECT gf1.pk.followerId FROM GroupFollower gf1 " + "WHERE gf1.pk.followingId=:followingId") .setParameter("followingId", inRequest).getResultList(); getEntityManager().createQuery( "UPDATE VERSIONED Person SET groupsCount = followingGroup.size - 1 WHERE id IN " + "(SELECT gf3.pk.followerId FROM GroupFollower gf3 WHERE gf3.pk.followingId=:followingId)") .setParameter("followingId", inRequest).executeUpdate(); getEntityManager().createQuery("DELETE FROM GroupFollower WHERE followingId=:followingId") .setParameter("followingId", inRequest).executeUpdate(); return followerIds; }  }
RemoveGroupFollowers extends BaseArgDomainMapper<Long, List<Long>> { @SuppressWarnings("unchecked") @Override public List<Long> execute(final Long inRequest) { List<Long> followerIds = getEntityManager().createQuery( "SELECT gf1.pk.followerId FROM GroupFollower gf1 " + "WHERE gf1.pk.followingId=:followingId") .setParameter("followingId", inRequest).getResultList(); getEntityManager().createQuery( "UPDATE VERSIONED Person SET groupsCount = followingGroup.size - 1 WHERE id IN " + "(SELECT gf3.pk.followerId FROM GroupFollower gf3 WHERE gf3.pk.followingId=:followingId)") .setParameter("followingId", inRequest).executeUpdate(); getEntityManager().createQuery("DELETE FROM GroupFollower WHERE followingId=:followingId") .setParameter("followingId", inRequest).executeUpdate(); return followerIds; }  @SuppressWarnings("unchecked") @Override List<Long> execute(final Long inRequest); }
RemoveGroupFollowers extends BaseArgDomainMapper<Long, List<Long>> { @SuppressWarnings("unchecked") @Override public List<Long> execute(final Long inRequest) { List<Long> followerIds = getEntityManager().createQuery( "SELECT gf1.pk.followerId FROM GroupFollower gf1 " + "WHERE gf1.pk.followingId=:followingId") .setParameter("followingId", inRequest).getResultList(); getEntityManager().createQuery( "UPDATE VERSIONED Person SET groupsCount = followingGroup.size - 1 WHERE id IN " + "(SELECT gf3.pk.followerId FROM GroupFollower gf3 WHERE gf3.pk.followingId=:followingId)") .setParameter("followingId", inRequest).executeUpdate(); getEntityManager().createQuery("DELETE FROM GroupFollower WHERE followingId=:followingId") .setParameter("followingId", inRequest).executeUpdate(); return followerIds; }  @SuppressWarnings("unchecked") @Override List<Long> execute(final Long inRequest);  }