/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package DAO;
import Entity.Registro_Inv;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
/**
*
* @author Leonardo
*/
public class Registro_invDAO {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PPG_PU");
public void crear(Registro_Inv registro) {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try {
em.merge(registro);
em.flush();
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
} finally {
em.close();
}
}
public List<Registro_Inv> leer() {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
List<Registro_Inv> registros = new ArrayList<Registro_Inv>();
Query cons = em.createQuery("select u from Registro_Inv u");
try {
for (int i = 0; i < cons.getResultList().size(); i++) {
Registro_Inv reg = (Registro_Inv) cons.getResultList().get(i);
registros.add(reg);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
em.close();
return registros;
}
}
}