List of usage examples for javax.persistence EntityManager createQuery
public Query createQuery(CriteriaDelete deleteQuery);
Query
for executing a criteria delete query. From source file:streaming.test.StreamingTest.java
public void requete10() { System.out.println("Requete 10"); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); System.out.println(em.createQuery( "SELECT f1 FROM Film f1 JOIN f1.real r WHERE r.prenom ='Joel' INTERSECT SELECT f2 FROM Film f2 JOIN f2.real r1 WHERE r1.prenom='Ethan'") .getResultList());// w w w. jav a 2s. c o m }
From source file:streaming.test.StreamingTest.java
public void requete11() { System.out.println("Requete 11"); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); System.out.println(em.createQuery( "SELECT f FROM Film f WHERE f.anneeProd=(SELECT MIN(f1.anneeProd) FROM Film f1 JOIN f1.real r1 WHERE r1.prenom ='Peter')") .getResultList());/*from ww w . j av a 2s . c o m*/ }
From source file:edu.vt.middleware.gator.JpaConfigManager.java
/** {@inheritDoc}. */ @SuppressWarnings("unchecked") @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<ProjectConfig> findProjectsByClientName(final String name) { final EntityManager em = getEntityManager(); final String queryString = "SELECT p FROM ProjectConfig p, IN(p.clientsInternal) c " + "WHERE c.name = :name"; final Query query = em.createQuery(queryString); query.setParameter("name", name); logger.trace("Executing query " + queryString); logger.trace("Query params: name=" + name); final List<ProjectConfig> projects = query.getResultList(); for (ProjectConfig project : projects) { loadFullProject(project);// ww w . j ava 2 s. c o m } return projects; }
From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.MetaCategoryErrorITCase.java
/** * Test add./*from ww w.j a va2 s. co m*/ * * @throws Exception the exception */ @Test public void testMetaCategory_Error_single_document() throws Exception { long size = countArticles(); EntityManager em = emf.createEntityManager(); String[] ids = new String[] { "1000", "1001" }; // insert all items for (String id : ids) { // item should not be in the db Query query = em.createQuery( new StringBuilder().append("SELECT x FROM news x WHERE x.fs_id = ").append(id).toString()); assertEquals(0, query.getResultList().size()); // load content String content = getContent("src/test/resources/inbox/add/pressreleasesdetails_" + id + ".xml", "hibernate"); // send content to jms broker template.sendBody("jms:topic:BUS_OUT", content); // wait Thread.sleep(TimeOuts.LONG); // item should be inserted to db query = em.createQuery( new StringBuilder().append("SELECT x FROM news x WHERE x.fs_id = ").append(id).toString()); assertEquals(1, query.getResultList().size()); } assertEquals("not all items are present", size + ids.length, countArticles()); Query query = em.createQuery( new StringBuilder().append("SELECT x FROM category x WHERE x.fs_id = 2001").toString()); // Query query = em.createQuery(new StringBuilder().append("SELECT x FROM category x WHERE x.fs_id = 3786").toString()); NewsCategory cat = (NewsCategory) query.getSingleResult(); assertEquals(2, cat.getMetaCategories().size()); em.close(); }
From source file:streaming.test.StreamingTest.java
public void requete2() { System.out.println("Requete 2"); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); Assert.assertEquals(6, em.createQuery("SELECT g FROM Genre g").getResultList().size()); Assert.assertEquals(6L, em.createQuery("SELECT count(g) FROM Genre g").getSingleResult()); }
From source file:com.jada.admin.contactus.ContactUsMaintAction.java
public void initSearchInfo(ContactUsMaintActionForm form, String siteId) throws Exception { EntityManager em = JpaConnection.getInstance().getCurrentEntityManager(); Query query = em .createQuery("from country in class Country where country.siteId = :siteId order by countryName"); query.setParameter("siteId", siteId); Iterator<?> iterator = query.getResultList().iterator(); Vector<LabelValueBean> vector = new Vector<LabelValueBean>(); while (iterator.hasNext()) { Country country = (Country) iterator.next(); LabelValueBean bean = new LabelValueBean(country.getCountryName(), country.getCountryCode()); vector.add(bean);//from w w w . j a va2 s. c o m } LabelValueBean countries[] = new LabelValueBean[vector.size()]; vector.copyInto(countries); form.setCountries(countries); String sql = ""; sql = "from State state " + "left join fetch state.country country " + "where country.siteId = :siteId " + "order by country.countryId, state.stateName"; query = em.createQuery(sql); query.setParameter("siteId", siteId); iterator = query.getResultList().iterator(); vector = new Vector<LabelValueBean>(); vector.add(new LabelValueBean("", "")); while (iterator.hasNext()) { State state = (State) iterator.next(); LabelValueBean bean = new LabelValueBean(state.getStateName(), state.getStateCode()); vector.add(bean); } LabelValueBean states[] = new LabelValueBean[vector.size()]; vector.copyInto(states); form.setStates(states); }
From source file:streaming.test.StreamingTest.java
public void requete13() { System.out.println("Requete 13"); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); Collection<Object[]> col = em .createQuery("SELECT COUNT(f.id), r FROM Film f JOIN f.real r GROUP BY r ORDER BY COUNT(f.id)") .getResultList();// w w w . ja v a 2s .c o m for (Object o[] : col) { System.out.println(o[0] + " " + ((Realisateur) o[1]).getNom() + " " + ((Realisateur) o[1]).getPrenom()); } }
From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.CommandITCase.java
/** * Count articles.//w ww . j a va 2 s. c o m * * @return the long * @throws Exception the exception */ private long countArticles() throws Exception { EntityManager em = emf.createEntityManager(); Query query = em.createQuery("SELECT COUNT(p.headline) FROM news p"); Long countResult = (Long) query.getSingleResult(); em.close(); return countResult; }
From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.CommandITCase.java
/** * Count categories./*from w w w.jav a2s . co m*/ * * @return the long * @throws Exception the exception */ private long countCategories() throws Exception { EntityManager em = emf.createEntityManager(); Query query = em.createQuery("SELECT COUNT(p.fs_id) FROM category p"); Long countResult = (Long) query.getSingleResult(); em.close(); return countResult; }
From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.CommandITCase.java
/** * Count meta categories.//from w w w . ja va2s .c o m * * @return the long * @throws Exception the exception */ private long countMetaCategories() throws Exception { EntityManager em = emf.createEntityManager(); Query query = em.createQuery("SELECT COUNT(p.fs_id) FROM metaCategory p"); Long countResult = (Long) query.getSingleResult(); em.close(); return countResult; }