Package org.uned.agonzalo16.bitacora.dao

Source Code of org.uned.agonzalo16.bitacora.dao.ArticleDao

package org.uned.agonzalo16.bitacora.dao;

import static org.uned.agonzalo16.bitacora.dao.OfyFactory.ofy;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.uned.agonzalo16.bitacora.domain.Article;
import org.uned.agonzalo16.bitacora.domain.Blog;
import org.uned.agonzalo16.bitacora.domain.Comment;
import org.uned.agonzalo16.bitacora.domain.User;

import com.googlecode.objectify.Key;

@Repository
public class ArticleDao {

  public List<Article> findAll() {
    return ofy().load().type(Article.class).order("creationDate").list();
  }

  public List<Article> findAll(int limit, int offset) {
    return ofy().load().type(Article.class).limit(limit).offset(offset).order("-creationDate").list();
  }

  public List<Article> findByBlog(Blog blog) {
    return ofy().load().type(Article.class).filter("blog", blog).order("-creationDate").list();
  }

  public int countByBlog(Blog blog) {
    return ofy().load().type(Article.class).filter("blog", blog).count();
  }

  public List<Article> findByUser(User user) {
    return ofy().load().type(Article.class).filter("user", user).order("-creationDate").list();
  }

  public Article get(Long id) {
    return ofy().load().type(Article.class).id(id).now();
  }

  public Article merge(Article article) {
    ofy().save().entity(article).now();
    return article;
  }

  public void delete(Long id) {
    Article article = get(id);
    List<Key<Comment>> comments = ofy().load().type(Comment.class).ancestor(article).keys().list();
    ofy().delete().type(Article.class).id(id).now();
    ofy().delete().keys(comments).now();
  }
}
TOP

Related Classes of org.uned.agonzalo16.bitacora.dao.ArticleDao

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.