List of usage examples for javax.persistence EntityManagerFactory close
public void close();
From source file:BO.UserHandler.java
public int sendChallengeRequest(VUser user) { EntityManager em;/* ww w.j a v a 2 s. c o m*/ EntityManagerFactory emf; emf = Persistence.createEntityManagerFactory(PERSISTENCE_NAME); em = emf.createEntityManager(); try { em.getTransaction().begin(); System.out.println("Challenged by: " + user.getEmail()); System.out.println("Challenged friend: " + user.getFriendToAdd()); User friend = getUserByEmail(user.getFriendToAdd()); GameServerCommunicator gameComm = new GameServerCommunicator(); ArrayList<String> playerNames = new ArrayList<>(); playerNames.add(user.getEmail()); playerNames.add(user.getFriendToAdd()); int gameId = gameComm.requestNewGame(playerNames); if (gameId == -1) { //if something went wrong return -1; } //Send cloud message to friend JSONObject notificationObj = new JSONObject(); notificationObj.put("body", "CHALLENGE " + user.getEmail() + " " + GameInfo.getInstance().getIp() + " " + GameInfo.getInstance().getClientPort() + " " + gameId); notificationObj.put("title", "A Challenge"); JSONObject messageObj = new JSONObject(); messageObj.put("token", friend.getDeviceToken()); messageObj.put("notification", notificationObj); JSONObject mainObject = new JSONObject(); mainObject.put("message", messageObj); HttpPost url = getHttpURL(); url.setEntity(new StringEntity(mainObject.toString())); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(url); System.out.println("Response:"); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); System.out.println(responseString); em.flush(); em.getTransaction().commit(); return gameId; } catch (Exception e) { System.out.println(e); return -1; } finally { if (em != null) { em.close(); } emf.close(); } }
From source file:Logica.Usuario.java
/** * * @return ArrayList/*from ww w . j ava2 s. c o m*/ * @throws RemoteException * * Genera una lista con todo el inventario existente en la base de datos */ @Override public ArrayList<ItemInventario> itemInventarioAdmin() throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); ArrayList<ItemInventario> lista = new ArrayList<>(); EntityManager em = emf.createEntityManager(); Query q = em.createNamedQuery("Item.InventarioAdmin"); List<Item> resultList = q.getResultList(); for (Item i : resultList) { lista.add(i.EntityToItem(i)); } emf.close(); return lista; }
From source file:Logica.Usuario.java
/** * * @param NIT//from w ww .j a v a 2s.co m * @return proveedor * @throws RemoteException * * Busca los datos de un proveedor de acuerdo al nit recibido */ @Override public proveedor getDatosProveedor(String NIT) throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); ProveedorJpaController prov = new ProveedorJpaController(emf); Proveedor find = prov.findProveedor(NIT); proveedor p = new proveedor(find.getNit(), find.getNombre(), find.getDir(), find.getTel(), find.getFax(), find.getCiudad(), find.getCelular(), find.getCorreo(), find.getContacto()); emf.close(); return p; }
From source file:Logica.Usuario.java
/** * * @param descripcion/* w ww . j a v a 2s. c o m*/ * @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 id//from w w w.j av a2 s. c om * @return * @throws RemoteException */ @Override public solicitudPr getSolicitud(String id) throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); SolicitudPrJpaController contr = new SolicitudPrJpaController(emf); SolicitudPr found = contr.findSolicitudPr(new Double(id)); users datosUsuario = this.getDatosUsuario(found.getIdSolicitante()); solicitudPr s = found.tosolicitudPr(found, found.getIdSolicitante()); s.setNombreSolicitante(datosUsuario.getNombre()); s.setArea(datosUsuario.getLab()); emf.close(); return s; }
From source file:Logica.Usuario.java
/** * * @param item//ww w .j a v a2s. c o m * @return boolean * @throws RemoteException * * Crea un tem */ @Override public boolean crearItem(ItemInventario item) throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); boolean hecho = false; ItemJpaController itm = new ItemJpaController(emf); Item i = new Item(item.getNumero(), item.getInventario(), item.getDescripcion(), item.getPresentacion(), new Double(Float.toString(item.getCantidad())), new Double(Float.toString(item.getPrecio())), item.getcCalidad(), item.getCEsp()); try { itm.create(i); hecho = true; emf.close(); } catch (Exception ex) { Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex); } return hecho; }
From source file:Logica.Usuario.java
/** * * @param identificacion//from w ww . j a va 2s . c o m * @param nombre * @param correo * @param psw * @param area * @param id * @return boolean * @throws RemoteException * * Crea un usuario completamente nuevo */ @Override public boolean crearUsuario(String identificacion, String nombre, String correo, String psw, String area, String id) throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); boolean creado = false; UsuarioJpaController contr = new UsuarioJpaController(emf); Entities.Usuario nuevo = new Entities.Usuario(identificacion, this.encriptar(psw), nombre, correo, area, contr.findUsuario(id)); try { contr.create(nuevo); creado = true; } catch (Exception ex) { Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex); } emf.close(); return creado; }
From source file:Logica.Usuario.java
/** * * @return ArrayList//from w w w .j av a 2 s .c o m * @throws RemoteException * * Genera una lista con todos los proveedores que se encuentran en el * sistema */ @Override public ArrayList<proveedor> todosProveedores() throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); ArrayList<proveedor> proveedores = new ArrayList<>(); EntityManager em = emf.createEntityManager(); Query q = em.createNamedQuery("Proveedor.findAllOrderByName"); List<Proveedor> resultList = q.getResultList(); for (Proveedor p : resultList) { proveedores.add(new proveedor(p.getNit(), p.getNombre(), p.getDir(), p.getTel(), p.getFax(), p.getCiudad(), p.getCelular(), p.getCorreo(), p.getContacto())); } emf.close(); return proveedores; }
From source file:Logica.Usuario.java
/** * * @param numSol/*from w w w. j a v a 2 s . c o m*/ * @param cinterno * @return * @throws RemoteException */ @Override public String getCantAprobada(String numSol, String cinterno) throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); EntityManager em = emf.createEntityManager(); ItemJpaController itm = new ItemJpaController(emf); Item findItem = itm.findItem(cinterno); Query q = em.createNamedQuery("Itxsol.findSol_Item"); q.setParameter("numSol", new BigDecimal(numSol)); q.setParameter("cinterno", findItem); List<Itxsol> resultList = q.getResultList(); for (Itxsol r : resultList) { System.out.println(r.getCinterno().getCinterno()); } emf.close(); return resultList.get(0).getCantidadaprobada().toString(); }
From source file:Logica.Usuario.java
/** * * @param numorden/*from www.java2s. co m*/ * @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; }