List of usage examples for javax.persistence EntityManager close
public void close();
From source file:com.sixsq.slipstream.persistence.Run.java
public static List<Run> listAll() throws ConfigurationException, ValidationException { EntityManager em = PersistenceUtil.createEntityManager(); Query q = createNamedQuery(em, "allRuns"); @SuppressWarnings("unchecked") List<Run> runs = q.getResultList(); em.close(); return runs;// w w w . j ava 2s . c o m }
From source file:vn.edu.vnuk.tasks_jpa.dao.TaskDao.java
public void delete(Long id) throws SQLException { Task task = this.read(id); EntityManager manager = getEntityManager(); manager.getTransaction().begin();/* ww w .j a va 2 s . co m*/ task = manager.merge(task); manager.remove(task); manager.getTransaction().commit(); manager.close(); }
From source file:com.sixsq.slipstream.persistence.Run.java
public static Run loadRunWithRuntimeParameters(String uuid) throws ConfigurationException, ValidationException { EntityManager em = PersistenceUtil.createEntityManager(); Query q = createNamedQuery(em, "runWithRuntimeParameters"); q.setParameter("uuid", uuid); Run run = (Run) q.getSingleResult(); em.close(); return run;//from ww w . ja v a2 s.c o m }
From source file:cz.fi.muni.pa165.daoImpl.TroopDAOImpl.java
@Override public List<Troop> getAllTroops() { EntityManager em = emf.createEntityManager(); em.getTransaction().begin();/*from ww w .j a v a2s. c om*/ List<Troop> troops = em.createQuery("SELECT t FROM Troop t", Troop.class).getResultList(); em.getTransaction().commit(); em.close(); return troops; }
From source file:com.soen.ebanking.dao.ObjectDao.java
public void addObject(Object entity) { EntityManager em = this.getEMF().createEntityManager(); try {/*from w w w . ja v a 2 s . c o m*/ em.getTransaction().begin(); em.persist(entity); em.getTransaction().commit(); } finally { em.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 ww w. j av a 2s . c o m Run run = Run.abortOrReset(abortMessage, nodename, em, uuid); transaction.commit(); em.close(); return run; }
From source file:org.croodie.resource.UserServerResource.java
@Override public Representation createUser(User user) { EntityManagerFactory emf = EMF.get(); EntityManager em = emf.createEntityManager(); try {// w ww.j av a 2 s. co m em.persist(user); } catch (Exception ex) { throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Internal Server Error", ex); } finally { em.close(); } return new JacksonRepresentation<User>(user); }
From source file:com.srotya.tau.api.ApplicationManager.java
/** * @param appConfiguration//from w ww . java 2s. c om */ public void init(AppConfig appConfiguration) { config = new Properties(System.getProperties()); if (appConfiguration.getTauConfig() != null) { try { config.load(new FileInputStream(appConfiguration.getTauConfig())); } catch (IOException e) { throw new RuntimeException("Configuration file not loaded", e); } } else { try { config.load( ApplicationManager.class.getClassLoader().getResourceAsStream("default-config.properties")); } catch (IOException e) { throw new RuntimeException("Default configuration file not loaded", e); } } try { Utils.createDatabase(config.getProperty(JAVAX_PERSISTENCE_JDBC_URL), config.getProperty(JAVAX_PERSISTENCE_JDBC_DB, "tau"), config.getProperty(JAVAX_PERSISTENCE_JDBC_USER), config.getProperty(JAVAX_PERSISTENCE_JDBC_PASSWORD), config.getProperty(JAVAX_PERSISTENCE_JDBC_DRIVER)); } catch (Exception e) { throw new RuntimeException(e); } config.setProperty(JAVAX_PERSISTENCE_JDBC_URL, config.getProperty(JAVAX_PERSISTENCE_JDBC_URL) + config.getProperty(JAVAX_PERSISTENCE_JDBC_DB, "tau") + "?useSSL=false"); factory = Persistence.createEntityManagerFactory("tau", config); EntityManager em = factory.createEntityManager(); em.close(); initializeEventSourcer(); checkAndCreateGlobalRuleGroup(); }
From source file:com.yahoo.sql4d.indexeragent.meta.DBHandler.java
public DataSource getDataSource(int id) { EntityManager em = getEntityManager(); try {/*from ww w . j a v a 2 s. c o m*/ return em.find(DataSource.class, id); } finally { em.close(); } }
From source file:camelinaction.JpaTest.java
@SuppressWarnings("unchecked") private void assertEntityInDB() throws Exception { JpaEndpoint endpoint = (JpaEndpoint) context.getEndpoint("jpa:camelinaction.PurchaseOrder"); EntityManager em = endpoint.getEntityManagerFactory().createEntityManager(); List list = em.createQuery("select x from camelinaction.PurchaseOrder x").getResultList(); assertEquals(1, list.size());/*from w ww. j av a 2 s . co m*/ assertIsInstanceOf(PurchaseOrder.class, list.get(0)); em.close(); }