public void create(ChequesProveedores chequesProveedores) { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Proveedores proveedoresidProveedores = chequesProveedores.getProveedoresidProveedores(); if (proveedoresidProveedores != null) { proveedoresidProveedores = em.getReference( proveedoresidProveedores.getClass(), proveedoresidProveedores.getIdProveedores()); chequesProveedores.setProveedoresidProveedores(proveedoresidProveedores); } Bancos bancosIdbancos = chequesProveedores.getBancosIdbancos(); if (bancosIdbancos != null) { bancosIdbancos = em.getReference(bancosIdbancos.getClass(), bancosIdbancos.getIdbancos()); chequesProveedores.setBancosIdbancos(bancosIdbancos); } em.persist(chequesProveedores); if (proveedoresidProveedores != null) { proveedoresidProveedores.getChequesProveedoresCollection().add(chequesProveedores); proveedoresidProveedores = em.merge(proveedoresidProveedores); } if (bancosIdbancos != null) { bancosIdbancos.getChequesProveedoresCollection().add(chequesProveedores); bancosIdbancos = em.merge(bancosIdbancos); } em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void edit(Room room) throws NonexistentEntityException, RollbackFailureException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Room persistentRoom = em.find(Room.class, room.getId()); Department departmentOld = persistentRoom.getDepartment(); Department departmentNew = room.getDepartment(); Category categoryOld = persistentRoom.getCategory(); Category categoryNew = room.getCategory(); if (departmentNew != null) { departmentNew = em.getReference(departmentNew.getClass(), departmentNew.getId()); room.setDepartment(departmentNew); } if (categoryNew != null) { categoryNew = em.getReference(categoryNew.getClass(), categoryNew.getId()); room.setCategory(categoryNew); } room = em.merge(room); if (departmentOld != null && !departmentOld.equals(departmentNew)) { departmentOld.getRoomCollection().remove(room); departmentOld = em.merge(departmentOld); } if (departmentNew != null && !departmentNew.equals(departmentOld)) { departmentNew.getRoomCollection().add(room); departmentNew = em.merge(departmentNew); } if (categoryOld != null && !categoryOld.equals(categoryNew)) { categoryOld.getRoomCollection().remove(room); categoryOld = em.merge(categoryOld); } if (categoryNew != null && !categoryNew.equals(categoryOld)) { categoryNew.getRoomCollection().add(room); categoryNew = em.merge(categoryNew); } em.getTransaction().commit(); } catch (Exception ex) { try { em.getTransaction().rollback(); } catch (Exception re) { throw new RollbackFailureException( "An error occurred attempting to roll back the transaction.", re); } String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { Integer id = room.getId(); if (findRoom(id) == null) { throw new NonexistentEntityException("The room with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }
public void edit(CheckoutRecord checkoutRecord) throws NonexistentEntityException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); CheckoutRecord persistentCheckoutRecord = em.find(CheckoutRecord.class, checkoutRecord.getId()); Member memberOld = persistentCheckoutRecord.getMember(); Member memberNew = checkoutRecord.getMember(); Fine fineOld = persistentCheckoutRecord.getFine(); Fine fineNew = checkoutRecord.getFine(); if (memberNew != null) { memberNew = em.getReference(memberNew.getClass(), memberNew.getUniqueMemberNumber()); checkoutRecord.setMember(memberNew); } if (fineNew != null) { fineNew = em.getReference(fineNew.getClass(), fineNew.getId()); checkoutRecord.setFine(fineNew); } checkoutRecord = em.merge(checkoutRecord); if (memberOld != null && !memberOld.equals(memberNew)) { memberOld.getRecords().remove(checkoutRecord); memberOld = em.merge(memberOld); } if (memberNew != null && !memberNew.equals(memberOld)) { memberNew.getRecords().add(checkoutRecord); memberNew = em.merge(memberNew); } if (fineOld != null && !fineOld.equals(fineNew)) { fineOld.setRecord(null); fineOld = em.merge(fineOld); } if (fineNew != null && !fineNew.equals(fineOld)) { CheckoutRecord oldRecordOfFine = fineNew.getRecord(); if (oldRecordOfFine != null) { oldRecordOfFine.setFine(null); oldRecordOfFine = em.merge(oldRecordOfFine); } fineNew.setRecord(checkoutRecord); fineNew = em.merge(fineNew); } em.getTransaction().commit(); } catch (Exception ex) { String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { long id = checkoutRecord.getId(); if (findCheckoutRecord(id) == null) { throw new NonexistentEntityException( "The checkoutRecord with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }
@RequestMapping("/determinaQuantidade") @ResponseBody public String determinaQuantidade(Integer idProdutoGrupo, Integer idGrupo) { ProdutoGrupo produto = manager.getReference(ProdutoGrupo.class, idProdutoGrupo); Grupo grupo = manager.getReference(Grupo.class, idGrupo); DeterminaQuantidades d = produtoGrupoDAO.determinaQuant(idGrupo); DeterQuantpadrao detPad = produtoGrupoDAO.deterQuantPadrao(idGrupo); DetalhesItemProducao detalhes = new DetalhesItemProducao(); BigDecimal[] valores = pegaValores(produto.getIdProdutoGrupo(), grupo.getIdgrupo()); // valores [0] = t - valorUnit; // valores [1] = p - preco; // valores [2] = q - quantDeter Bigdecimal; // valores [3] = d - Diaria Bigdecimal; double quantDeter = valores[2].doubleValue(); double diarias = valores[3].doubleValue(); double quantDiaria = quantDeter * diarias; if (d == null) { if (detPad == null) { novoDeterminaQuant(produto, grupo); } else { manager.remove(detPad); novoDeterminaQuant(produto, grupo); } } else { d.setProdutoGrupo(produto); d.setValorUnit(valores[0]); d.setPrecoTotal(valores[1]); d.setQuantDeterm(quantDeter); d.setDiarias(diarias); manager.merge(d); } String quant = valores[2].toString(); String quantDia = String.valueOf(quantDiaria); String precs = valores[1].toString(); precs = util.ConverteDolarParaReal(precs); String tots = valores[0].toString(); tots = util.ConverteDolarParaReal(tots); detalhes.setDeterminaQuant(quantDia); detalhes.setPrecoTotal(precs); detalhes.setValorUnit(tots); Gson gson = new Gson(); return gson.toJson(detalhes); }
public void create(Usuario usuario) { if (usuario.getHistoricoList() == null) { usuario.setHistoricoList(new ArrayList<Historico>()); } if (usuario.getHistoricoList1() == null) { usuario.setHistoricoList1(new ArrayList<Historico>()); } EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); List<Historico> attachedHistoricoList = new ArrayList<Historico>(); for (Historico historicoListHistoricoToAttach : usuario.getHistoricoList()) { historicoListHistoricoToAttach = em.getReference( historicoListHistoricoToAttach.getClass(), historicoListHistoricoToAttach.getIdhistorico()); attachedHistoricoList.add(historicoListHistoricoToAttach); } usuario.setHistoricoList(attachedHistoricoList); List<Historico> attachedHistoricoList1 = new ArrayList<Historico>(); for (Historico historicoList1HistoricoToAttach : usuario.getHistoricoList1()) { historicoList1HistoricoToAttach = em.getReference( historicoList1HistoricoToAttach.getClass(), historicoList1HistoricoToAttach.getIdhistorico()); attachedHistoricoList1.add(historicoList1HistoricoToAttach); } usuario.setHistoricoList1(attachedHistoricoList1); em.persist(usuario); for (Historico historicoListHistorico : usuario.getHistoricoList()) { Usuario oldAtendenteOfHistoricoListHistorico = historicoListHistorico.getAtendente(); historicoListHistorico.setAtendente(usuario); historicoListHistorico = em.merge(historicoListHistorico); if (oldAtendenteOfHistoricoListHistorico != null) { oldAtendenteOfHistoricoListHistorico.getHistoricoList().remove(historicoListHistorico); oldAtendenteOfHistoricoListHistorico = em.merge(oldAtendenteOfHistoricoListHistorico); } } for (Historico historicoList1Historico : usuario.getHistoricoList1()) { Usuario oldUsuarioOfHistoricoList1Historico = historicoList1Historico.getUsuario(); historicoList1Historico.setUsuario(usuario); historicoList1Historico = em.merge(historicoList1Historico); if (oldUsuarioOfHistoricoList1Historico != null) { oldUsuarioOfHistoricoList1Historico.getHistoricoList1().remove(historicoList1Historico); oldUsuarioOfHistoricoList1Historico = em.merge(oldUsuarioOfHistoricoList1Historico); } } em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void edit(Timereport timereport) throws NonexistentEntityException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Timereport persistentTimereport = em.find(Timereport.class, timereport.getIdtimereport()); Utilisateur idutilisateurOld = persistentTimereport.getIdutilisateur(); Utilisateur idutilisateurNew = timereport.getIdutilisateur(); Tache idtacheOld = persistentTimereport.getIdtache(); Tache idtacheNew = timereport.getIdtache(); if (idutilisateurNew != null) { idutilisateurNew = em.getReference(idutilisateurNew.getClass(), idutilisateurNew.getIdutilisateur()); timereport.setIdutilisateur(idutilisateurNew); } if (idtacheNew != null) { idtacheNew = em.getReference(idtacheNew.getClass(), idtacheNew.getIdtache()); timereport.setIdtache(idtacheNew); } timereport = em.merge(timereport); if (idutilisateurOld != null && !idutilisateurOld.equals(idutilisateurNew)) { idutilisateurOld.getTimereportCollection().remove(timereport); idutilisateurOld = em.merge(idutilisateurOld); } if (idutilisateurNew != null && !idutilisateurNew.equals(idutilisateurOld)) { idutilisateurNew.getTimereportCollection().add(timereport); idutilisateurNew = em.merge(idutilisateurNew); } if (idtacheOld != null && !idtacheOld.equals(idtacheNew)) { idtacheOld.getTimereportCollection().remove(timereport); idtacheOld = em.merge(idtacheOld); } if (idtacheNew != null && !idtacheNew.equals(idtacheOld)) { idtacheNew.getTimereportCollection().add(timereport); idtacheNew = em.merge(idtacheNew); } em.getTransaction().commit(); } catch (Exception ex) { String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { Integer id = timereport.getIdtimereport(); if (findTimereport(id) == null) { throw new NonexistentEntityException( "The timereport with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }
public void edit(Inventary inventary) throws NonexistentEntityException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Inventary persistentInventary = em.find(Inventary.class, inventary.getId()); Product productIdOld = persistentInventary.getProductId(); Product productIdNew = inventary.getProductId(); Billing billingIdOld = persistentInventary.getBillingId(); Billing billingIdNew = inventary.getBillingId(); if (productIdNew != null) { productIdNew = em.getReference(productIdNew.getClass(), productIdNew.getId()); inventary.setProductId(productIdNew); } if (billingIdNew != null) { billingIdNew = em.getReference(billingIdNew.getClass(), billingIdNew.getId()); inventary.setBillingId(billingIdNew); } inventary = em.merge(inventary); if (productIdOld != null && !productIdOld.equals(productIdNew)) { productIdOld.getInventaryList().remove(inventary); productIdOld = em.merge(productIdOld); } if (productIdNew != null && !productIdNew.equals(productIdOld)) { productIdNew.getInventaryList().add(inventary); productIdNew = em.merge(productIdNew); } if (billingIdOld != null && !billingIdOld.equals(billingIdNew)) { billingIdOld.getInventaryList().remove(inventary); billingIdOld = em.merge(billingIdOld); } if (billingIdNew != null && !billingIdNew.equals(billingIdOld)) { billingIdNew.getInventaryList().add(inventary); billingIdNew = em.merge(billingIdNew); } em.getTransaction().commit(); } catch (Exception ex) { String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { Integer id = inventary.getId(); if (findInventary(id) == null) { throw new NonexistentEntityException( "The inventary with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }
/** Find by the primary key. */ @Override public <T> T getReference(Class<T> entityClass, Object primaryKey) { EntityManager em = getCurrent(); if (em != null) return em.getReference(entityClass, primaryKey); em = createEntityManager(); try { return em.getReference(entityClass, primaryKey); } finally { freeEntityManager(em); } }
public void create(Factura factura) { if (factura.getGastoList() == null) { factura.setGastoList(new ArrayList<Gasto>()); } EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Proveedor idproveedor = factura.getIdproveedor(); if (idproveedor != null) { idproveedor = em.getReference(idproveedor.getClass(), idproveedor.getIdproveedor()); factura.setIdproveedor(idproveedor); } Usuario idusuario = factura.getIdusuario(); if (idusuario != null) { idusuario = em.getReference(idusuario.getClass(), idusuario.getIdusuario()); factura.setIdusuario(idusuario); } List<Gasto> attachedGastoList = new ArrayList<Gasto>(); for (Gasto gastoListGastoToAttach : factura.getGastoList()) { gastoListGastoToAttach = em.getReference(gastoListGastoToAttach.getClass(), gastoListGastoToAttach.getIdgasto()); attachedGastoList.add(gastoListGastoToAttach); } factura.setGastoList(attachedGastoList); em.persist(factura); if (idproveedor != null) { idproveedor.getFacturaList().add(factura); idproveedor = em.merge(idproveedor); } if (idusuario != null) { idusuario.getFacturaList().add(factura); idusuario = em.merge(idusuario); } for (Gasto gastoListGasto : factura.getGastoList()) { Factura oldIdfacturaOfGastoListGasto = gastoListGasto.getIdfactura(); gastoListGasto.setIdfactura(factura); gastoListGasto = em.merge(gastoListGasto); if (oldIdfacturaOfGastoListGasto != null) { oldIdfacturaOfGastoListGasto.getGastoList().remove(gastoListGasto); oldIdfacturaOfGastoListGasto = em.merge(oldIdfacturaOfGastoListGasto); } } em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void create(Configdecripcionlogin configdecripcionlogin) { if (configdecripcionlogin.getInfoHistoriac() == null) { configdecripcionlogin.setInfoHistoriac(new ArrayList<InfoHistoriac>()); } EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Configlogin idLogin = configdecripcionlogin.getIdLogin(); if (idLogin != null) { idLogin = em.getReference(idLogin.getClass(), idLogin.getId()); configdecripcionlogin.setIdLogin(idLogin); } List<InfoHistoriac> attachedInfoHistoriac = new ArrayList<InfoHistoriac>(); for (InfoHistoriac infoHistoriacInfoHistoriacToAttach : configdecripcionlogin.getInfoHistoriac()) { infoHistoriacInfoHistoriacToAttach = em.getReference( infoHistoriacInfoHistoriacToAttach.getClass(), infoHistoriacInfoHistoriacToAttach.getId()); attachedInfoHistoriac.add(infoHistoriacInfoHistoriacToAttach); } configdecripcionlogin.setInfoHistoriac(attachedInfoHistoriac); em.persist(configdecripcionlogin); if (idLogin != null) { idLogin.getConfigdecripcionloginList().add(configdecripcionlogin); idLogin = em.merge(idLogin); } for (InfoHistoriac infoHistoriacInfoHistoriac : configdecripcionlogin.getInfoHistoriac()) { Configdecripcionlogin oldIdConfigdecripcionloginOfInfoHistoriacInfoHistoriac = infoHistoriacInfoHistoriac.getIdConfigdecripcionlogin(); infoHistoriacInfoHistoriac.setIdConfigdecripcionlogin(configdecripcionlogin); infoHistoriacInfoHistoriac = em.merge(infoHistoriacInfoHistoriac); if (oldIdConfigdecripcionloginOfInfoHistoriacInfoHistoriac != null) { oldIdConfigdecripcionloginOfInfoHistoriacInfoHistoriac .getInfoHistoriac() .remove(infoHistoriacInfoHistoriac); oldIdConfigdecripcionloginOfInfoHistoriacInfoHistoriac = em.merge(oldIdConfigdecripcionloginOfInfoHistoriacInfoHistoriac); } } em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void create(Usuario usuario) throws PreexistingEntityException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Investigador investigadorIdentificacion = usuario.getInvestigadorIdentificacion(); if (investigadorIdentificacion != null) { investigadorIdentificacion = em.getReference( investigadorIdentificacion.getClass(), investigadorIdentificacion.getIdentificacion()); usuario.setInvestigadorIdentificacion(investigadorIdentificacion); } em.persist(usuario); if (investigadorIdentificacion != null) { investigadorIdentificacion.getUsuarioList().add(usuario); investigadorIdentificacion = em.merge(investigadorIdentificacion); } em.getTransaction().commit(); } catch (Exception ex) { if (findUsuario(usuario.getNombre()) != null) { throw new PreexistingEntityException("Usuario " + usuario + " already exists.", ex); } throw ex; } finally { if (em != null) { em.close(); } } }
public void destroy(String id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Usuario usuario; try { usuario = em.getReference(Usuario.class, id); usuario.getNombre(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The usuario with id " + id + " no longer exists.", enfe); } Investigador investigadorIdentificacion = usuario.getInvestigadorIdentificacion(); if (investigadorIdentificacion != null) { investigadorIdentificacion.getUsuarioList().remove(usuario); investigadorIdentificacion = em.merge(investigadorIdentificacion); } em.remove(usuario); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); TipoClasePuc tipoClasePuc; try { tipoClasePuc = em.getReference(TipoClasePuc.class, id); tipoClasePuc.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The tipoClasePuc with id " + id + " no longer exists.", enfe); } List<ClasePuc> clasePucList = tipoClasePuc.getClasePucList(); for (ClasePuc clasePucListClasePuc : clasePucList) { clasePucListClasePuc.setIdClase(null); clasePucListClasePuc = em.merge(clasePucListClasePuc); } em.remove(tipoClasePuc); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(String id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Permisos permisos; try { permisos = em.getReference(Permisos.class, id); permisos.getUsuarioId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The permisos with id " + id + " no longer exists.", enfe); } Usuario usuario = permisos.getUsuario(); if (usuario != null) { usuario.setPermisos(null); usuario = em.merge(usuario); } em.remove(permisos); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
/** * Deletes the authorization after removing it from any groups that might be referring to it * * @param em the entity manager reference * @param id the ID for authorizatino entity * @throws PersistenceException if there were any errors deleting the authorization */ static void deleteAuthorization(EntityManager em, long id) throws PersistenceException { Authorization auth = em.find(Authorization.class, id); // may return null, if this entity is not saved, in which // case don't do anything. if (auth == null) { return; } // Iterate through all groups and remove the authorization from them Set<SummaryGroup> groups = auth.getGroups(); if (groups != null) { for (SummaryGroup g : groups) { Group group = new SingleGroupQuery(g.getId()).fetch(); Set<Authorization> auths = group.getAuthorizations(); HashSet<Authorization> updated = new HashSet<Authorization>(); for (Authorization a : auths) { if (a.getId() != auth.getId()) { updated.add(a); } } group.setAuthorizations(updated); group.save(); } } em.remove(em.getReference(Authorization.class, auth.getId())); }
public void create(BarEntity bar) throws PreexistingEntityException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); ContractEntity contract = bar.getContract(); if (contract != null) { contract = em.getReference(contract.getClass(), contract.getId()); bar.setContract(contract); } em.persist(bar); if (contract != null) { contract.getBarCollection().add(bar); contract = em.merge(contract); } em.getTransaction().commit(); } catch (Exception ex) { if (findBar(bar.getId()) != null) { throw new PreexistingEntityException("Bar " + bar + " already exists.", ex); } throw ex; } finally { if (em != null /*&& em.isOpen()*/) { em.close(); } } }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); ChequesProveedores chequesProveedores; try { chequesProveedores = em.getReference(ChequesProveedores.class, id); chequesProveedores.getIdchequesProveedores(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The chequesProveedores with id " + id + " no longer exists.", enfe); } Proveedores proveedoresidProveedores = chequesProveedores.getProveedoresidProveedores(); if (proveedoresidProveedores != null) { proveedoresidProveedores.getChequesProveedoresCollection().remove(chequesProveedores); proveedoresidProveedores = em.merge(proveedoresidProveedores); } Bancos bancosIdbancos = chequesProveedores.getBancosIdbancos(); if (bancosIdbancos != null) { bancosIdbancos.getChequesProveedoresCollection().remove(chequesProveedores); bancosIdbancos = em.merge(bancosIdbancos); } em.remove(chequesProveedores); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(BitacoraId id) throws NonexistentEntityException, RollbackFailureException, Exception { EntityManager em = null; try { utx.begin(); em = getEntityManager(); Bitacora bitacora; try { bitacora = em.getReference(Bitacora.class, id); bitacora.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The bitacora with id " + id + " no longer exists.", enfe); } em.remove(bitacora); utx.commit(); } catch (Exception ex) { try { utx.rollback(); } catch (Exception re) { throw new RollbackFailureException( "An error occurred attempting to roll back the transaction.", re); } throw ex; } finally { if (em != null) { em.close(); } } }
public void edit(CategHabitacion categHabitacion) throws NonexistentEntityException, Exception { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); CategHabitacion persistentCategHabitacion = em.find(CategHabitacion.class, categHabitacion.getCodigoCategoria()); Collection<Habitacion> habitacionCollectionOld = persistentCategHabitacion.getHabitacionCollection(); Collection<Habitacion> habitacionCollectionNew = categHabitacion.getHabitacionCollection(); Collection<Habitacion> attachedHabitacionCollectionNew = new ArrayList<Habitacion>(); for (Habitacion habitacionCollectionNewHabitacionToAttach : habitacionCollectionNew) { habitacionCollectionNewHabitacionToAttach = em.getReference( habitacionCollectionNewHabitacionToAttach.getClass(), habitacionCollectionNewHabitacionToAttach.getNumero()); attachedHabitacionCollectionNew.add(habitacionCollectionNewHabitacionToAttach); } habitacionCollectionNew = attachedHabitacionCollectionNew; categHabitacion.setHabitacionCollection(habitacionCollectionNew); categHabitacion = em.merge(categHabitacion); for (Habitacion habitacionCollectionOldHabitacion : habitacionCollectionOld) { if (!habitacionCollectionNew.contains(habitacionCollectionOldHabitacion)) { habitacionCollectionOldHabitacion.setCodigoCategoria(null); habitacionCollectionOldHabitacion = em.merge(habitacionCollectionOldHabitacion); } } for (Habitacion habitacionCollectionNewHabitacion : habitacionCollectionNew) { if (!habitacionCollectionOld.contains(habitacionCollectionNewHabitacion)) { CategHabitacion oldCodigoCategoriaOfHabitacionCollectionNewHabitacion = habitacionCollectionNewHabitacion.getCodigoCategoria(); habitacionCollectionNewHabitacion.setCodigoCategoria(categHabitacion); habitacionCollectionNewHabitacion = em.merge(habitacionCollectionNewHabitacion); if (oldCodigoCategoriaOfHabitacionCollectionNewHabitacion != null && !oldCodigoCategoriaOfHabitacionCollectionNewHabitacion.equals(categHabitacion)) { oldCodigoCategoriaOfHabitacionCollectionNewHabitacion .getHabitacionCollection() .remove(habitacionCollectionNewHabitacion); oldCodigoCategoriaOfHabitacionCollectionNewHabitacion = em.merge(oldCodigoCategoriaOfHabitacionCollectionNewHabitacion); } } } em.getTransaction().commit(); } catch (Exception ex) { String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { Integer id = categHabitacion.getCodigoCategoria(); if (findCategHabitacion(id) == null) { throw new NonexistentEntityException( "The categHabitacion with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); CategHabitacion categHabitacion; try { categHabitacion = em.getReference(CategHabitacion.class, id); categHabitacion.getCodigoCategoria(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The categHabitacion with id " + id + " no longer exists.", enfe); } Collection<Habitacion> habitacionCollection = categHabitacion.getHabitacionCollection(); for (Habitacion habitacionCollectionHabitacion : habitacionCollection) { habitacionCollectionHabitacion.setCodigoCategoria(null); habitacionCollectionHabitacion = em.merge(habitacionCollectionHabitacion); } em.remove(categHabitacion); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Inventary inventary; try { inventary = em.getReference(Inventary.class, id); inventary.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The inventary with id " + id + " no longer exists.", enfe); } Product productId = inventary.getProductId(); if (productId != null) { productId.getInventaryList().remove(inventary); productId = em.merge(productId); } Billing billingId = inventary.getBillingId(); if (billingId != null) { billingId.getInventaryList().remove(inventary); billingId = em.merge(billingId); } em.remove(inventary); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Tema tema; try { tema = em.getReference(Tema.class, id); tema.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException("The tema with id " + id + " no longer exists.", enfe); } Clase idAreaDerecho = tema.getIdAreaDerecho(); if (idAreaDerecho != null) { idAreaDerecho.getTemaList().remove(tema); idAreaDerecho = em.merge(idAreaDerecho); } List<Normatividad> normatividadList = tema.getNormatividadList(); for (Normatividad normatividadListNormatividad : normatividadList) { normatividadListNormatividad.setIdTema(null); normatividadListNormatividad = em.merge(normatividadListNormatividad); } List<Proceso> procesoList = tema.getProcesoList(); for (Proceso procesoListProceso : procesoList) { procesoListProceso.setIdTema(null); procesoListProceso = em.merge(procesoListProceso); } em.remove(tema); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(long id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); CheckoutRecord checkoutRecord; try { checkoutRecord = em.getReference(CheckoutRecord.class, id); checkoutRecord.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The checkoutRecord with id " + id + " no longer exists.", enfe); } Member member = checkoutRecord.getMember(); if (member != null) { member.getRecords().remove(checkoutRecord); member = em.merge(member); } Fine fine = checkoutRecord.getFine(); if (fine != null) { fine.setRecord(null); fine = em.merge(fine); } em.remove(checkoutRecord); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Carrera carrera; try { carrera = em.getReference(Carrera.class, id); carrera.getIdCarrera(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The carrera with id " + id + " no longer exists.", enfe); } Collection<Alumno> alumnoCollection = carrera.getAlumnoCollection(); for (Alumno alumnoCollectionAlumno : alumnoCollection) { alumnoCollectionAlumno.setIdCarreraFK(null); alumnoCollectionAlumno = em.merge(alumnoCollectionAlumno); } em.remove(carrera); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void deletar(final Integer id) { try { getEntityManager().remove(em.getReference(clazz, id)); } catch (Exception e) { System.out.print("Erro ao excluir!"); } }
/** * Returns the resolved MulchEvents entity. * * @return an resolved entity */ public MulchEvent resolveEntity(EntityManager em) { MulchLevel mulchLevels = entity.getMulchLevel(); if (mulchLevels != null) { entity.setMulchLevel(em.getReference(MulchLevel.class, mulchLevels.getMulchLevelPK())); } return entity; }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); BarEntity bar; try { bar = em.getReference(BarEntity.class, id); bar.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException("The bar with id " + id + " no longer exists.", enfe); } ContractEntity contract = bar.getContract(); if (contract != null) { contract.getBarCollection().remove(bar); contract = em.merge(contract); } em.remove(bar); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void destroy(String id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Cliente cliente; try { cliente = em.getReference(Cliente.class, id); cliente.getIdCliente(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The cliente with id " + id + " no longer exists.", enfe); } List<Venta> ventaList = cliente.getVentaList(); for (Venta ventaListVenta : ventaList) { ventaListVenta.setIdCliente(null); ventaListVenta = em.merge(ventaListVenta); } em.remove(cliente); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }
public void edit(Long altId, Vote vote) throws NonExistingEntityException, RollbackFailureException, Exception { Alternative alternative = em.find(Alternative.class, altId); if (alternative == null) { throw new NonExistingEntityException("Alternative with Id = " + altId + " does not exist"); } vote.setAlternative(alternative); Vote persistentVote = em.find(Vote.class, vote.getId()); Alternative alternativeOld = persistentVote.getAlternative(); Alternative alternativeNew = vote.getAlternative(); if (alternativeNew != null) { alternativeNew = em.getReference(alternativeNew.getClass(), alternativeNew.getId()); vote.setAlternative(alternativeNew); } vote = em.merge(vote); if (alternativeOld != null && !alternativeOld.equals(alternativeNew)) { alternativeOld.getVotes().remove(vote); alternativeOld = em.merge(alternativeOld); } if (alternativeNew != null && !alternativeNew.equals(alternativeOld)) { alternativeNew.getVotes().add(vote); alternativeNew = em.merge(alternativeNew); } }
public void destroy(Integer id) throws NonexistentEntityException { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); Telefonos telefonos; try { telefonos = em.getReference(Telefonos.class, id); telefonos.getId(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The telefonos with id " + id + " no longer exists.", enfe); } DatosPersonales codigoPersona = telefonos.getCodigoPersona(); if (codigoPersona != null) { codigoPersona.getTelefonosCollection().remove(telefonos); codigoPersona = em.merge(codigoPersona); } em.remove(telefonos); em.getTransaction().commit(); } finally { if (em != null) { em.close(); } } }