mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
index title hash
This commit is contained in:
@@ -9,8 +9,6 @@ import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntryContent;
|
||||
import com.commafeed.backend.model.FeedEntryContent_;
|
||||
@@ -19,27 +17,15 @@ import com.google.common.collect.Iterables;
|
||||
|
||||
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
|
||||
|
||||
public FeedEntryContent findExisting(FeedEntryContent content) {
|
||||
public FeedEntryContent findExisting(String contentHash, String titleHash) {
|
||||
|
||||
CriteriaQuery<FeedEntryContent> query = builder.createQuery(getType());
|
||||
Root<FeedEntryContent> root = query.from(getType());
|
||||
|
||||
Predicate p1 = builder.equal(root.get(FeedEntryContent_.contentHash), DigestUtils.sha1Hex(content.getContent()));
|
||||
Predicate p2 = null;
|
||||
if (content.getTitle() == null) {
|
||||
p2 = builder.isNull(root.get(FeedEntryContent_.title));
|
||||
} else {
|
||||
p2 = builder.equal(root.get(FeedEntryContent_.title), content.getTitle());
|
||||
}
|
||||
Predicate p1 = builder.equal(root.get(FeedEntryContent_.contentHash), contentHash);
|
||||
Predicate p2 = builder.equal(root.get(FeedEntryContent_.titleHash), titleHash);
|
||||
|
||||
Predicate p3 = null;
|
||||
if (content.getAuthor() == null) {
|
||||
p3 = builder.isNull(root.get(FeedEntryContent_.author));
|
||||
} else {
|
||||
p3 = builder.equal(root.get(FeedEntryContent_.author), content.getAuthor());
|
||||
}
|
||||
|
||||
query.where(p1, p2, p3);
|
||||
query.where(p1, p2);
|
||||
TypedQuery<FeedEntryContent> q = em.createQuery(query);
|
||||
return Iterables.getFirst(q.getResultList(), null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user