don't fetch the whole content, just return the id if it does

This commit is contained in:
Athou
2013-07-27 16:42:50 +02:00
parent 60bf96411c
commit 6d396e1982
3 changed files with 16 additions and 9 deletions

View File

@@ -17,16 +17,18 @@ import com.google.common.collect.Iterables;
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
public FeedEntryContent findExisting(String contentHash, String titleHash) {
public Long findExisting(String contentHash, String titleHash) {
CriteriaQuery<FeedEntryContent> query = builder.createQuery(getType());
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<FeedEntryContent> root = query.from(getType());
query.select(root.get(FeedEntryContent_.id));
Predicate p1 = builder.equal(root.get(FeedEntryContent_.contentHash), contentHash);
Predicate p2 = builder.equal(root.get(FeedEntryContent_.titleHash), titleHash);
query.where(p1, p2);
TypedQuery<FeedEntryContent> q = em.createQuery(query);
TypedQuery<Long> q = em.createQuery(query);
limit(q, 0, 1);
return Iterables.getFirst(q.getResultList(), null);
}