remove one to many relationships

This commit is contained in:
Athou
2015-03-30 11:31:58 +02:00
parent 3e77a83ca6
commit cebeef04a0
2 changed files with 7 additions and 12 deletions

View File

@@ -17,6 +17,7 @@ import com.commafeed.backend.model.QUser;
import com.google.common.collect.Iterables;
import com.mysema.query.BooleanBuilder;
import com.mysema.query.jpa.hibernate.HibernateQuery;
import com.mysema.query.jpa.hibernate.HibernateSubQuery;
@Singleton
public class FeedDAO extends GenericDAO<Feed> {
@@ -33,12 +34,14 @@ public class FeedDAO extends GenericDAO<Feed> {
disabledDatePredicate.or(feed.disabledUntil.isNull());
disabledDatePredicate.or(feed.disabledUntil.lt(new Date()));
HibernateQuery query = newQuery().from(feed);
HibernateQuery query = null;
if (lastLoginThreshold != null) {
QFeedSubscription subs = QFeedSubscription.feedSubscription;
QUser user = QUser.user;
query.join(feed.subscriptions, subs).join(subs.user, user).where(disabledDatePredicate, user.lastLogin.gt(lastLoginThreshold));
query = newQuery().from(subs);
query.join(subs.feed, feed).join(subs.user, user).where(disabledDatePredicate, user.lastLogin.gt(lastLoginThreshold));
} else {
query = newQuery().from(feed);
query.where(disabledDatePredicate);
}
@@ -60,6 +63,7 @@ public class FeedDAO extends GenericDAO<Feed> {
public List<Feed> findWithoutSubscriptions(int max) {
QFeedSubscription sub = QFeedSubscription.feedSubscription;
return newQuery().from(feed).leftJoin(feed.subscriptions, sub).where(sub.id.isNull()).limit(max).list(feed);
return newQuery().from(feed).where(new HibernateSubQuery().from(sub).where(sub.feed.eq(feed)).notExists()).limit(max).list(feed);
// return newQuery().from(feed).leftJoin(feed.subscriptions, sub).where(sub.id.isNull()).limit(max).list(feed);
}
}