Ejemplo n.º 1
0
 public void destroy(Integer id) throws NonexistentEntityException {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Contribuyente contribuyente;
     try {
       contribuyente = em.getReference(Contribuyente.class, id);
       contribuyente.getDni();
     } catch (EntityNotFoundException enfe) {
       throw new NonexistentEntityException(
           "The contribuyente with id " + id + " no longer exists.", enfe);
     }
     em.remove(contribuyente);
     em.getTransaction().commit();
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
Ejemplo n.º 2
0
 public void create(Contribuyente contribuyente) throws PreexistingEntityException, Exception {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     em.persist(contribuyente);
     em.getTransaction().commit();
   } catch (Exception ex) {
     if (findContribuyente(contribuyente.getDni()) != null) {
       throw new PreexistingEntityException(
           "Contribuyente " + contribuyente + " already exists.", ex);
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
Ejemplo n.º 3
0
 public void edit(Contribuyente contribuyente) throws NonexistentEntityException, Exception {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     contribuyente = em.merge(contribuyente);
     em.getTransaction().commit();
   } catch (Exception ex) {
     String msg = ex.getLocalizedMessage();
     if (msg == null || msg.length() == 0) {
       Integer id = contribuyente.getDni();
       if (findContribuyente(id) == null) {
         throw new NonexistentEntityException(
             "The contribuyente with id " + id + " no longer exists.");
       }
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }