Example usage for javax.persistence EntityManager createNamedQuery

List of usage examples for javax.persistence EntityManager createNamedQuery

Introduction

In this page you can find the example usage for javax.persistence EntityManager createNamedQuery.

Prototype

public Query createNamedQuery(String name);

Source Link

Document

Create an instance of Query for executing a named query (in the Java Persistence query language or in native SQL).

Usage

From source file:Logica.Usuario.java

/**
 *
 * @param numorden//from   ww w .jav  a2s. c  om
 * @return
 * @throws RemoteException
 */
@Override
public evProv getEvaluacionProv(double numorden) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Evaluacionprov.findByNumorden");
    q.setParameter("numorden", numorden);
    List<Evaluacionprov> resultList = q.getResultList();
    evProv ev = null;
    for (Evaluacionprov e : resultList) {
        ev = new evProv(e.getNitProv(), e.getNumorden(), e.getEv1(), e.getEv2(), e.getEv3(), e.getEv4(),
                e.getEv5(), e.getEv6(), e.getEv7(), e.getEv8());
    }
    emf.close();
    return ev;
}

From source file:Logica.Usuario.java

@Override
public Double buscarPrecio(ItemInventario i, String proveedor) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByAllParameters3");
    q.setParameter("numsol", new Double(i.getNumSolAsociado()));
    q.setParameter("nit", new ProveedorJpaController(emf).findProveedor(proveedor));
    q.setParameter("caprobada", i.getCantidadAprobada());
    q.setParameter("cinterno", new ItemJpaController(emf).findItem(i.getNumero()));
    List<Itmxorden> resultList = q.getResultList();
    double precio = 0;
    if (!resultList.isEmpty() && resultList != null) {
        precio = resultList.get(0).getPrecioU();
    }/*ww  w.  j a va  2  s. co  m*/
    emf.close();
    return new Double(precio);
}

From source file:Logica.Usuario.java

@Override
public int buscarOcompra(ItemInventario i, String proveedor) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByAllParameters2");
    q.setParameter("numsol", new Double(i.getNumSolAsociado()));
    q.setParameter("nit", new ProveedorJpaController(emf).findProveedor(proveedor));
    q.setParameter("caprobada", i.getCantidadAprobada());
    q.setParameter("precio", i.getPrecio());
    q.setParameter("cinterno", new ItemJpaController(emf).findItem(i.getNumero()));
    List<Itmxorden> resultList = q.getResultList();
    double numorden = -1;
    if (!resultList.isEmpty() && resultList != null) {
        numorden = resultList.get(0).getNumorden();
    }//  w w w  . j a  v a2  s .  co  m
    emf.close();
    return new Double(numorden).intValue();
}

From source file:Logica.Usuario.java

@Override
public int buscarOrdenByNumSol(ItemInventario i, String proveedor, String numSol) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByAllParameters2");
    q.setParameter("nit", new ProveedorJpaController(emf).findProveedor(proveedor));
    q.setParameter("caprobada", i.getCantidadAprobada());
    q.setParameter("precio", i.getPrecio());
    q.setParameter("cinterno", new ItemJpaController(emf).findItem(i.getNumero()));
    q.setParameter("numsol", new Double(numSol));
    List<Itmxorden> resultList = q.getResultList();
    double numorden = -1;
    if (resultList != null && !resultList.isEmpty() && resultList.get(0) != null) {
        numorden = resultList.get(0).getNumorden();
    }// w ww  .j  a  v a2s. c  o  m
    emf.close();
    return new Double(numorden).intValue();
}

From source file:Logica.Usuario.java

/**
 *
 * @param e//from w  w w .j  a v a 2 s .  c o m
 * @throws RemoteException
 */
@Override
public void borrarEvaluacion(evProv e) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Evaluacionprov.findByNumorden");
    q.setParameter("numorden", e.getNumorden());
    List<Evaluacionprov> ev = q.getResultList();
    EvaluacionprovJpaController contr = new EvaluacionprovJpaController(emf);
    for (Evaluacionprov ee : ev) {
        try {
            contr.destroy(ee.getId());
        } catch (NonexistentEntityException ex) {
            Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    emf.close();
}

From source file:Logica.Usuario.java

/**
 *
 * @param numSol//from w w  w .j  a  v  a2s .com
 * @return ArrayList
 * @throws RemoteException
 *
 * Genera el listado de tems solicitados asociados a un numero de
 * solicitud.
 */
@Override
public ArrayList<ItemInventario> getItems_numSol(BigDecimal numSol) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    ItemJpaController control = new ItemJpaController(emf);
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itxsol.findByNumSol");
    q.setParameter("numSol", new Double(numSol.toString()));
    List<Itxsol> resultList = q.getResultList();
    ArrayList<ItemInventario> retorno = new ArrayList<>();
    for (Itxsol i : resultList) {
        Item findItem = control.findItem(i.getCinterno().getCinterno());
        ItemInventario itm = findItem.EntityToItem(findItem);
        itm.setCantidadSolicitada(new Float(i.getCantidadsol()));
        retorno.add(itm);
    }
    emf.close();
    return retorno;
}

From source file:Logica.Usuario.java

/**
 *
 * @param numSol//from   ww w  .j  a v a  2s  . c o m
 * @param Aprobado
 * @return
 * @throws RemoteException
 */
@Override
public ArrayList<ItemInventario> getItemsAprobado(BigDecimal numSol, String Aprobado) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    ItemJpaController control = new ItemJpaController(emf);
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itxsol.findByAprobado");
    q.setParameter("numSol", new Double(numSol.toString()));
    q.setParameter("aprobado", "%" + Aprobado + "%");
    List<Itxsol> resultList = q.getResultList();
    ArrayList<ItemInventario> retorno = new ArrayList<>();
    for (Itxsol i : resultList) {
        Item findItem = control.findItem(i.getCinterno().getCinterno());
        ItemInventario itm = findItem.EntityToItem(findItem);
        itm.setCantidadSolicitada(new Float(i.getCantidadsol()));
        retorno.add(itm);
    }
    emf.close();
    return retorno;
}

From source file:Logica.Usuario.java

/**
 *
 * @param descripcion//from w ww .  j av a 2s  .  c  om
 * @param presentacion
 * @param inv
 * @return
 * @throws RemoteException
 */
@Override
public ArrayList<ItemInventario> busquedaItem(String descripcion, String presentacion, String inv)
        throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Item.busqueda");
    q.setParameter("descripcion", "%" + descripcion + "%");
    q.setParameter("presentacion", "%" + presentacion + "%");
    q.setParameter("inv", "%" + inv + "%");
    List<Item> resultList = q.getResultList();
    if (resultList == null) {
        emf.close();
        return new ArrayList<>();
    } else {
        ArrayList<ItemInventario> lstRetorno = new ArrayList<>();
        for (Item i : resultList) {
            lstRetorno.add(i.EntityToItem(i));
        }
        emf.close();
        return lstRetorno;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param i//  w w  w.ja v a  2  s. c  o m
 * @return
 * @throws RemoteException
 */
@Override
public ArrayList<itemxproveedor> getProveedorAsociado(itemxproveedor i) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    String cinterno = i.getCinterno();
    Double precio = new Double(Float.toString(i.getPrecio()));
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Ixp.findByCinterno_Precio");
    q.setParameter("cinterno", cinterno);
    q.setParameter("precio", precio);
    List<Ixp> resultList = q.getResultList();
    ArrayList<itemxproveedor> retorno = new ArrayList<>();
    if (!resultList.isEmpty()) {
        for (Ixp ixp : resultList) {
            proveedor datosProveedor = this.getDatosProveedor(ixp.getNit());
            itemxproveedor itx = new itemxproveedor(datosProveedor.getNombre(), new Float(ixp.getPrecio()),
                    ixp.getCinterno());
            itx.setNIT(ixp.getNit());
            retorno.add(itx);
        }
    }
    emf.close();
    return retorno;

}

From source file:Logica.Usuario.java

@Override
public ArrayList<ItemInventario> getItemxProveedorSolicitudes(String proveedor, String generado)
        throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itxsol.findItemByProveedor");
    q.setParameter("nit", proveedor);
    List<Itxsol> resultList = q.getResultList();
    ArrayList<ItemInventario> listaItems = new ArrayList<>();
    for (Itxsol i : resultList) {
        if (i.getGenerado().equalsIgnoreCase(generado)) {
            Item cinterno = i.getCinterno();
            ItemInventario EntityToItem = cinterno.EntityToItem(cinterno);
            EntityToItem.setNumSolAsociado(Double.toString(i.getNumSol()));
            EntityToItem.setCantidadAprobada(i.getCantidadaprobada().floatValue());
            listaItems.add(EntityToItem);
        }/*from ww  w  .  j a va  2  s  . c  om*/
    }
    if (!resultList.isEmpty()) {
        emf.close();
        return listaItems;
    } else {
        emf.close();
        return null;
    }
}