List of usage examples for javax.persistence EntityManager createQuery
public Query createQuery(CriteriaDelete deleteQuery);
Query
for executing a criteria delete query. From source file:uk.ac.ebi.intact.editor.services.admin.HqlQueryService.java
@Transactional(value = "jamiTransactionManager", readOnly = true, propagation = Propagation.REQUIRED) public List<? extends IntactPrimaryObject> runQuery(int maxResults, String hqlQuery) { maxResults = Math.min(maxResults, MAX_RESULTS); hqlQuery = cleanQuery(hqlQuery);// ww w . ja v a 2 s. c o m EntityManager em = getIntactDao().getEntityManager(); Query query = em.createQuery(hqlQuery); query.setMaxResults(maxResults); return query.getResultList(); }
From source file:com.taobao.ad.easyschedule.dao.reportjob.impl.JPAReportJobDAOImpl.java
@SuppressWarnings("unchecked") @Override//www .java2 s. c o m public List<ReportJobDO> findReportJob(final ReportJobDO reportJob) { return (List<ReportJobDO>) super.getJpaTemplate().execute(new JpaCallback() { @Override public Object doInJpa(EntityManager em) throws PersistenceException { return em.createQuery( "select t from es_report_job t where t.reportTime<=?1 and t.reportTime >=?2 order by t.reportTime ") .setParameter(1, reportJob.getEndTime()).setParameter(2, reportJob.getStartTime()) .getResultList(); } }); }
From source file:com.taobao.ad.easyschedule.dao.datatrackinglog.impl.JPADataTrackingLogDAOImpl.java
@SuppressWarnings("unchecked") public List<DatatrackingLogDO> getDataTrackingByGroupAndName(final DatatrackingLogDO datatrackingLog) throws DataAccessException { return (List<DatatrackingLogDO>) this.getJpaTemplate().execute(new JpaCallback() { @Override/*from w w w . ja va2s . c o m*/ public Object doInJpa(EntityManager em) throws PersistenceException { Query query = em.createQuery( "select t from es_datatracking_log t where t.jobName=?1 and t.jobGroup=?2 and t.createTime>=?3 and t.createTime<=?4 order by t.createTime desc") .setParameter(1, datatrackingLog.getJobName()) .setParameter(2, datatrackingLog.getJobGroup()) .setParameter(3, datatrackingLog.getQueryStartTime()) .setParameter(4, datatrackingLog.getQueryEndTime()); List<DatatrackingLogDO> dataList = query.getResultList(); if (dataList != null && !dataList.isEmpty()) { Collections.sort(dataList, new Comparator<DatatrackingLogDO>() { @Override public int compare(DatatrackingLogDO o1, DatatrackingLogDO o2) { return o1.getCreateTime().compareTo(o2.getCreateTime()); } }); } return dataList; } }); }
From source file:com.taobao.ad.easyschedule.dao.logs.impl.JPALogsDAOImpl.java
public void deleteAllLogs() { this.getJpaTemplate().execute(new JpaCallback() { @Override/* ww w . ja va 2 s . co m*/ public Object doInJpa(EntityManager em) throws PersistenceException { return em.createQuery("delete from es_logs t where 1=1").executeUpdate(); } }); }
From source file:se.trillian.goodies.spring.jpa.GenericJpaDaoSupport.java
public void deleteById(final IdType id) { if (deleteQuery == null) { deleteQuery = "delete from " + getEntityName() + " where " + getIdPropertyName() + "=?"; }/* w w w. ja v a 2s .com*/ getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager entityManager) throws PersistenceException { return entityManager.createQuery(deleteQuery).setParameter(1, id).executeUpdate(); } }); }
From source file:de.egore911.opengate.services.FactionService.java
@GET @Path("/list") @Produces("application/json") @Documentation("Returns a list of factions in the format [{id, name},{id, name}]") public Response list() { JSONArray jsonArray = new JSONArray(); EntityManager em = EntityManagerFilter.getEntityManager(); List<Faction> factions = em.createQuery("select faction from Faction faction order by name") .getResultList();/*www . j a va2 s .c o m*/ try { for (Faction faction : factions) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", faction.getName()); jsonObject.put("id", faction.getKey().getId()); jsonArray.put(jsonObject); } return Response.ok(jsonArray.toString()).build(); } catch (JSONException e) { LOG.log(Level.SEVERE, e.getMessage(), e); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:streaming.service.DataBaseService.java
public void supprimerTout() { EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); em.getTransaction().begin();/*from w w w . jav a 2 s .com*/ em.createQuery("DELETE FROM Lien l").executeUpdate(); em.createQuery("DELETE FROM Episode e").executeUpdate(); em.createQuery("DELETE FROM Saison s").executeUpdate(); em.createQuery("DELETE FROM Serie se").executeUpdate(); em.createQuery("DELETE FROM Film f").executeUpdate(); em.createQuery("DELETE FROM Realisateur r").executeUpdate(); em.createQuery("DELETE FROM Pays p").executeUpdate(); em.createQuery("DELETE FROM Genre g").executeUpdate(); em.getTransaction().commit(); }
From source file:streaming.service.DBService.java
public void deleteAll() { EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager(); em.getTransaction().begin();/*from ww w. j a va 2 s . co m*/ em.createQuery("DELETE FROM Lien l").executeUpdate(); em.createQuery("DELETE FROM Episode e").executeUpdate(); em.createQuery("DELETE FROM Saison saison").executeUpdate(); em.createQuery("DELETE FROM Serie serie").executeUpdate(); em.createQuery("DELETE FROM Film f").executeUpdate(); em.createQuery("DELETE FROM Genre g").executeUpdate(); em.createQuery("DELETE FROM Realisateur r").executeUpdate(); em.createQuery("DELETE FROM Pays p").executeUpdate(); em.getTransaction().commit(); }
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 www. ja v a2 s. c o m*/ assertIsInstanceOf(PurchaseOrder.class, list.get(0)); em.close(); }
From source file:com.taobao.ad.easyschedule.dao.logs.impl.JPALogsDAOImpl.java
@Override public LogsDO getLastStartLog(final String jobGroup, final String jobName) { return (LogsDO) this.getJpaTemplate().execute(new JpaCallback() { @Override//from www . j a v a2 s . co m public Object doInJpa(EntityManager em) throws PersistenceException { return em.createQuery( "select t from es_logs t where t.opsubname=?1 and t.opsubtype=?2 order by t.optime desc") .setParameter(1, jobGroup + "|" + jobName).setParameter(2, LogsDO.SUBTYPE_JOB_START) .setMaxResults(1).getSingleResult(); } }); }