@SuppressWarnings("unchecked") @Test public void testExecute() { final long activityId = 6790L; final long personId = 99L; Query q = getEntityManager().createQuery( "FROM LikedActivity where personId=:personId and activityId=:activityId").setParameter("personId", personId).setParameter("activityId", activityId); List<LikedActivity> results = q.getResultList(); assertTrue(results.size() == 0); String key = CacheKeys.LIKED_BY_PERSON_ID + personId; assertTrue(insertLikedActivity.getCache().getList(key) == null); assertTrue(insertLikedActivity.execute(new LikedActivity(personId, activityId))); assertTrue(q.getResultList().size() == 1); assertTrue(insertLikedActivity.getCache().getList(key) == null); }
public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "FROM LikedActivity where personId=:personId and activityId=:activityId").setParameter("personId", inLikedActivity.getPersonId()).setParameter("activityId", inLikedActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inLikedActivity); getCache().delete(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId()); getCache().addToTopOfList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }
InsertLikedActivity extends CachedDomainMapper { public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "FROM LikedActivity where personId=:personId and activityId=:activityId").setParameter("personId", inLikedActivity.getPersonId()).setParameter("activityId", inLikedActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inLikedActivity); getCache().delete(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId()); getCache().addToTopOfList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; } }
InsertLikedActivity extends CachedDomainMapper { public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "FROM LikedActivity where personId=:personId and activityId=:activityId").setParameter("personId", inLikedActivity.getPersonId()).setParameter("activityId", inLikedActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inLikedActivity); getCache().delete(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId()); getCache().addToTopOfList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }  }
InsertLikedActivity extends CachedDomainMapper { public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "FROM LikedActivity where personId=:personId and activityId=:activityId").setParameter("personId", inLikedActivity.getPersonId()).setParameter("activityId", inLikedActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inLikedActivity); getCache().delete(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId()); getCache().addToTopOfList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }  Boolean execute(final LikedActivity inLikedActivity); }
InsertLikedActivity extends CachedDomainMapper { public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "FROM LikedActivity where personId=:personId and activityId=:activityId").setParameter("personId", inLikedActivity.getPersonId()).setParameter("activityId", inLikedActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inLikedActivity); getCache().delete(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId()); getCache().addToTopOfList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }  Boolean execute(final LikedActivity inLikedActivity);  }