@SuppressWarnings("unchecked") @Test public void testExecuteAlreadyPresent() { final long personId = 99L; final long activityId = 6789L; final long activityId2 = 54321L; Query q = getEntityManager().createQuery( "FROM LikedActivity where personId=:personId and activityId=:activityId"); q.setParameter("personId", personId); q.setParameter("activityId", activityId); List<LikedActivity> results = q.getResultList(); assertTrue(results.size() == 1); String key = CacheKeys.LIKED_BY_PERSON_ID + personId; List<Long> ids = new ArrayList<Long>(); ids.add(activityId); ids.add(activityId2); deleteLikedActivity.getCache().setList(key, ids); assertTrue(deleteLikedActivity.getCache().getList(key) != null); assertTrue(deleteLikedActivity.execute(new LikedActivity(personId, activityId))); assertTrue(q.getResultList().size() == 0); List<Long> cachedList = deleteLikedActivity.getCache().getList(key); assertFalse(cachedList.contains(activityId)); assertTrue(cachedList.contains(activityId2)); }
@SuppressWarnings("unchecked") public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "DELETE FROM LikedActivity where personId=:personId and activityId=:activityId"); q.setParameter("personId", inLikedActivity.getPersonId()); q.setParameter("activityId", inLikedActivity.getActivityId()); q.executeUpdate(); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId(), inLikedActivity.getActivityId()); getCache().removeFromList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }
DeleteLikedActivity extends CachedDomainMapper { @SuppressWarnings("unchecked") public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "DELETE FROM LikedActivity where personId=:personId and activityId=:activityId"); q.setParameter("personId", inLikedActivity.getPersonId()); q.setParameter("activityId", inLikedActivity.getActivityId()); q.executeUpdate(); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId(), inLikedActivity.getActivityId()); getCache().removeFromList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; } }
DeleteLikedActivity extends CachedDomainMapper { @SuppressWarnings("unchecked") public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "DELETE FROM LikedActivity where personId=:personId and activityId=:activityId"); q.setParameter("personId", inLikedActivity.getPersonId()); q.setParameter("activityId", inLikedActivity.getActivityId()); q.executeUpdate(); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId(), inLikedActivity.getActivityId()); getCache().removeFromList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }  }
DeleteLikedActivity extends CachedDomainMapper { @SuppressWarnings("unchecked") public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "DELETE FROM LikedActivity where personId=:personId and activityId=:activityId"); q.setParameter("personId", inLikedActivity.getPersonId()); q.setParameter("activityId", inLikedActivity.getActivityId()); q.executeUpdate(); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId(), inLikedActivity.getActivityId()); getCache().removeFromList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }  @SuppressWarnings("unchecked") Boolean execute(final LikedActivity inLikedActivity); }
DeleteLikedActivity extends CachedDomainMapper { @SuppressWarnings("unchecked") public Boolean execute(final LikedActivity inLikedActivity) { Query q = getEntityManager().createQuery( "DELETE FROM LikedActivity where personId=:personId and activityId=:activityId"); q.setParameter("personId", inLikedActivity.getPersonId()); q.setParameter("activityId", inLikedActivity.getActivityId()); q.executeUpdate(); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + inLikedActivity.getPersonId(), inLikedActivity.getActivityId()); getCache().removeFromList(CacheKeys.LIKERS_BY_ACTIVITY_ID + inLikedActivity.getActivityId(), inLikedActivity.getPersonId()); return Boolean.TRUE; }  @SuppressWarnings("unchecked") Boolean execute(final LikedActivity inLikedActivity);  }