@Test public void testAddFollower() { Person ford = jpaPersonMapper.findByAccountId("fordp"); Person sagan = jpaPersonMapper.findByAccountId("csagan"); assertEquals("followers/followings should be 0 initially", 0, ford.getFollowersCount()); assertEquals("followers/followings should be 0 initially", 0, ford.getFollowingCount()); assertEquals("followers/followings should be 0 initially", 0, sagan.getFollowersCount()); assertEquals("followers/followings should be 0 initially", 0, sagan.getFollowingCount()); jpaPersonMapper.addFollower(ford.getId(), sagan.getId()); getEntityManager().clear(); ford = jpaPersonMapper.findByAccountId("fordp"); sagan = jpaPersonMapper.findByAccountId("csagan"); assertEquals("sagan should have 1 follower", 1, sagan.getFollowersCount()); assertEquals("sagan follows no one", 0, sagan.getFollowingCount()); assertEquals("ford should have no followers", 0, ford.getFollowersCount()); assertEquals("ford should be following sagan", 1, ford.getFollowingCount()); jpaPersonMapper.addFollower(ford.getId(), sagan.getId()); getEntityManager().clear(); ford = jpaPersonMapper.findByAccountId("fordp"); sagan = jpaPersonMapper.findByAccountId("csagan"); assertEquals("Followers count changed after duplicate add.", 1, sagan.getFollowersCount()); assertEquals("Following count changed after duplicate add", 0, sagan.getFollowingCount()); assertEquals("follower's Followers count changed after duplicate add.", 0, ford.getFollowersCount()); assertEquals("follower's Following count changed after duplicate add", 1, ford.getFollowingCount()); }
public void addFollower(final long followerId, final long followingId) { Query q = getEntityManager().createQuery( "FROM Follower where followerId=:followerId and followingId=:followingId").setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new Follower(followerId, followingId)); 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 addFollower(final long followerId, final long followingId) { Query q = getEntityManager().createQuery( "FROM Follower where followerId=:followerId and followingId=:followingId").setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new Follower(followerId, followingId)); 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 addFollower(final long followerId, final long followingId) { Query q = getEntityManager().createQuery( "FROM Follower where followerId=:followerId and followingId=:followingId").setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new Follower(followerId, followingId)); 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 addFollower(final long followerId, final long followingId) { Query q = getEntityManager().createQuery( "FROM Follower where followerId=:followerId and followingId=:followingId").setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new Follower(followerId, followingId)); 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 addFollower(final long followerId, final long followingId) { Query q = getEntityManager().createQuery( "FROM Follower where followerId=:followerId and followingId=:followingId").setParameter("followerId", followerId).setParameter("followingId", followingId); if (q.getResultList().size() > 0) { return; } getEntityManager().persist(new Follower(followerId, followingId)); 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);  }