
package bbuvajava;

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

public class ControladoraBD {


    public void persist(Object object) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAJAVAPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }

      public List getData_Cliente() {
          EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAJAVAPU");
          EntityManager em = emf.createEntityManager();
          return em.createQuery("SELECT c FROM Cliente c").getResultList();
}
      public List getData_Producto() {
          EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAJAVAPU");
          EntityManager em = emf.createEntityManager();
          return em.createQuery("SELECT p FROM Producto p").getResultList();
}
      public static List getData_Sucursal() {
          EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAJAVAPU");
          EntityManager em = emf.createEntityManager();
          return em.createQuery("SELECT s FROM Sucursal s").getResultList();
}
       

}
