2013-07-24 15:39:20 +02:00
|
|
|
package com.commafeed.backend.dao;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
import org.hibernate.SessionFactory;
|
|
|
|
|
|
2013-07-24 15:39:20 +02:00
|
|
|
import com.commafeed.backend.model.FeedEntryContent;
|
2014-08-08 16:49:02 +02:00
|
|
|
import com.commafeed.backend.model.QFeedEntry;
|
|
|
|
|
import com.commafeed.backend.model.QFeedEntryContent;
|
2015-07-09 12:34:54 +02:00
|
|
|
import com.querydsl.jpa.JPAExpressions;
|
|
|
|
|
import com.querydsl.jpa.JPQLQuery;
|
2013-07-24 15:39:20 +02:00
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
@Singleton
|
2013-07-24 15:39:20 +02:00
|
|
|
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
|
|
|
|
|
|
2022-01-02 21:32:40 +01:00
|
|
|
private final QFeedEntryContent content = QFeedEntryContent.feedEntryContent;
|
|
|
|
|
private final QFeedEntry entry = QFeedEntry.feedEntry;
|
2013-07-24 15:39:20 +02:00
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
@Inject
|
2014-08-08 16:49:02 +02:00
|
|
|
public FeedEntryContentDAO(SessionFactory sessionFactory) {
|
|
|
|
|
super(sessionFactory);
|
|
|
|
|
}
|
2013-07-24 15:39:20 +02:00
|
|
|
|
2022-01-02 21:45:21 +01:00
|
|
|
public List<FeedEntryContent> findExisting(String contentHash, String titleHash) {
|
|
|
|
|
return query().select(content).from(content).where(content.contentHash.eq(contentHash), content.titleHash.eq(titleHash)).fetch();
|
2013-07-24 15:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int deleteWithoutEntries(int max) {
|
2015-04-23 08:55:47 +02:00
|
|
|
|
2015-07-09 12:34:54 +02:00
|
|
|
JPQLQuery<Integer> subQuery = JPAExpressions.selectOne().from(entry).where(entry.content.id.eq(content.id));
|
|
|
|
|
List<FeedEntryContent> list = query().selectFrom(content).where(subQuery.notExists()).limit(max).fetch();
|
2015-04-23 08:55:47 +02:00
|
|
|
|
2013-07-24 15:39:20 +02:00
|
|
|
int deleted = list.size();
|
2013-11-14 12:56:08 +01:00
|
|
|
delete(list);
|
2013-07-24 15:39:20 +02:00
|
|
|
return deleted;
|
|
|
|
|
}
|
|
|
|
|
}
|