List of usage examples for javax.persistence EntityManager close
public void close();
From source file:eu.optimis.trustedinstance.DBStorage.java
@SuppressWarnings("finally") public boolean store(DBStorageEntry entry) throws Exception { if (update(entry)) { return true; }/*from ww w .ja v a 2s. c o m*/ boolean result = true; EntityManager em = emf.createEntityManager(); try { em.getTransaction().begin(); em.persist(entry); em.getTransaction().commit(); } catch (Exception e) { result = false; throw e; } finally { em.close(); return result; } }
From source file:com.thruzero.domain.jpa.transaction.JpaDatabaseTransactionMgr.java
@Override public void commitTransaction() { if (isTransactionActive()) { EntityManager entityManager = doGetCurrentPersistenceManager(false); entityManager.getTransaction().commit(); if (entityManager.isOpen()) { entityManager.close(); }/*from w w w . j a va 2 s .c o m*/ } }
From source file:com.thruzero.domain.jpa.transaction.JpaDatabaseTransactionMgr.java
@Override public void rollbackTransaction() { if (isTransactionActive()) { EntityManager entityManager = doGetCurrentPersistenceManager(false); entityManager.getTransaction().rollback(); if (entityManager.isOpen()) { entityManager.close(); }/*ww w . j a va 2 s. c o m*/ } }
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();/*from w ww . ja va 2s . co m*/ try { mgr.persist(vessel); xa.commit(); success = true; } catch (Exception ignoreMe) { rollbackQuietly(xa); } finally { mgr.close(); } return success; }
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 ww w . j av a 2s. co 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.webbfontaine.valuewebb.action.tt.TtLogger.java
public String deleteUserLog(TtLog log) { EntityManager entityManager = null; try {//from w ww . j av a2 s. com entityManager = Utils.createEntityManager(); entityManager.remove(entityManager.merge(log)); entityManager.flush(); reloadLogs(log); } finally { if (entityManager != null) { entityManager.close(); } } return ""; }
From source file:com.yahoo.sql4d.indexeragent.meta.DBHandler.java
/** * /*from w w w. j a va 2s .c om*/ * @return */ public long getInprogressTasksCount() { EntityManager em = getEntityManager(); try { return (long) em.createQuery("SELECT COUNT(st.id) FROM StatusTrail st WHERE " + " st.status = 'in_progress' AND st.givenUp = 0").getSingleResult(); } finally { em.close(); } }
From source file:com.epam.training.taranovski.web.project.repository.implementation.UserSkillRepositoryImplementation.java
@Override public UserSkill getById(int id) { EntityManager em = entityManagerFactory.createEntityManager(); UserSkill userSkill;//from ww w .j ava2 s . co m try { em.getTransaction().begin(); userSkill = em.find(UserSkill.class, id); em.getTransaction().commit(); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return userSkill; }
From source file:edu.csueb.cs6320.utils.UserService.java
public List<User> getUserList() { EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager(); em.getTransaction().begin();//from ww w .ja va 2s.com List<User> users = em.createQuery("SELECT u FROM User u", User.class).getResultList(); em.getTransaction().commit(); em.close(); return users; }
From source file:facades.PersonFacadeDB.java
@Override public Person addPerson(String json) { //make person from Json Person p = gson.fromJson(json, Person.class); EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceFileName); EntityManager em = emf.createEntityManager(); EntityTransaction transaction = em.getTransaction(); transaction.begin();/*from www . ja va2 s . co m*/ try { em.persist(p); transaction.commit(); } catch (Exception e) { transaction.rollback(); } finally { em.close(); } return p; }