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 requete5() { System.out.println("Requete 5"); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); System.out/*www . jav a2 s .co m*/ .println(em.createQuery("SELECT f FROM Film f WHERE f.genre.nom = 'Fantastique'").getResultList()); }
From source file:streaming.test.StreamingTest.java
public void requete4() { System.out.println("Requete 4"); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); System.out.println(/*from w ww. j a v a 2 s .com*/ em.createQuery("SELECT f FROM Film f JOIN f.genre g WHERE g.nom='Fantastique' ORDER BY f.titre ASC") .getResultList()); }
From source file:streaming.test.StreamingTest.java
public void requete3() { System.out.println("Requete 3"); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); Assert.assertEquals(1,/*from w ww . ja v a2 s . c o m*/ em.createQuery("SELECT f FROM Film f JOIN f.pays p WHERE p.nom='France'").getResultList().size()); }
From source file:net.kamhon.ieagle.dao.JpaDao.java
@Override public int bulkUpdate(String query, final Object... objectArray) { final String query2 = convertJpaPositionParams(query); return getJpaTemplate().execute(new JpaCallback<Integer>() { @Override/*from w w w . ja v a 2s . c o m*/ public Integer doInJpa(EntityManager em) throws PersistenceException { Query q = em.createQuery(query2); for (int i = 0; i < objectArray.length; i++) { q.setParameter(i + 1, objectArray[i]); } return q.executeUpdate(); } }); }
From source file:net.kamhon.ieagle.dao.JpaDao.java
@Override public T findUnique(String query, final Object... objectArray) { final String query2 = convertJpaPositionParams(query); return getJpaTemplate().execute(new JpaCallback<T>() { @SuppressWarnings("unchecked") @Override//from w w w .j a va2 s .com public T doInJpa(EntityManager em) throws PersistenceException { Query q = em.createQuery(query2); for (int i = 0; i < objectArray.length; i++) { q.setParameter(i + 1, objectArray[i]); } return (T) q.getSingleResult(); } }); }
From source file:net.kamhon.ieagle.dao.JpaDao.java
@SuppressWarnings("unchecked") @Override/*from w w w . ja va 2s . c om*/ public List<T> findBlock(String query, final int offset, final int recordCount, final Object... objectArray) { final String query2 = convertJpaPositionParams(query); return getJpaTemplate().executeFind(new JpaCallback<List<T>>() { @Override public List<T> doInJpa(EntityManager em) throws PersistenceException { Query q = em.createQuery(query2); for (int i = 0; i < objectArray.length; i++) { q.setParameter(i + 1, objectArray[i]); } q.setFirstResult(offset); q.setMaxResults(recordCount); return q.getResultList(); } }); }
From source file:com.creditcloud.common.entities.dao.AbstractReadDAO.java
/** * list all entity/*ww w .ja v a 2 s.c o m*/ * * @return */ public List<T> findAll() { EntityManager em = getEntityManager(); CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return em.createQuery(cq).getResultList(); }
From source file:org.SRV.testServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from ww w . j av a2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { entityManagerFactory = Persistence.createEntityManagerFactory("org.SRV_war_1.0.0-BUILD-SNAPSHOTPU"); EntityManager entityManager = entityManagerFactory.createEntityManager(); // List<Essence> essence = entityManager.createQuery("select * from essence").getResultList(); //Query query = entityManager.createQuery("FROM Essence u WHERE u.id = :id").setParameter("id", 1); //List<Essence> resultList = query.getResultList(); List<Essence> resultList = entityManager.createQuery("SELECT e FROM Essence e").getResultList(); entityManager.close(); entityManagerFactory.close(); String json = new Gson().toJson(resultList); response.getWriter().write(json); }
From source file:com.creditcloud.common.entities.dao.AbstractReadDAO.java
/** * find entity in the range// w w w . ja v a2 s . c o m * * @param range * @return */ public List<T> findRange(int[] range) { EntityManager em = getEntityManager(); CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); Query q = em.createQuery(cq); q.setMaxResults(range[1] - range[0]); q.setFirstResult(range[0]); return q.getResultList(); }
From source file:streaming.swing.JPanelOptionFilm.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed Film f = new Film(); EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); int i = jComboBox1.getSelectedIndex(); int j = jComboBox2.getSelectedIndex(); String ge = lg.get(i).getNom(); String pa = lp.get(j).getNom(); String s = jTextField1.getText(); List<Film> liste = em.createQuery( "SELECT f FROM Film f JOIN f.genreFilm g JOIN f.paysFilm p WHERE g.nom='ge' OR p.nom='pa' OR f.titre='s'") .getResultList();/*from w w w . j a v a 2s. co m*/ supprimerPanneau(); // jtFilm.setModel(new Tabl eModelListFilmRechercher(liste)); // add(jtFilm, BorderLayout.CENTER); }