package com.ibtp.kontor.comics.dal;

import com.ibtp.kontor.comics.entity.StoryArcEntity;
import com.ibtp.kontor.dal.BaseImpl;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.Collection;
import java.util.List;

/**
 * Created by TPEETZ on 28.01.2015.
 */
public class StoryArcImpl extends BaseImpl implements StoryArcDao {

    @Override
    public StoryArcEntity getById(Long id) {
        return null;
    }

    @Override
    public Collection<StoryArcEntity> findByIds(List<Long> ids) {
        return null;
    }

    @Override
    public Collection<StoryArcEntity> findByTitle(String title) {
        Query query = getEntityManager().createNamedQuery("StoryArc.findByTitle");
        query.setParameter("title", title);
        return query.getResultList();
    }

    @Override
    public Collection<StoryArcEntity> findAll() {
        Query query = getEntityManager().createNamedQuery("StoryArc.findAll");
        return query.getResultList();
    }

    @Override
    public StoryArcEntity store(StoryArcEntity entity) {
        EntityManager em = getEntityManager();
        em.getTransaction().begin();
        em.persist(entity);
        em.getTransaction().commit();
        return entity;
    }

    @Override
    public void delete(StoryArcEntity entity) {
        EntityManager em = getEntityManager();
        em.getTransaction().begin();
        em.remove(entity);
        em.getTransaction().commit();
    }
}
