List of usage examples for javax.persistence EntityTransaction begin
public void begin();
From source file:com.netflix.dse.pig2json.model.PersistTest.java
@Test public void persistPlan() throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); P2jPlanPackage p = mapper.readValue(PersistTest.class.getResourceAsStream("/test.json"), P2jPlanPackage.class); EntityTransaction et = em.getTransaction(); et.begin(); em.persist(p);/*from w w w. java2 s .co m*/ em.flush(); et.commit(); P2jPlanPackage p2 = em.find(P2jPlanPackage.class, p.getId()); String j = mapper.writeValueAsString(p); String j2 = mapper.writeValueAsString(p2); Assert.assertEquals(j2, j); }
From source file:modelo.DaoTiposActividadesImpl.java
@Transactional() @Override/*from ww w. j a v a2 s . c o m*/ public void guardarActividad(TipoActividad act) { EntityTransaction tx = em.getTransaction(); tx.begin(); em.persist(act); tx.commit(); em.close(); }
From source file:com.netflix.dse.pig2json.model.PersistTest.java
@Test public void persistStatus() throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); StringWriter writer = new StringWriter(); IOUtils.copy(PersistTest.class.getResourceAsStream("/status.json"), writer, "UTF-8"); P2jPlanStatus p = mapper.readValue(PersistTest.class.getResourceAsStream("/status.json"), P2jPlanStatus.class); EntityTransaction et = em.getTransaction(); et.begin(); em.persist(p);/*from w w w . j a v a 2 s. c o m*/ em.flush(); et.commit(); P2jPlanStatus p2 = em.find(P2jPlanStatus.class, p.getId()); String j = mapper.writeValueAsString(p); String j2 = mapper.writeValueAsString(p2); Assert.assertEquals(j2, j); }
From source file:modelo.DaoTiposActividadesImpl.java
@Override public void eliminarActividad(int idtipoActividad) { /* EntityManager em=this.obtenerEntityManager(); Actividad act=em.find(Actividad.class,idactividades); EntityTransaction tx=em.getTransaction(); tx.begin();/*w w w. ja va 2 s. com*/ em.remove(act); tx.commit(); em.close();*/ String jpql = "delete from Actividad act where act.idactividades=?1"; Query q = em.createQuery(jpql); q.setParameter(1, idtipoActividad); EntityTransaction tx = em.getTransaction(); tx.begin(); q.executeUpdate(); tx.commit(); em.close(); }
From source file:org.spc.ofp.tubs.domain.purseseine.TripRepository.java
public void update(final PurseSeineTrip trip) { final EntityManager mgr = emf.createEntityManager(); final EntityTransaction xa = mgr.getTransaction(); try {/*from ww w.jav a2 s. c o m*/ xa.begin(); mgr.merge(trip); xa.commit(); } catch (Exception ex) { if (xa.isActive()) { xa.rollback(); } } finally { mgr.close(); } }
From source file:org.spc.ofp.tubs.domain.purseseine.TripRepository.java
public void save(final PurseSeineTrip trip) { final EntityManager mgr = emf.createEntityManager(); final EntityTransaction xa = mgr.getTransaction(); try {//from w w w . j a v a 2 s . c o m xa.begin(); mgr.persist(trip); mgr.flush(); xa.commit(); mgr.refresh(trip); } catch (Exception ex) { if (xa.isActive()) { xa.rollback(); } } finally { mgr.close(); } }
From source file:com.sixsq.slipstream.persistence.Run.java
public static Run abortOrReset(String abortMessage, String nodename, String uuid) { EntityManager em = PersistenceUtil.createEntityManager(); EntityTransaction transaction = em.getTransaction(); transaction.begin(); Run run = Run.abortOrReset(abortMessage, nodename, em, uuid); transaction.commit();//from w w w . ja va 2s .co m em.close(); return run; }
From source file:com.appdynamics.loan.persistence.BasePersistenceImpl.java
@Transactional public void delete(Serializable object) { EntityManager entityManager = getEntityManager(); EntityTransaction txn = entityManager.getTransaction(); txn.begin(); try {// w ww . j a va2s .com entityManager.remove(object); } catch (Exception ex) { txn.rollback(); } finally { if (!txn.getRollbackOnly()) { txn.commit(); } } }
From source file:com.sixsq.slipstream.persistence.Run.java
public static Run updateRunState(Run run, States newState, boolean retry) { EntityManager em = PersistenceUtil.createEntityManager(); EntityTransaction transaction = em.getTransaction(); transaction.begin(); try {/*from w ww.j ava 2 s . com*/ run = Run.loadFromUuid(run.getUuid(), em); run.setState(newState); transaction.commit(); em.close(); } catch (Exception e) { String error = "error setting run state: " + newState; if (retry) { Logger.getLogger("restlet").warning(error + " retrying..."); } else { Logger.getLogger("restlet").severe(error); } // retry once if (retry) { updateRunState(run, newState, false); } } return run; }
From source file:com.appdynamics.loan.persistence.BasePersistenceImpl.java
/** * The method to update the serailizable business objects into the database. * //w w w. j a v a 2 s .c o m * @param object -- * serializable object * @throws PersistenceException */ @Transactional public void update(final Serializable object) { EntityManager entityManager = getEntityManager(); EntityTransaction txn = entityManager.getTransaction(); txn.begin(); try { entityManager.merge(object); } catch (Exception ex) { txn.rollback(); } finally { if (!txn.getRollbackOnly()) { txn.commit(); } } }