@Test public void testRemoveFollower() { Person smithers = jpaPersonMapper.findByAccountId("smithers"); Person burns = jpaPersonMapper.findByAccountId("mrburns"); assertEquals("burns should have 1 follower", 1, burns.getFollowersCount()); assertEquals("burns should not be following any", 0, burns.getFollowingCount()); assertEquals("smithers should have no followers", 0, smithers.getFollowersCount()); assertEquals("smithers should be following burns", 1, smithers.getFollowingCount()); jpaPersonMapper.removeFollower(smithers.getId(), burns.getId()); getEntityManager().clear(); smithers = jpaPersonMapper.findByAccountId("smithers"); burns = jpaPersonMapper.findByAccountId("mrburns"); assertEquals("followers/followings should be 0 after removal", 0, smithers.getFollowersCount()); assertEquals("followers/followings should be 0 after removal", 0, smithers.getFollowingCount()); assertEquals("followers/followings should be 0 after removal", 0, burns.getFollowersCount()); assertEquals("burns followings should be 0 after removal", 0, burns.getFollowingCount()); Person ford = jpaPersonMapper.findByAccountId("fordp"); Person sagan = jpaPersonMapper.findByAccountId("csagan"); jpaPersonMapper.removeFollower(ford.getId(), sagan.getId()); getEntityManager().clear(); ford = jpaPersonMapper.findByAccountId("fordp"); sagan = jpaPersonMapper.findByAccountId("csagan"); assertEquals("followers/followings should be 0 after removal", 0, smithers.getFollowersCount()); assertEquals("followers/followings should be 0 after removal", 0, smithers.getFollowingCount()); assertEquals("followers/followings should be 0 after removal", 0, burns.getFollowersCount()); assertEquals("burns followings should be 0 after removal", 0, burns.getFollowingCount()); }
public void removeFollower(final long followerId, final long followingId) { int rowsDeleted = getEntityManager().createQuery( "DELETE FROM Follower where followerId=:followerId and followingId=:followingId").setParameter( "followerId", followerId).setParameter("followingId", followingId).executeUpdate(); if (rowsDeleted == 0) { return; } getEntityManager().createQuery( "update versioned Person set followingCount = following.size - 1 " + "where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager().createQuery( "update versioned Person set followersCount = followers.size - 1 where id=:followingId").setParameter( "followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); Person followingEntity = findById(followingId); getFullTextSession().index(followingEntity); }
PersonMapper extends DomainEntityMapper<Person> implements FollowMapper { public void removeFollower(final long followerId, final long followingId) { int rowsDeleted = getEntityManager().createQuery( "DELETE FROM Follower where followerId=:followerId and followingId=:followingId").setParameter( "followerId", followerId).setParameter("followingId", followingId).executeUpdate(); if (rowsDeleted == 0) { return; } getEntityManager().createQuery( "update versioned Person set followingCount = following.size - 1 " + "where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager().createQuery( "update versioned Person set followersCount = followers.size - 1 where id=:followingId").setParameter( "followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); Person followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } }
PersonMapper extends DomainEntityMapper<Person> implements FollowMapper { public void removeFollower(final long followerId, final long followingId) { int rowsDeleted = getEntityManager().createQuery( "DELETE FROM Follower where followerId=:followerId and followingId=:followingId").setParameter( "followerId", followerId).setParameter("followingId", followingId).executeUpdate(); if (rowsDeleted == 0) { return; } getEntityManager().createQuery( "update versioned Person set followingCount = following.size - 1 " + "where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager().createQuery( "update versioned Person set followersCount = followers.size - 1 where id=:followingId").setParameter( "followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); Person followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } PersonMapper(final QueryOptimizer inQueryOptimizer); }
PersonMapper extends DomainEntityMapper<Person> implements FollowMapper { public void removeFollower(final long followerId, final long followingId) { int rowsDeleted = getEntityManager().createQuery( "DELETE FROM Follower where followerId=:followerId and followingId=:followingId").setParameter( "followerId", followerId).setParameter("followingId", followingId).executeUpdate(); if (rowsDeleted == 0) { return; } getEntityManager().createQuery( "update versioned Person set followingCount = following.size - 1 " + "where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager().createQuery( "update versioned Person set followersCount = followers.size - 1 where id=:followingId").setParameter( "followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); Person followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } PersonMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") Person findByAccountId(final String accountId); @SuppressWarnings("unchecked") Person findByOpenSocialId(final String openSocialId); void addFollower(final long followerId, final long followingId); void removeFollower(final long followerId, final long followingId); PagedSet<Person> getFollowers(final String accountId, final int start, final int end); PagedSet<Followable> getFollowing(final String accountId, final int start, final int end); @SuppressWarnings("unchecked") boolean isFollowing(final String followerAccountId, final String followingAccountId); @SuppressWarnings("unchecked") List<Person> findPeopleByPrefix(final String prefix); @SuppressWarnings("unchecked") List<Person> findPeopleByOpenSocialIds(final List<String> openSocialIds); @SuppressWarnings("unchecked") List<Person> findPeopleFollowedUsingFollowerOpenSocialIds(final List<String> openSocialIds); }
PersonMapper extends DomainEntityMapper<Person> implements FollowMapper { public void removeFollower(final long followerId, final long followingId) { int rowsDeleted = getEntityManager().createQuery( "DELETE FROM Follower where followerId=:followerId and followingId=:followingId").setParameter( "followerId", followerId).setParameter("followingId", followingId).executeUpdate(); if (rowsDeleted == 0) { return; } getEntityManager().createQuery( "update versioned Person set followingCount = following.size - 1 " + "where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager().createQuery( "update versioned Person set followersCount = followers.size - 1 where id=:followingId").setParameter( "followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); Person followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } PersonMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") Person findByAccountId(final String accountId); @SuppressWarnings("unchecked") Person findByOpenSocialId(final String openSocialId); void addFollower(final long followerId, final long followingId); void removeFollower(final long followerId, final long followingId); PagedSet<Person> getFollowers(final String accountId, final int start, final int end); PagedSet<Followable> getFollowing(final String accountId, final int start, final int end); @SuppressWarnings("unchecked") boolean isFollowing(final String followerAccountId, final String followingAccountId); @SuppressWarnings("unchecked") List<Person> findPeopleByPrefix(final String prefix); @SuppressWarnings("unchecked") List<Person> findPeopleByOpenSocialIds(final List<String> openSocialIds); @SuppressWarnings("unchecked") List<Person> findPeopleFollowedUsingFollowerOpenSocialIds(final List<String> openSocialIds);  }