List of usage examples for javax.persistence EntityTransaction commit
public void commit();
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();// www . j av a 2 s . c om em.persist(p); 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: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 w w w . j av a 2 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: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();//from w ww. ja v a2s . c o m em.persist(p); 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:test.unit.be.fedict.trust.service.PersistenceTest.java
private void refresh() { // we clear the hibernate cache EntityTransaction entityTransaction = this.entityManager.getTransaction(); entityTransaction.commit(); this.entityManager.clear(); entityTransaction.begin();//from w w w .ja v a 2s . c om }
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 {/* w ww. j a va2 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();//from www .j a v a 2 s . com Run run = Run.abortOrReset(abortMessage, nodename, em, uuid); transaction.commit(); em.close(); return run; }
From source file:it.infn.ct.futuregateway.apiserver.resources.observers.TaskObserver.java
@Override public final void update(final Observable obs, final Object arg) { if (!(obs instanceof Task)) { log.error("Wrong abject associated with the oserver"); }/*from www .j ava 2 s . c om*/ Task t = (Task) obs; if (t.getId() == null || t.getStatus() == null) { return; } log.debug("Task " + t.getId() + " updated"); if (t.getStatus().equals(Task.STATUS.WAITING) && t.getApplicationDetail() != null) { if (t.getInputFiles() != null) { for (TaskFile tf : t.getInputFiles()) { if (tf.getStatus().equals(TaskFile.FILESTATUS.NEEDED)) { return; } } } t.setStatus(Task.STATUS.READY); submit(t); } EntityManager em = emf.createEntityManager(); EntityTransaction et = em.getTransaction(); try { et.begin(); em.merge(t); et.commit(); } catch (RuntimeException re) { log.error("Impossible to update the task!"); log.error(re); if (et != null && et.isActive()) { et.rollback(); } } finally { em.close(); } }
From source file:com.medigy.persist.Ejb3TestCase.java
protected void tearDown() throws Exception { final EntityManager entityManager = getEntityManager(); final EntityTransaction transaction = entityManager.getTransaction(); SetupTestConfiguration.getInstance().getPostInsertEventListener().deleteEntityList(entityManager); transaction.commit(); entityManager.close();/*from w w w . j a v a2 s.c om*/ SessionManager.getInstance().popActiveSession(); }
From source file:org.spc.ofp.tubs.domain.common.CommonRepository.java
public boolean saveVessel(final Vessel vessel) { boolean success = false; final EntityManager mgr = emf.createEntityManager(); final EntityTransaction xa = mgr.getTransaction(); xa.begin();// w ww . java2s . c o m try { mgr.persist(vessel); xa.commit(); success = true; } catch (Exception ignoreMe) { rollbackQuietly(xa); } finally { mgr.close(); } return success; }
From source file:it.infn.ct.futuregateway.apiserver.v1.InfrastructureCollectionService.java
/** * Register a new infrastructure./* w w w .j a v a 2 s. co m*/ * * @param infra The infrastructure to register * @return The registered infrastructure */ @POST @Status(Response.Status.CREATED) @Consumes({ MediaType.APPLICATION_JSON, Constants.INDIGOMIMETYPE }) @Produces(Constants.INDIGOMIMETYPE) public final Infrastructure createInfrastructure(final Infrastructure infra) { Date now = new Date(); infra.setDateCreated(now); EntityManager em = getEntityManager(); EntityTransaction et = null; try { et = em.getTransaction(); et.begin(); em.persist(infra); et.commit(); log.debug("New infrastructure registered: " + infra.getId()); } catch (RuntimeException re) { if (et != null && et.isActive()) { et.rollback(); } log.error("Impossible to create the infrastructure"); log.error(re); } finally { em.close(); } return infra; }