List of usage examples for javax.persistence EntityManager close
public void close();
From source file:it.infn.ct.futuregateway.apiserver.v1.InfrastructureService.java
/** * Retrieve the infrastructure details.// ww w. j a v a 2 s .c o m * Infrastructure details include all the information needed to access the * remote infrastructure. * * @param id The infrastructure id. This is a path parameter retrieved from * the URL * @return The infrastructure */ @GET @Produces(Constants.INDIGOMIMETYPE) public final Infrastructure getInfraDetails(@PathParam("id") final String id) { Infrastructure infra; EntityManager em = getEntityManager(); try { infra = em.find(Infrastructure.class, id); } catch (IllegalArgumentException re) { log.error("Impossible to retrieve the application"); log.error(re); throw new RuntimeException("Impossible to access the application " + "list"); } finally { em.close(); } if (infra == null) { throw new NotFoundException(); } else { return infra; } }
From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancySkillRepositoryImplementation.java
@Override public VacancySkill getById(int id) { EntityManager em = entityManagerFactory.createEntityManager(); VacancySkill vacancySkill;/*from w ww.j av a 2 s . c o m*/ try { em.getTransaction().begin(); vacancySkill = em.find(VacancySkill.class, id); em.getTransaction().commit(); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return vacancySkill; }
From source file:com.yahoo.sql4d.indexeragent.meta.DBHandler.java
/** * //from w w w.ja v a 2s. c o m * @return */ public List<StatusTrail> getAllInprogressTasks() { EntityManager em = getEntityManager(); try { return em.createQuery( "SELECT st FROM StatusTrail st WHERE " + " st.status = 'in_progress' AND st.givenUp = 0", StatusTrail.class).getResultList(); } finally { em.close(); } }
From source file:eu.optimis.trustedinstance.DBStorage.java
@SuppressWarnings("finally") public DBStorageEntry get(String resourceKey) throws Exception { DBStorageEntry result = null;// w w w . j a v a2s. com EntityManager em = emf.createEntityManager(); try { em.getTransaction().begin(); result = (DBStorageEntry) em.find(DBStorageEntry.class, resourceKey); em.getTransaction().commit(); } catch (Exception e) { result = null; throw e; } finally { em.close(); return result; } }
From source file:cz.fi.muni.pa165.dto.PrintedBookDAOTest.java
@Test public void testFindPrintedBooks() { EntityManager em = emf.createEntityManager(); PrintedBookDAOImpl pbDAO = new PrintedBookDAOImpl(); pbDAO.setManager(em);//from www. j av a2s .c om Book b = new Book(); b.setIdBook(1); List<PrintedBook> l = pbDAO.findPrintedBooks(b); em.close(); assertEquals(2, l.size()); }
From source file:com.webbfontaine.valuewebb.irms.impl.data.AttachedDocDataSource.java
@Override public InputStream getInputStream() throws IOException { EntityManager entityManager = Utils.createEntityManager(); try {//from w ww. j a v a2s. co m // We should always be able to find attached doc for already persisted TT Blob data = (Blob) entityManager.createNativeQuery(SELECT_QUERY).setParameter(1, docId) .getSingleResult(); return stream(data); } catch (Exception e) { throw Throwables.propagate(e); } finally { entityManager.close(); } }
From source file:com.espirit.moddev.examples.uxbridge.newswidget.test.CommandITCase.java
/** * Count articles.// ww w .j a v a 2s . co m * * @return the long * @throws Exception the exception */ private long countArticles() throws Exception { EntityManager em = emf.createEntityManager(); Query query = em.createQuery("SELECT COUNT(p.title) FROM article p"); Long countResult = (Long) query.getSingleResult(); em.close(); return countResult; }
From source file:it.infn.ct.futuregateway.apiserver.v1.TaskService.java
/** * Retrieves the task details. Task details include all the fields a task * consist of as described in the documentation. This include all the * information included in the task collection and many others. * * @param id The task id. This is a path parameter retrieved from the url * @return The task/*from ww w . j a v a 2s. c o m*/ */ @GET @Produces(Constants.INDIGOMIMETYPE) public final Task getTaskDetails(@PathParam("id") final String id) { Task task; EntityManager em = getEntityManager(); try { task = em.find(Task.class, id); } catch (IllegalArgumentException re) { log.error("Impossible to retrieve the task"); log.error(re); throw new RuntimeException("Impossible to access the task list"); } finally { em.close(); } if (task == null) { throw new NotFoundException(); } else { log.debug("Associated " + task.getInputFiles().size() + " files"); return task; } }
From source file:com.epam.training.taranovski.spring.repository.oracle.AdminRepositoryOracle.java
/** * * @param id//from w ww . j a v a 2s . c om * @return */ @Override public Admin getById(int id) { EntityManager em = emf.createEntityManager(); Admin admin; try { em.getTransaction().begin(); admin = em.find(Admin.class, id); em.getTransaction().commit(); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return admin; }
From source file:cz.fi.muni.pa165.dto.PrintedBookDAOTest.java
@Test public void testFind() { EntityManager em = emf.createEntityManager(); PrintedBookDAOImpl pbDAO = new PrintedBookDAOImpl(); pbDAO.setManager(em);/*from ww w.j a v a 2 s.c o m*/ PrintedBook book = new PrintedBook(); book.setIdPrintedBook(1); PrintedBook pb = pbDAO.find(book); em.close(); assertEquals(1, pb.getIdPrintedBook()); }