/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javabbuva;

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

/**
 *
 * @author Adrian
 */
public class ControladorBD {

    static EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAPU");

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

    //public static void setUpDB() {
    //}

    public static List getDataClientesF() {
        //EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAPU");
        return emf.createEntityManager().createQuery("SELECT p FROM ClienteFisico p").getResultList();
    }

    public static List getDataClientesJ() {
        //EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAPU");
        return emf.createEntityManager().createQuery("SELECT p FROM ClienteJuridico p").getResultList();
    }

    public static List getDataProductos() {
        //EntityManagerFactory emf = Persistence.createEntityManagerFactory("BBUVAPU");
        return emf.createEntityManager().createQuery("SELECT p FROM Producto p").getResultList();
    }

}
