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 create(Bitacora bitacora) throws PreexistingEntityException, RollbackFailureException, Exception { if (bitacora.getId() == null) { bitacora.setId(new BitacoraId()); } EntityManager em = null; try { utx.begin(); em = getEntityManager(); em.persist(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); } if (findBitacora(bitacora.getId()) != null) { throw new PreexistingEntityException("Bitacora " + bitacora + " already exists.", ex); } throw ex; } finally { if (em != null) { em.close(); } } }
public void edit(Bitacora bitacora) throws NonexistentEntityException, RollbackFailureException, Exception { EntityManager em = null; try { utx.begin(); em = getEntityManager(); bitacora = em.merge(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); } String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { BitacoraId id = bitacora.getId(); if (findBitacora(id) == null) { throw new NonexistentEntityException("The bitacora with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }