/*
 * 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.SportEntity;
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 = "SportDao")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class SportImpl implements SportDao {

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

    @Override
    public SportEntity getById(Long id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

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

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

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

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