package net.davidvoid.thor.lightning.data.access;

import java.util.List;

import net.davidvoid.thor.lightning.data.source.MongoDataSource;
import net.davidvoid.thor.lightning.entity.FeedRelation;
import net.davidvoid.thor.lightning.entity.Item;

import org.springframework.beans.factory.annotation.Autowired;

import com.mongodb.DBCollection;

/**
 * Created by david on 3/21/16.
 */
public class ItemStore {
    @Autowired
    private MongoDataSource data_source = null;

    public List<Item> getItems(FeedRelation feed) {
        return null;
    }

    public Item addItem(Item item) {
        return null;
    }

    public void updateItem(Item item) {

    }

    private DBCollection getCollection() {
        return data_source.getDatabase().getCollection("item");
    }

}

@@ -65,80 +65,15 @@
 til.
-List;%0A%0Aimport net.davidvoid.thor.lightning.data.source.MongoDataSourc
+Dat
 e;%0A
+%0A
 impo
@@ -111,28 +111,22 @@
 .entity.
-FeedRelation
+Entity
 ;%0Aimport
@@ -180,64 +180,34 @@
 ort 
-org.springframework.beans.factory.annotation.Autowired;%0A
+com.mongodb.BasicDBObject;
 %0Aimp
@@ -228,19 +228,16 @@
 b.DB
-Collection;
+Object;%0A
 %0A%0A/*
@@ -276,150 +276,799 @@
 .%0A *
-/%0Apublic class ItemStore %7B%0A    @Autowired%0A    private MongoDataSource data_source = null;%0A%0A    public List%3CItem%3E getItems(FeedRelation feed) %7B
+ collection name: item%0A * %7B _id: XX, id: long, name: string, author: string, content: string,%0A * url: string, is_saved: boolean, is_read: boolean, last_update; Date%7D%0A */%0Apublic class ItemStore extends AbstractStore %7B%0A%0A    private static final String COLLECTION_NAME = %22item%22;%0A%0A    @Override%0A    protected DBObject toDBObject(Entity entity) %7B%0A        Item item = (Item) entity;%0A        %0A        BasicDBObject object = new BasicDBObject(%22id%22, item.getId());%0A        object.put(%22name%22, item.getName());%0A        object.put(%22author%22, item.getAuthor());%0A        object.put(%22content%22, item.getContent());%0A        object.put(%22url%22, item.getUrl());%0A        object.put(%22is_saved%22, item.isSaved());%0A        object.put(%22is_read%22, item.isRead());%0A        object.put(%22last_update%22, item.getLastUpdate());%0A
 %0A   
@@ -1071,36 +1071,38 @@
 %0A        return 
-null
+object
 ;%0A    %7D%0A%0A    pub
@@ -1102,109 +1102,555 @@
     
-public Item addItem(Item item) %7B%0A        return null
+@Override%0A    protected Entity toEntity(DBObject object) %7B%0A        Item item = new Item();%0A        item.setId((Long)object.get(%22id%22));%0A        item.setName((String)object.get(%22name%22));%0A        item.setAuthor((String)object.get(%22author%22));%0A        item.setContent((String)object.get(%22content%22));%0A        item.setUrl((String)object.get(%22url%22))
 ;%0A    
-%7D%0A%0A
     
-public void updateItem(Item
+item.setIsSaved((boolean)object.get(%22is_saved%22));%0A        item.setIsRead((boolean)object.get(%22is_read%22));%0A        item.setLastUpdate((Date)object.get(%22last_update%22));%0A        %0A        return
  item
-) %7B%0A
+;
 %0A   
@@ -1661,116 +1661,263 @@
     
-private DBCollection getCollection() %7B%0A        return data_source.getDatabase().getCollection(%22item%22)
+@Override%0A    protected DBObject getModifyQuery(Entity entity) %7B%0A        Item item = (Item) entity;%0A        return new BasicDBObject(%22id%22, item.getId());%0A    %7D%0A%0A    @Override%0A    protected String getCollectionName() %7B%0A        return COLLECTION_NAME
 ;%0A    %7D%0A
 %0A%7D%0A
@@ -1913,11 +1913,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

implement the class based on abstract class