/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.peetz.tradingcards.dal;

import com.peetz.tradingcards.entity.BaseSetEntity;
import com.peetz.tradingcards.entity.ManufacturerEntity;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author tpeetz
 */
@Stateless(name = "ManufacturerDao")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ManufacturerImpl implements ManufacturerDao {

    @PersistenceContext(unitName = "kontor")
    private EntityManager em;

    @Override
    public ManufacturerEntity getById(Long id) {
        Query q = em.createNamedQuery("Manufacturer.findById");
	q.setParameter("id", id);
	ManufacturerEntity entity = (ManufacturerEntity)q.getSingleResult();
	return entity;
    }

    @Override
    public List<ManufacturerEntity> findByIds(List<Long> ids) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @SuppressWarnings("unchecked")
	@Override
    public List<ManufacturerEntity> findByName(String name) {
        Query q = em.createNamedQuery("Manufacturer.findByName");
	q.setParameter("name", name);
	List<ManufacturerEntity> resultList = q.getResultList();
	return resultList;
    }

    @Override
    public ManufacturerEntity assignBaseSet(ManufacturerEntity comic, BaseSetEntity baseSet) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ManufacturerEntity store(ManufacturerEntity entity) {
    	em.persist(entity);
    	return entity;
    }

    @Override
    public void delete(ManufacturerEntity entity) {
    	em.remove(entity);
    }
}
