package dst.ass1.jpa.dao.impl;

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

public class GenericDAO<TImpl extends T, T> implements dst.ass1.jpa.dao.GenericDAO<T> {
    protected final EntityManager em;
    private final Class<TImpl> c;

    protected GenericDAO(EntityManager em, Class<TImpl> c) {
        this.em = em;
        this.c = c;
    }

    @Override
    public T findById(Long id) {
        return em.find(c, id);
    }

    @Override
    public List<T> findAll() {
        return em.createQuery("from " + c.getName()).getResultList();
    }
}
