コード例 #1
0
 public void destroy(Integer id)
     throws NonexistentEntityException, RollbackFailureException, Exception {
   EntityManager em = null;
   try {
     utx.begin();
     em = getEntityManager();
     City city;
     try {
       city = em.getReference(City.class, id);
       city.getId();
     } catch (EntityNotFoundException enfe) {
       throw new NonexistentEntityException("The city with id " + id + " no longer exists.", enfe);
     }
     em.remove(city);
     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();
     }
   }
 }
コード例 #2
0
 public void edit(City city)
     throws NonexistentEntityException, RollbackFailureException, Exception {
   EntityManager em = null;
   try {
     utx.begin();
     em = getEntityManager();
     city = em.merge(city);
     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) {
       Integer id = city.getId();
       if (findCity(id) == null) {
         throw new NonexistentEntityException("The city with id " + id + " no longer exists.");
       }
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }