@@ -0,0 +1,2566 @@
+package net.davidvoid.thor.lightning.data.access;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport net.davidvoid.thor.lightning.data.source.MongoDataSource;%0Aimport net.davidvoid.thor.lightning.entity.FeedRelation;%0Aimport net.davidvoid.thor.lightning.entity.Group;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0A%0Aimport com.mongodb.BasicDBObject;%0Aimport com.mongodb.DBCollection;%0Aimport com.mongodb.DBCursor;%0Aimport com.mongodb.DBObject;%0A%0A/**%0A * Created by david on 3/21/16.%0A * feed_relation collection:%0A * %7BId: XX, group_id: long, feed_id: long, name: string%7D%0A * index 1 : group_id, feed_id, unique%0A */%0Apublic class FeedRelationStore %7B%0A    @Autowired%0A    private MongoDataSource data_source = null;%0A%0A    public List%3CFeedRelation%3E getFeedRelations(Group group) %7B%0A    %09assert(group.has_valid_id());%0A    %09%0A    %09BasicDBObject query = get_query(group);%0A    %09DBCursor cursor = getCollection().find(query);%0A    %09%0A    %09return get_all(cursor);%0A    %7D%0A%0A    private List%3CFeedRelation%3E get_all(DBCursor cursor) %7B%0A    %09ArrayList%3CFeedRelation%3E relation = new ArrayList%3CFeedRelation%3E();%0A    %09%0A    %09while(cursor.hasNext()) %7B%0A    %09%09DBObject object = cursor.next();%0A    %09%09relation.add(to_relation(object));%0A    %09%7D%0A    %09return relation;%0A%09%7D%0A%0A%09private FeedRelation to_relation(DBObject object) %7B%0A%09%09FeedRelation relation = new FeedRelation();%0A%09%09relation.setGroup_id((Long)object.get(%22group_id%22));%0A%09%09relation.setFeed_id((Long)object.get(%22feed_id%22));%0A%09%09relation.setName((String)object.get(%22name%22));%0A%09%09%0A%09%09return relation;%0A%09%7D%0A%0A%09private BasicDBObject get_query(Group group) %7B%0A%09%09BasicDBObject query = new BasicDBObject(%22group_id%22, group.getId());%0A%09%09return query;%0A%09%7D%0A%0A%09public FeedRelation addFeedRelation(FeedRelation feed) %7B%0A%09%09DBObject object = to_object(feed);%0A%09%09getCollection().insert(object);%0A%0A%09%09return feed;%0A    %7D%0A%0A    private DBObject to_object(FeedRelation feed) %7B%0A    %09BasicDBObject object = new BasicDBObject(%22group_id%22, feed.getGroup_id());%0A    %09object.put(%22feed_id%22, feed.getFeed_id());%0A    %09object.put(%22name%22, feed.getName());%0A%0A%09%09return object;%0A%09%7D%0A%0A%09public void updateFeedRelation(FeedRelation feed) %7B%0A%09%09BasicDBObject query = get_query(feed);%0A%09%09DBObject update = to_object(feed);%0A%0A%09%09getCollection().update(query, update);%0A    %7D%0A%0A%0A    private BasicDBObject get_query(FeedRelation feed) %7B%0A    %09BasicDBObject object = new BasicDBObject(%22group_id%22, feed.getGroup_id());%0A    %09object.put(%22feed_id%22, feed.getFeed_id());%0A%0A%09%09return object;%0A%09%7D%0A%0A%09private DBCollection getCollection() %7B%0A        return data_source.getDatabase().getCollection(%22feed_relation%22);%0A    %7D%0A%7D%0A

access the group-feed relationship