@Test public void testAddFollowerWhenAlreadyFollowing() { final long personId = 99L; final long groupId = 1L; Person p = jpaPersonMapper.findById(personId); DomainGroup g = jpaGroupMapper.findById(groupId); int initialGroupsCount = p.getGroupCount(); int initialFollowersCount = g.getFollowersCount(); jpaGroupMapper.addFollower(p.getId(), g.getId()); getEntityManager().clear(); p = jpaPersonMapper.findById(personId); g = jpaGroupMapper.findById(groupId); assertEquals(initialGroupsCount, p.getGroupCount()); assertEquals(initialFollowersCount, g.getFollowersCount()); }
public void addFollower(final long followerId, final long followingId) { Query q = getEntityManager() .createQuery("FROM GroupFollower where followerId=:followerId and followingId=:followingId") .setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new GroupFollower(followerId, followingId)); getEntityManager() .createQuery( "update versioned Person set groupsCount = followingGroup.size," + " groupStreamHiddenLineIndex = groupStreamHiddenLineIndex + 1 where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager() .createQuery("update versioned DomainGroup set followersCount = followers.size where id=:followingId") .setParameter("followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); DomainGroup followingEntity = findById(followingId); getFullTextSession().index(followingEntity); }
DomainGroupMapper extends DomainEntityMapper<DomainGroup> implements FollowMapper, CompositeEntityMapper { public void addFollower(final long followerId, final long followingId) { Query q = getEntityManager() .createQuery("FROM GroupFollower where followerId=:followerId and followingId=:followingId") .setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new GroupFollower(followerId, followingId)); getEntityManager() .createQuery( "update versioned Person set groupsCount = followingGroup.size," + " groupStreamHiddenLineIndex = groupStreamHiddenLineIndex + 1 where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager() .createQuery("update versioned DomainGroup set followersCount = followers.size where id=:followingId") .setParameter("followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); DomainGroup followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } }
DomainGroupMapper extends DomainEntityMapper<DomainGroup> implements FollowMapper, CompositeEntityMapper { public void addFollower(final long followerId, final long followingId) { Query q = getEntityManager() .createQuery("FROM GroupFollower where followerId=:followerId and followingId=:followingId") .setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new GroupFollower(followerId, followingId)); getEntityManager() .createQuery( "update versioned Person set groupsCount = followingGroup.size," + " groupStreamHiddenLineIndex = groupStreamHiddenLineIndex + 1 where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager() .createQuery("update versioned DomainGroup set followersCount = followers.size where id=:followingId") .setParameter("followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); DomainGroup followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } DomainGroupMapper(final QueryOptimizer inQueryOptimizer); }
DomainGroupMapper extends DomainEntityMapper<DomainGroup> implements FollowMapper, CompositeEntityMapper { public void addFollower(final long followerId, final long followingId) { Query q = getEntityManager() .createQuery("FROM GroupFollower where followerId=:followerId and followingId=:followingId") .setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new GroupFollower(followerId, followingId)); getEntityManager() .createQuery( "update versioned Person set groupsCount = followingGroup.size," + " groupStreamHiddenLineIndex = groupStreamHiddenLineIndex + 1 where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager() .createQuery("update versioned DomainGroup set followersCount = followers.size where id=:followingId") .setParameter("followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); DomainGroup followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } DomainGroupMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") DomainGroup findByShortName(final String groupShortName); void addFollower(final long followerId, final long followingId); PagedSet<Person> getFollowers(final String shortName, 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 shortName); void removeFollower(final long followerId, final long followingId); void removeGroupCoordinator(final long followerId, final long followingId); @SuppressWarnings("unchecked") Long[] getFollowerAndCoordinatorPersonIds(final DomainGroup domainGroup); void deleteById(final long id); boolean isInputUserGroupCoordinator(final long followerId, final long followingId); boolean isGroupPrivate(final long followingId); int getGroupCoordinatorCount(final long followingId); }
DomainGroupMapper extends DomainEntityMapper<DomainGroup> implements FollowMapper, CompositeEntityMapper { public void addFollower(final long followerId, final long followingId) { Query q = getEntityManager() .createQuery("FROM GroupFollower where followerId=:followerId and followingId=:followingId") .setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new GroupFollower(followerId, followingId)); getEntityManager() .createQuery( "update versioned Person set groupsCount = followingGroup.size," + " groupStreamHiddenLineIndex = groupStreamHiddenLineIndex + 1 where id=:followerId") .setParameter("followerId", followerId).executeUpdate(); getEntityManager() .createQuery("update versioned DomainGroup set followersCount = followers.size where id=:followingId") .setParameter("followingId", followingId).executeUpdate(); getEntityManager().flush(); getEntityManager().clear(); DomainGroup followingEntity = findById(followingId); getFullTextSession().index(followingEntity); } DomainGroupMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") DomainGroup findByShortName(final String groupShortName); void addFollower(final long followerId, final long followingId); PagedSet<Person> getFollowers(final String shortName, 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 shortName); void removeFollower(final long followerId, final long followingId); void removeGroupCoordinator(final long followerId, final long followingId); @SuppressWarnings("unchecked") Long[] getFollowerAndCoordinatorPersonIds(final DomainGroup domainGroup); void deleteById(final long id); boolean isInputUserGroupCoordinator(final long followerId, final long followingId); boolean isGroupPrivate(final long followingId); int getGroupCoordinatorCount(final long followingId);  }