Example usage for javax.persistence EntityManagerFactory createEntityManager

List of usage examples for javax.persistence EntityManagerFactory createEntityManager

Introduction

In this page you can find the example usage for javax.persistence EntityManagerFactory createEntityManager.

Prototype

public EntityManager createEntityManager();

Source Link

Document

Create a new application-managed EntityManager.

Usage

From source file:Logica.Usuario.java

/**
 *
 * @param idUsuario/*from  www  .  j a  v  a2  s  .  c o  m*/
 * @param idRecurso
 * @param tipoRecurso
 * @return
 * @throws RemoteException
 */
@Override
public boolean ocultar(String idUsuario, String idRecurso, String tipoRecurso) throws RemoteException {
    try {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
        EntityManager em = emf.createEntityManager();
        Query q = em.createNamedQuery("Tablamostrar.findByAllParameters");
        q.setParameter("idU", idUsuario);
        q.setParameter("idA", new Double(idRecurso));
        q.setParameter("tipoA", tipoRecurso);
        List<Tablamostrar> resultList = q.getResultList();
        Integer idMostrar = resultList.get(0).getIdMostrar();
        TablamostrarJpaController controller = new TablamostrarJpaController(emf);
        Tablamostrar found = controller.findTablamostrar(idMostrar);
        found.setMostrar("NO");
        controller.edit(found);
        return true;
    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param cinterno// ww  w.ja v a 2  s  .  co m
 * @param NIT
 * @param precio
 * @return
 * @throws RemoteException
 *
 * Asocia un tem a un proveedor
 */
@Override
public boolean desasociarItem(String cinterno, String NIT, String precio) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    boolean hecho = false;
    try {
        Query q = em.createNamedQuery("Ixp.findByCinterno_NIT");
        q.setParameter("cinterno", cinterno);
        q.setParameter("nit", NIT);
        IxpJpaController ixpCo = new IxpJpaController(emf);
        List<Ixp> resultList = q.getResultList();
        Ixp itm = new Ixp();
        if (!resultList.isEmpty()) {
            itm = resultList.get(0);
            itm.setCinterno(cinterno);
            itm.setNit(NIT);
            itm.setPrecio(new Double(precio));
            ixpCo.destroy(itm.getId());
        }
        hecho = true;
    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    emf.close();
    return hecho;
}

From source file:Logica.Usuario.java

@Override
public ArrayList<proveedor> getProveedoresConSolicitudes(String generado) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itxsol.findProveedorByGenerado");
    q.setParameter("generado", "%" + generado + "%");
    ArrayList<proveedor> listaProveedores = new ArrayList<>();
    List<String> resultList = q.getResultList();
    if (!resultList.isEmpty()) {
        for (String i : resultList) {
            proveedor datosProveedor = this.getDatosProveedor(i);
            ArrayList<ItemInventario> itemsAsociados = this.getItemxProveedorSolicitudes(i, "NO");
            if (!itemsAsociados.isEmpty()) {
                datosProveedor.setItemAsociado(itemsAsociados);
            } else {
                datosProveedor.setItemAsociado(new ArrayList<ItemInventario>());
            }/*  w w w.j a va2 s  . co  m*/
            listaProveedores.add(datosProveedor);
        }
        emf.close();
        return listaProveedores;
    } else {
        emf.close();
        return null;
    }

}

From source file:Logica.Usuario.java

@Override
public recepcionProd getDatosRec2(BigDecimal numorden, String id) throws RemoteException {
    recepcionProd rec = null;//ww w . j a  va  2s.  co m
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden2");
    q.setParameter("numorden", new Double(numorden.toString()));
    List<Itmxorden> resultList = q.getResultList();
    ArrayList<itemRecep> items = new ArrayList<>();
    proveedor p = new proveedor();
    for (Itmxorden i : resultList) {
        Proveedor prov = i.getProveedorNit();
        p = new proveedor(prov.getNit(), prov.getNombre(), prov.getDir(), prov.getTel(), prov.getFax(),
                prov.getCiudad(), prov.getCelular(), prov.getCorreo(), p.getContacto());
        Item itm = i.getItemCinterno();
        items.add(new itemRecep(itm.getCinterno(), "", new Float(i.getCaprobada()), new Float(i.getPrecioU())));
    }
    Query qq = em.createNamedQuery("Ordencompra.findByNumOrden");
    qq.setParameter("numOrden", new Double(numorden.toString()));
    if (qq.getResultList().isEmpty()) {
        return null;
    } else {
        Ordencompra o = (Ordencompra) qq.getResultList().get(0);
        emf.close();
        rec = new recepcionProd(numorden, p, id, items, o.getObservaciones());
        return rec;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param id/*from w  w w. j a v a 2s  .  c  o  m*/
 * @return
 * @throws RemoteException
 */
@Override
public ArrayList<solicitudPr> getIdSolicitud(String id) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("SolicitudPr.findByIdSolicitante");
    q.setParameter("idSolicitante", id);
    List<SolicitudPr> resultList = q.getResultList();
    ArrayList<solicitudPr> retorno = new ArrayList<>();
    for (SolicitudPr pr : resultList) {
        solicitudPr s = pr.tosolicitudPr(pr, id);
        users datosUsuario = this.getDatosUsuario(id);
        s.setNombreSolicitante(datosUsuario.getNombre());
        s.setArea(datosUsuario.getLab());
        Query qMostrar = em.createNamedQuery("Tablamostrar.findByAllParameters");
        qMostrar.setParameter("idU", id);
        qMostrar.setParameter("idA", new Double(s.getNum_sol().toString()));
        qMostrar.setParameter("tipoA", "Solicitud");
        Tablamostrar get = new Tablamostrar();
        if (qMostrar.getResultList() != null && !qMostrar.getResultList().isEmpty()) {
            get = (Tablamostrar) qMostrar.getResultList().get(0);
            if (get.getMostrar().equalsIgnoreCase("SI") && get.getTipoArchivo().equalsIgnoreCase("Solicitud")) {
                retorno.add(s);
            }
        }

    }
    emf.close();
    return retorno;
}

From source file:Logica.Usuario.java

/**
 *
 * @param numorden//from   w  w w . ja v a2  s .  co  m
 * @param id
 * @return
 * @throws RemoteException
 *
 * Retorna los datos completos de una orden de compra.
 */
@Override
public recepcionProd getDatosRec(BigDecimal numorden, String id) throws RemoteException {
    recepcionProd rec = null;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden");
    q.setParameter("numorden", new Double(numorden.toString()));
    q.setParameter("recibido", "NO");
    List<Itmxorden> resultList = q.getResultList();
    ArrayList<itemRecep> items = new ArrayList<>();
    proveedor p = new proveedor();
    for (Itmxorden i : resultList) {
        Proveedor prov = i.getProveedorNit();
        p = new proveedor(prov.getNit(), prov.getNombre(), prov.getDir(), prov.getTel(), prov.getFax(),
                prov.getCiudad(), prov.getCelular(), prov.getCorreo(), p.getContacto());
        Item itm = i.getItemCinterno();
        items.add(new itemRecep(itm.getCinterno(), "", new Float(i.getCaprobada()), new Float(i.getPrecioU())));
    }
    Query qq = em.createNamedQuery("Ordencompra.findByNumOrden");
    qq.setParameter("numOrden", new Double(numorden.toString()));
    if (qq.getResultList().isEmpty()) {
        return null;
    } else {
        Ordencompra o = (Ordencompra) qq.getResultList().get(0);
        emf.close();
        rec = new recepcionProd(numorden, p, id, items, o.getObservaciones());
        return rec;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param cinterno//from w w w .j  a  v  a 2s  . c  o m
 * @param NIT
 * @param precio
 * @return
 * @throws RemoteException
 *
 * Asocia un tem a un proveedor
 */
@Override
public boolean asociarItem(String cinterno, String NIT, String precio) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    boolean hecho = false;
    try {
        Query q = em.createNamedQuery("Ixp.findByCinterno_NIT");
        q.setParameter("cinterno", cinterno);
        q.setParameter("nit", NIT);
        IxpJpaController ixpCo = new IxpJpaController(emf);
        List<Ixp> resultList = q.getResultList();
        Ixp itm = new Ixp();
        if (!resultList.isEmpty()) {
            itm = resultList.get(0);
        }
        itm.setCinterno(cinterno);
        itm.setNit(NIT);
        itm.setPrecio(new Double(precio));
        if (resultList.isEmpty()) {
            ixpCo.create(itm);
        } else {
            ixpCo.edit(itm);
        }
        hecho = true;

    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    emf.close();
    return hecho;
}

From source file:Logica.Usuario.java

@Override
public boolean devolverOCompra(ItemInventario itm, double numorden) throws RemoteException {
    boolean hecho = false;
    try {/*from   w w w . j  a  va  2s  . com*/
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
        EntityManager em = emf.createEntityManager();
        Query q = em.createNamedQuery("Itmxorden.findByNumorden_item");
        q.setParameter("numorden", numorden);
        Item findItem = new ItemJpaController(emf).findItem(itm.getNumero());
        q.setParameter("cinterno", findItem);
        List<Itmxorden> resultList = q.getResultList();
        ItmxordenJpaController con = new ItmxordenJpaController(emf);
        Itmxorden f = con.findItmxorden(resultList.get(0).getIdOCompra());
        con.destroy(f.getIdOCompra());
        Query qq = em.createNamedQuery("Itxsol.findSol_Item");
        qq.setParameter("numSol", new Double(itm.getNumSolAsociado()));
        qq.setParameter("cinterno", findItem);
        Itxsol get = (Itxsol) qq.getResultList().get(0);
        ItxsolJpaController itxCont = new ItxsolJpaController(emf);
        Itxsol found = itxCont.findItxsol(get.getId());
        found.setGenerado("NO");
        itxCont.edit(found);
        hecho = true;
    } catch (NonexistentEntityException ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    return hecho;
}

From source file:Logica.Usuario.java

/**
 *
 * @param numorden/*from w w  w.  java 2s. c  o m*/
 * @param id
 * @return
 * @throws RemoteException
 *
 * Retorna los datos completos de una orden de compra.
 */
@Override
public recepcionProd getDatosPedidoRecibido(BigDecimal numorden, String id) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden");
    q.setParameter("numorden", new Double(numorden.toString()));
    q.setParameter("recibido", "SI");
    ArrayList<itemRecep> items = new ArrayList<>();
    List<Itmxorden> resultList = q.getResultList();
    if (!resultList.isEmpty() || resultList != null) {
        Itmxorden get = resultList.get(0);
        proveedor p = new proveedor(get.getProveedorNit().getNit(), get.getProveedorNit().getNombre(),
                get.getProveedorNit().getDir(), get.getProveedorNit().getTel(), get.getProveedorNit().getFax(),
                get.getProveedorNit().getCiudad(), get.getProveedorNit().getCelular(),
                get.getProveedorNit().getCorreo(), get.getProveedorNit().getContacto());
        for (Itmxorden itmxorden : resultList) {
            Item itemCinterno = itmxorden.getItemCinterno();
            Query qq = em.createNamedQuery("Recepcion.findByNumorden");
            qq.setParameter("numorden", new Ordencompra(new Double(numorden.toString())));
            List<Recepcion> recepcion = qq.getResultList();
            for (Recepcion r : recepcion) {
                if (r.getCinterno().getCinterno().equalsIgnoreCase(itemCinterno.getCinterno())) {
                    itemRecep itmRecibido = new itemRecep(itemCinterno.getCinterno(), r.getFechallegada(),
                            r.getFechavencimiento(), r.getCcalidad(), r.getCesp(), r.getMverificacion(),
                            r.getObservaciones(), new Float(itmxorden.getCaprobada()),
                            new Float(r.getPrecioanterior()));
                    items.add(itmRecibido);
                }
            }
        }
        recepcionProd recepcionProd = new recepcionProd(numorden, p, "", items, id);
        return recepcionProd;
    } else {
        return null;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param numOrden/*from w  ww .  j  a  v a  2  s  .  c  om*/
 * @param idRec
 * @param articulos
 * @return
 * @throws RemoteException
 */
@Override
public boolean devolverPedido(BigDecimal numOrden, String idRec, ArrayList<itemRecep> articulos)
        throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden");
    q.setParameter("numorden", new Double(numOrden.toString()));
    q.setParameter("recibido", "SI");
    List<Itmxorden> resultList = q.getResultList();
    ItmxordenJpaController itm = new ItmxordenJpaController(emf);
    for (Itmxorden i : resultList) {
        for (itemRecep rec : articulos) {
            if (i.getItemCinterno().getCinterno().equalsIgnoreCase(rec.getCinterno())) {
                try {
                    this.updateCantidad(rec.getCinterno(), -rec.getcAprobada());
                    i.setRecibido("NO");
                    itm.edit(i);
                } catch (Exception ex) {
                    Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    q = em.createNamedQuery("Recepcion.findByNumorden");
    q.setParameter("numorden", new Ordencompra(new Double(numOrden.toString())));
    List<Recepcion> recepcion = q.getResultList();
    RecepcionJpaController contrRec = new RecepcionJpaController(emf);
    for (Recepcion r : recepcion) {
        for (itemRecep rec : articulos) {
            if (rec.getCinterno().equalsIgnoreCase(rec.getCinterno())) {
                try {
                    contrRec.destroy(r.getFechallegada());
                } catch (NonexistentEntityException ex) {
                    Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    return true;

}