forked from Archives/Athou_commafeed
queries tweaking
This commit is contained in:
@@ -17,8 +17,7 @@ import com.uaihebert.factory.EasyCriteriaFactory;
|
|||||||
import com.uaihebert.model.EasyCriteria;
|
import com.uaihebert.model.EasyCriteria;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class GenericDAO<T, K> implements
|
public abstract class GenericDAO<T, K> implements Serializable {
|
||||||
Serializable {
|
|
||||||
|
|
||||||
private TypeToken<T> type = new TypeToken<T>(getClass()) {
|
private TypeToken<T> type = new TypeToken<T>(getClass()) {
|
||||||
};
|
};
|
||||||
@@ -88,8 +87,7 @@ public abstract class GenericDAO<T, K> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<T> findByField(String field, Object value) {
|
public List<T> findByField(String field, Object value) {
|
||||||
EasyCriteria<T> criteria = EasyCriteriaFactory.createQueryCriteria(em,
|
EasyCriteria<T> criteria = createCriteria();
|
||||||
getType());
|
|
||||||
criteria.andEquals(field, value);
|
criteria.andEquals(field, value);
|
||||||
return criteria.getResultList();
|
return criteria.getResultList();
|
||||||
}
|
}
|
||||||
@@ -98,8 +96,8 @@ public abstract class GenericDAO<T, K> implements
|
|||||||
protected Class<T> getType() {
|
protected Class<T> getType() {
|
||||||
return (Class<T>) type.getRawType();
|
return (Class<T>) type.getRawType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EasyCriteria<T> createCriteria(){
|
public EasyCriteria<T> createCriteria() {
|
||||||
return EasyCriteriaFactory.createQueryCriteria(em, getType());
|
return EasyCriteriaFactory.createQueryCriteria(em, getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ public class Feed extends AbstractModel {
|
|||||||
@OneToMany(mappedBy = "feed")
|
@OneToMany(mappedBy = "feed")
|
||||||
private Set<FeedEntry> entries = Sets.newHashSet();
|
private Set<FeedEntry> entries = Sets.newHashSet();
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "feed")
|
||||||
|
private Set<FeedSubscription> subscriptions;
|
||||||
|
|
||||||
public Feed() {
|
public Feed() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -69,4 +72,12 @@ public class Feed extends AbstractModel {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<FeedSubscription> getSubscriptions() {
|
||||||
|
return subscriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubscriptions(Set<FeedSubscription> subscriptions) {
|
||||||
|
this.subscriptions = subscriptions;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ public class FeedCategory extends AbstractModel {
|
|||||||
@ManyToOne
|
@ManyToOne
|
||||||
private FeedCategory parent;
|
private FeedCategory parent;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "parent")
|
||||||
|
private Set<FeedCategory> children;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "category")
|
@OneToMany(mappedBy = "category")
|
||||||
private Set<FeedSubscription> subscriptions;
|
private Set<FeedSubscription> subscriptions;
|
||||||
|
|
||||||
@@ -62,4 +65,12 @@ public class FeedCategory extends AbstractModel {
|
|||||||
this.subscriptions = subscriptions;
|
this.subscriptions = subscriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<FeedCategory> getChildren() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildren(Set<FeedCategory> children) {
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,13 +61,15 @@ public class EntriesREST extends AbstractREST {
|
|||||||
} else {
|
} else {
|
||||||
FeedCategory feedCategory = null;
|
FeedCategory feedCategory = null;
|
||||||
if (!ALL.equals(id)) {
|
if (!ALL.equals(id)) {
|
||||||
feedCategory = feedCategoryService.findById(getUser(), Long.valueOf(id));
|
feedCategory = feedCategoryService.findById(getUser(),
|
||||||
|
Long.valueOf(id));
|
||||||
}
|
}
|
||||||
List<FeedCategory> childrenCategories = feedCategoryService
|
List<FeedCategory> childrenCategories = feedCategoryService
|
||||||
.findAllChildrenCategories(getUser(), feedCategory);
|
.findAllChildrenCategories(getUser(), feedCategory);
|
||||||
|
|
||||||
Map<Long, FeedSubscription> subMapping = Maps.uniqueIndex(
|
List<FeedSubscription> subs = feedSubscriptionService
|
||||||
feedSubscriptionService.findAll(getUser()),
|
.findAll(getUser());
|
||||||
|
Map<Long, FeedSubscription> subMapping = Maps.uniqueIndex(subs,
|
||||||
new Function<FeedSubscription, Long>() {
|
new Function<FeedSubscription, Long>() {
|
||||||
public Long apply(FeedSubscription sub) {
|
public Long apply(FeedSubscription sub) {
|
||||||
return sub.getFeed().getId();
|
return sub.getFeed().getId();
|
||||||
@@ -104,8 +106,8 @@ public class EntriesREST extends AbstractREST {
|
|||||||
List<FeedEntryWithStatus> unreadEntries = feedEntryService.getEntries(
|
List<FeedEntryWithStatus> unreadEntries = feedEntryService.getEntries(
|
||||||
categories, getUser(), unreadOnly, offset, limit);
|
categories, getUser(), unreadOnly, offset, limit);
|
||||||
for (FeedEntryWithStatus feedEntry : unreadEntries) {
|
for (FeedEntryWithStatus feedEntry : unreadEntries) {
|
||||||
entries.add(populateEntry(buildEntry(feedEntry),
|
Long id = feedEntry.getEntry().getFeed().getId();
|
||||||
subMapping.get(feedEntry.getEntry().getFeed().getId())));
|
entries.add(populateEntry(buildEntry(feedEntry), subMapping.get(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
|
|||||||
Reference in New Issue
Block a user