@Test public void testRefreshWhenHashTagAlreadyExists() { HashTagDbRefreshStrategy sut = new HashTagDbRefreshStrategy(); sut.setEntityManager(getEntityManager()); List<String> existingHashTagContents = new ArrayList<String>(); existingHashTagContents.add("#foo"); existingHashTagContents.add("#bar"); List<HashTag> existingHashTags = getEntityManager().createQuery("FROM HashTag WHERE id IN(1,2)") .getResultList(); sut.refresh(existingHashTagContents, existingHashTags); assertAllHashTagsHaveIds(existingHashTags); List<HashTag> resultsAfterRefresh = getEntityManager().createQuery("FROM HashTag").getResultList(); assertEquals(5, resultsAfterRefresh.size()); }
@Override public void refresh(final List<String> inContents, final List<HashTag> inHashTags) { List<String> contents = new ArrayList<String>(); for (String content : inContents) { if (!content.startsWith("#")) { content = "#" + content.toLowerCase(); } else { content = content.toLowerCase(); } contents.add(content); } List<HashTag> foundHashTags = getEntityManager().createQuery("FROM HashTag WHERE content IN (:contents)") .setParameter("contents", contents).getResultList(); inHashTags.clear(); inHashTags.addAll(foundHashTags); for (String content : inContents) { if (isHashTagInCollection(content, foundHashTags)) { if (log.isTraceEnabled()) { log.trace("HashTag " + content + " already exists - skipping."); } continue; } if (log.isTraceEnabled()) { log.trace("Inserting hashtag " + content + " in the database."); } HashTag ht = new HashTag(content); getEntityManager().persist(ht); inHashTags.add(ht); } }
HashTagDbRefreshStrategy extends BaseDomainMapper implements RefreshStrategy<List<String>, List<HashTag>> { @Override public void refresh(final List<String> inContents, final List<HashTag> inHashTags) { List<String> contents = new ArrayList<String>(); for (String content : inContents) { if (!content.startsWith("#")) { content = "#" + content.toLowerCase(); } else { content = content.toLowerCase(); } contents.add(content); } List<HashTag> foundHashTags = getEntityManager().createQuery("FROM HashTag WHERE content IN (:contents)") .setParameter("contents", contents).getResultList(); inHashTags.clear(); inHashTags.addAll(foundHashTags); for (String content : inContents) { if (isHashTagInCollection(content, foundHashTags)) { if (log.isTraceEnabled()) { log.trace("HashTag " + content + " already exists - skipping."); } continue; } if (log.isTraceEnabled()) { log.trace("Inserting hashtag " + content + " in the database."); } HashTag ht = new HashTag(content); getEntityManager().persist(ht); inHashTags.add(ht); } } }
HashTagDbRefreshStrategy extends BaseDomainMapper implements RefreshStrategy<List<String>, List<HashTag>> { @Override public void refresh(final List<String> inContents, final List<HashTag> inHashTags) { List<String> contents = new ArrayList<String>(); for (String content : inContents) { if (!content.startsWith("#")) { content = "#" + content.toLowerCase(); } else { content = content.toLowerCase(); } contents.add(content); } List<HashTag> foundHashTags = getEntityManager().createQuery("FROM HashTag WHERE content IN (:contents)") .setParameter("contents", contents).getResultList(); inHashTags.clear(); inHashTags.addAll(foundHashTags); for (String content : inContents) { if (isHashTagInCollection(content, foundHashTags)) { if (log.isTraceEnabled()) { log.trace("HashTag " + content + " already exists - skipping."); } continue; } if (log.isTraceEnabled()) { log.trace("Inserting hashtag " + content + " in the database."); } HashTag ht = new HashTag(content); getEntityManager().persist(ht); inHashTags.add(ht); } }  }
HashTagDbRefreshStrategy extends BaseDomainMapper implements RefreshStrategy<List<String>, List<HashTag>> { @Override public void refresh(final List<String> inContents, final List<HashTag> inHashTags) { List<String> contents = new ArrayList<String>(); for (String content : inContents) { if (!content.startsWith("#")) { content = "#" + content.toLowerCase(); } else { content = content.toLowerCase(); } contents.add(content); } List<HashTag> foundHashTags = getEntityManager().createQuery("FROM HashTag WHERE content IN (:contents)") .setParameter("contents", contents).getResultList(); inHashTags.clear(); inHashTags.addAll(foundHashTags); for (String content : inContents) { if (isHashTagInCollection(content, foundHashTags)) { if (log.isTraceEnabled()) { log.trace("HashTag " + content + " already exists - skipping."); } continue; } if (log.isTraceEnabled()) { log.trace("Inserting hashtag " + content + " in the database."); } HashTag ht = new HashTag(content); getEntityManager().persist(ht); inHashTags.add(ht); } }  @Override void refresh(final List<String> inContents, final List<HashTag> inHashTags); }
HashTagDbRefreshStrategy extends BaseDomainMapper implements RefreshStrategy<List<String>, List<HashTag>> { @Override public void refresh(final List<String> inContents, final List<HashTag> inHashTags) { List<String> contents = new ArrayList<String>(); for (String content : inContents) { if (!content.startsWith("#")) { content = "#" + content.toLowerCase(); } else { content = content.toLowerCase(); } contents.add(content); } List<HashTag> foundHashTags = getEntityManager().createQuery("FROM HashTag WHERE content IN (:contents)") .setParameter("contents", contents).getResultList(); inHashTags.clear(); inHashTags.addAll(foundHashTags); for (String content : inContents) { if (isHashTagInCollection(content, foundHashTags)) { if (log.isTraceEnabled()) { log.trace("HashTag " + content + " already exists - skipping."); } continue; } if (log.isTraceEnabled()) { log.trace("Inserting hashtag " + content + " in the database."); } HashTag ht = new HashTag(content); getEntityManager().persist(ht); inHashTags.add(ht); } }  @Override void refresh(final List<String> inContents, final List<HashTag> inHashTags);  }