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);
}
}

View File

@@ -1,12 +1,9 @@
package com.commafeed.backend.model;
import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@@ -103,12 +100,6 @@ public class Feed extends AbstractModel {
@Column(length = 40)
private String lastContentHash;
@OneToMany(mappedBy = "feed", cascade = CascadeType.REMOVE)
private Set<FeedEntry> entries;
@OneToMany(mappedBy = "feed")
private Set<FeedSubscription> subscriptions;
/**
* detected hub for pubsubhubbub
*/