package com.peetz.kontor.dal;

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;

import com.peetz.kontor.entity.KontorUserEntity;

@Stateless(name = "ComicDao")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class KontorUserImpl implements KontorUserDao {

	@PersistenceContext
	private EntityManager em;

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

	@Override
	public List<KontorUserEntity> findByIds(List<Long> ids) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public KontorUserEntity findByLogin(String login) {
		Query q = em.createNamedQuery("findByLogin");
		q.setParameter("login", login);
		KontorUserEntity entity = (KontorUserEntity)q.getSingleResult();
		return entity;
	}

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

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