@SuppressWarnings("unchecked") @Test public void testExecute() { final long activityId = 6790L; final long personId = 99L; Query q = getEntityManager().createQuery( "FROM StarredActivity where personId=:personId and activityId=:activityId").setParameter("personId", personId).setParameter("activityId", activityId); List<StarredActivity> results = q.getResultList(); assertTrue(results.size() == 0); String key = CacheKeys.STARRED_BY_PERSON_ID + personId; assertTrue(insertStarredActivity.getCache().getList(key) == null); assertTrue(insertStarredActivity.execute(new StarredActivity(personId, activityId))); assertTrue(q.getResultList().size() == 1); assertTrue(insertStarredActivity.getCache().getList(key) != null); }
public Boolean execute(final StarredActivity inStarredActivity) { Query q = getEntityManager().createQuery( "FROM StarredActivity where personId=:personId and activityId=:activityId").setParameter("personId", inStarredActivity.getPersonId()).setParameter("activityId", inStarredActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inStarredActivity); String key = CacheKeys.STARRED_BY_PERSON_ID + inStarredActivity.getPersonId(); List<Long> starredIds = starredActivitiesMapper.execute(inStarredActivity.getPersonId()); if (starredIds == null) { starredIds = new LinkedList<Long>(); } starredIds.add(inStarredActivity.getActivityId()); Collections.sort(starredIds); Collections.reverse(starredIds); getCache().setList(key, starredIds); return Boolean.TRUE; }
InsertStarredActivity extends CachedDomainMapper { public Boolean execute(final StarredActivity inStarredActivity) { Query q = getEntityManager().createQuery( "FROM StarredActivity where personId=:personId and activityId=:activityId").setParameter("personId", inStarredActivity.getPersonId()).setParameter("activityId", inStarredActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inStarredActivity); String key = CacheKeys.STARRED_BY_PERSON_ID + inStarredActivity.getPersonId(); List<Long> starredIds = starredActivitiesMapper.execute(inStarredActivity.getPersonId()); if (starredIds == null) { starredIds = new LinkedList<Long>(); } starredIds.add(inStarredActivity.getActivityId()); Collections.sort(starredIds); Collections.reverse(starredIds); getCache().setList(key, starredIds); return Boolean.TRUE; } }
InsertStarredActivity extends CachedDomainMapper { public Boolean execute(final StarredActivity inStarredActivity) { Query q = getEntityManager().createQuery( "FROM StarredActivity where personId=:personId and activityId=:activityId").setParameter("personId", inStarredActivity.getPersonId()).setParameter("activityId", inStarredActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inStarredActivity); String key = CacheKeys.STARRED_BY_PERSON_ID + inStarredActivity.getPersonId(); List<Long> starredIds = starredActivitiesMapper.execute(inStarredActivity.getPersonId()); if (starredIds == null) { starredIds = new LinkedList<Long>(); } starredIds.add(inStarredActivity.getActivityId()); Collections.sort(starredIds); Collections.reverse(starredIds); getCache().setList(key, starredIds); return Boolean.TRUE; } InsertStarredActivity(final GetStarredActivityIds inStarredActivitiesMapper); }
InsertStarredActivity extends CachedDomainMapper { public Boolean execute(final StarredActivity inStarredActivity) { Query q = getEntityManager().createQuery( "FROM StarredActivity where personId=:personId and activityId=:activityId").setParameter("personId", inStarredActivity.getPersonId()).setParameter("activityId", inStarredActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inStarredActivity); String key = CacheKeys.STARRED_BY_PERSON_ID + inStarredActivity.getPersonId(); List<Long> starredIds = starredActivitiesMapper.execute(inStarredActivity.getPersonId()); if (starredIds == null) { starredIds = new LinkedList<Long>(); } starredIds.add(inStarredActivity.getActivityId()); Collections.sort(starredIds); Collections.reverse(starredIds); getCache().setList(key, starredIds); return Boolean.TRUE; } InsertStarredActivity(final GetStarredActivityIds inStarredActivitiesMapper); Boolean execute(final StarredActivity inStarredActivity); }
InsertStarredActivity extends CachedDomainMapper { public Boolean execute(final StarredActivity inStarredActivity) { Query q = getEntityManager().createQuery( "FROM StarredActivity where personId=:personId and activityId=:activityId").setParameter("personId", inStarredActivity.getPersonId()).setParameter("activityId", inStarredActivity.getActivityId()); if (q.getResultList().size() > 0) { return Boolean.TRUE; } this.getEntityManager().persist(inStarredActivity); String key = CacheKeys.STARRED_BY_PERSON_ID + inStarredActivity.getPersonId(); List<Long> starredIds = starredActivitiesMapper.execute(inStarredActivity.getPersonId()); if (starredIds == null) { starredIds = new LinkedList<Long>(); } starredIds.add(inStarredActivity.getActivityId()); Collections.sort(starredIds); Collections.reverse(starredIds); getCache().setList(key, starredIds); return Boolean.TRUE; } InsertStarredActivity(final GetStarredActivityIds inStarredActivitiesMapper); Boolean execute(final StarredActivity inStarredActivity);  }