@Test public void testExecuteWithExisting() { final long id = 42L; GetFeedSubscriberRequest request = new GetFeedSubscriberRequest(2L, id, EntityType.PERSON, 0); FeedSubscriber feedSub = sut.execute(request); assertEquals(2L, feedSub.getId()); }
@SuppressWarnings("unchecked") @Override public FeedSubscriber execute(final GetFeedSubscriberRequest inRequest) { String query = "FROM FeedSubscriber WHERE feed.id=:feedId AND entityId=:entityId AND type = :type"; List<FeedSubscriber> feedSubs = getEntityManager().createQuery(query) .setParameter("feedId", inRequest.getFeedId()) .setParameter("entityId", inRequest.getEntityId()) .setParameter("type", inRequest.getEntityType()).getResultList(); if (feedSubs.size() > 0) { return feedSubs.get(0); } FeedSubscriber feedSub = new FeedSubscriber(); feedSub.setEntityId(inRequest.getEntityId()); feedSub.setEntityType(inRequest.getEntityType()); feedSub.setFeed((Feed) getHibernateSession().load(Feed.class, inRequest.getFeedId())); feedSub.setRequestor((Person) getHibernateSession().load(Person.class, inRequest.getRequestorPersonId())); getEntityManager().persist(feedSub); return feedSub; }
GetFeedSubscriberOrCreateMapper extends ReadMapper<GetFeedSubscriberRequest, FeedSubscriber> { @SuppressWarnings("unchecked") @Override public FeedSubscriber execute(final GetFeedSubscriberRequest inRequest) { String query = "FROM FeedSubscriber WHERE feed.id=:feedId AND entityId=:entityId AND type = :type"; List<FeedSubscriber> feedSubs = getEntityManager().createQuery(query) .setParameter("feedId", inRequest.getFeedId()) .setParameter("entityId", inRequest.getEntityId()) .setParameter("type", inRequest.getEntityType()).getResultList(); if (feedSubs.size() > 0) { return feedSubs.get(0); } FeedSubscriber feedSub = new FeedSubscriber(); feedSub.setEntityId(inRequest.getEntityId()); feedSub.setEntityType(inRequest.getEntityType()); feedSub.setFeed((Feed) getHibernateSession().load(Feed.class, inRequest.getFeedId())); feedSub.setRequestor((Person) getHibernateSession().load(Person.class, inRequest.getRequestorPersonId())); getEntityManager().persist(feedSub); return feedSub; } }
GetFeedSubscriberOrCreateMapper extends ReadMapper<GetFeedSubscriberRequest, FeedSubscriber> { @SuppressWarnings("unchecked") @Override public FeedSubscriber execute(final GetFeedSubscriberRequest inRequest) { String query = "FROM FeedSubscriber WHERE feed.id=:feedId AND entityId=:entityId AND type = :type"; List<FeedSubscriber> feedSubs = getEntityManager().createQuery(query) .setParameter("feedId", inRequest.getFeedId()) .setParameter("entityId", inRequest.getEntityId()) .setParameter("type", inRequest.getEntityType()).getResultList(); if (feedSubs.size() > 0) { return feedSubs.get(0); } FeedSubscriber feedSub = new FeedSubscriber(); feedSub.setEntityId(inRequest.getEntityId()); feedSub.setEntityType(inRequest.getEntityType()); feedSub.setFeed((Feed) getHibernateSession().load(Feed.class, inRequest.getFeedId())); feedSub.setRequestor((Person) getHibernateSession().load(Person.class, inRequest.getRequestorPersonId())); getEntityManager().persist(feedSub); return feedSub; }  }
GetFeedSubscriberOrCreateMapper extends ReadMapper<GetFeedSubscriberRequest, FeedSubscriber> { @SuppressWarnings("unchecked") @Override public FeedSubscriber execute(final GetFeedSubscriberRequest inRequest) { String query = "FROM FeedSubscriber WHERE feed.id=:feedId AND entityId=:entityId AND type = :type"; List<FeedSubscriber> feedSubs = getEntityManager().createQuery(query) .setParameter("feedId", inRequest.getFeedId()) .setParameter("entityId", inRequest.getEntityId()) .setParameter("type", inRequest.getEntityType()).getResultList(); if (feedSubs.size() > 0) { return feedSubs.get(0); } FeedSubscriber feedSub = new FeedSubscriber(); feedSub.setEntityId(inRequest.getEntityId()); feedSub.setEntityType(inRequest.getEntityType()); feedSub.setFeed((Feed) getHibernateSession().load(Feed.class, inRequest.getFeedId())); feedSub.setRequestor((Person) getHibernateSession().load(Person.class, inRequest.getRequestorPersonId())); getEntityManager().persist(feedSub); return feedSub; }  @SuppressWarnings("unchecked") @Override FeedSubscriber execute(final GetFeedSubscriberRequest inRequest); }
GetFeedSubscriberOrCreateMapper extends ReadMapper<GetFeedSubscriberRequest, FeedSubscriber> { @SuppressWarnings("unchecked") @Override public FeedSubscriber execute(final GetFeedSubscriberRequest inRequest) { String query = "FROM FeedSubscriber WHERE feed.id=:feedId AND entityId=:entityId AND type = :type"; List<FeedSubscriber> feedSubs = getEntityManager().createQuery(query) .setParameter("feedId", inRequest.getFeedId()) .setParameter("entityId", inRequest.getEntityId()) .setParameter("type", inRequest.getEntityType()).getResultList(); if (feedSubs.size() > 0) { return feedSubs.get(0); } FeedSubscriber feedSub = new FeedSubscriber(); feedSub.setEntityId(inRequest.getEntityId()); feedSub.setEntityType(inRequest.getEntityType()); feedSub.setFeed((Feed) getHibernateSession().load(Feed.class, inRequest.getFeedId())); feedSub.setRequestor((Person) getHibernateSession().load(Person.class, inRequest.getRequestorPersonId())); getEntityManager().persist(feedSub); return feedSub; }  @SuppressWarnings("unchecked") @Override FeedSubscriber execute(final GetFeedSubscriberRequest inRequest);  }