List of usage examples for javax.persistence EntityManager createQuery
public Query createQuery(CriteriaDelete deleteQuery);
Query
for executing a criteria delete query. From source file:com.taobao.ad.easyschedule.base.JPABaseDAO.java
public int getQueryCount(String queryString, final Map<String, Object> map) { final List<String> keyList = getKeyList(map); final String queryStringCallBack = getQueryString(queryString, keyList, null); return (Integer) this.getJpaTemplate().execute(new JpaCallback() { @Override/*from w w w.ja v a2 s. c om*/ public Integer doInJpa(EntityManager em) throws PersistenceException { Query query = em.createQuery(queryStringCallBack); for (int i = 0; i < keyList.size(); i++) { query.setParameter((i + 1), map.get(keyList.get(i))); } return ((Long) query.getSingleResult()).intValue(); } }); }
From source file:com.taobao.ad.easyschedule.base.JPABaseDAO.java
public List executeQueryIsNotEmpty(String queryString, final Map<String, Object> map, String orderBy) { final List<String> keyList = getKeyList(map); final String queryStringCallBack = getQueryString(queryString, keyList, orderBy); return (List) this.getJpaTemplate().execute(new JpaCallback() { @Override/* ww w .j a va 2 s . co m*/ public List doInJpa(EntityManager em) throws PersistenceException { Query query = em.createQuery(queryStringCallBack); for (int i = 0; i < keyList.size(); i++) { query.setParameter((i + 1), map.get(keyList.get(i))); } return query.getResultList(); } }); }
From source file:com.taobao.ad.easyschedule.base.JPABaseDAO.java
public List queryForListIsNotEmpty(String queryString, final Map<String, Object> map, final PageInfo pageInfo, String orderBy) {/*ww w . j ava2 s .c o m*/ final List<String> keyList = getKeyList(map); final String queryStringCallBack = getQueryString(queryString, keyList, orderBy); return (List) this.getJpaTemplate().execute(new JpaCallback() { @Override public List doInJpa(EntityManager em) throws PersistenceException { Query query = em.createQuery(queryStringCallBack); for (int i = 0; i < keyList.size(); i++) { query.setParameter((i + 1), map.get(keyList.get(i))); } // query.setFirstResult(((pageInfo.getToPage() == 0 ? 1 : // pageInfo.getToPage()) - 1) * pageInfo.getPerPageSize()); query.setFirstResult(pageInfo.getStartRow()); query.setMaxResults(pageInfo.getPerPageSize()); return query.getResultList(); } }); }
From source file:com.taobao.ad.easyschedule.base.JPABaseDAO.java
public Object executeSingleIsNotEmpty(String queryString, final Map<String, Object> map, String orderBy) { final List<String> keyList = getKeyList(map); final String queryStringCallBack = getQueryString(queryString, keyList, orderBy); return this.getJpaTemplate().execute(new JpaCallback() { @Override//from w w w. j a v a 2s .c o m public Object doInJpa(EntityManager em) throws PersistenceException { Query query = em.createQuery(queryStringCallBack); for (int i = 0; i < keyList.size(); i++) { query.setParameter((i + 1), map.get(keyList.get(i))); } query.setMaxResults(1); try { return query.getSingleResult(); } catch (Exception e) { return null; } } }); }
From source file:net.anthonychaves.bookmarks.service.UserService.java
public User findUser(String emailAddress) { EntityManager em = emf.createEntityManager(); User user = null;//from w ww. j ava 2s. co m try { Query query = em.createQuery("select u from User u where u.emailAddress = ?1").setParameter(1, emailAddress); em.getTransaction().begin(); user = (User) query.getSingleResult(); em.getTransaction().rollback(); } catch (NoResultException e) { user = null; } return user; }
From source file:de.iai.ilcd.model.dao.UserGroupDao.java
public Long getGroupsCount(Organization org) { if (org == null) { return null; }//from w w w . j a v a 2 s. com EntityManager em = PersistenceUtil.getEntityManager(); try { Query q = em.createQuery( "SELECT COUNT(DISTINCT g) FROM UserGroup g WHERE g.organization.id = :orgId ORDER BY g.groupName"); q.setParameter("orgId", org.getId()); return (Long) q.getSingleResult(); } catch (Exception e) { return null; } }
From source file:ejb.bean.UsuarioDAOJPAImplBean.java
/**Mtodo para a busca de todos os usurios existentes no banco de dados. * @author Richel Sensineli/* www .ja va 2 s .co m*/ * @param nome String - Nome do usurio * @return Collection list */ @Override public Collection buscaTodosUsuarios() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("UsuarioPU"); EntityManager em = emf.createEntityManager(); Query q = em.createQuery("select u from UsuarioImpl u"); Collection result = null; result = q.getResultList(); em.clear(); em.close(); emf.close(); return result; }
From source file:de.iai.ilcd.model.dao.UserGroupDao.java
@SuppressWarnings("unchecked") public List<UserGroup> getGroups(Organization org, Integer first, Integer pageSize) { if (org == null) { return null; }/*w w w. j av a2s. com*/ EntityManager em = PersistenceUtil.getEntityManager(); try { Query q = em.createQuery( "SELECT DISTINCT g FROM UserGroup g WHERE g.organization.id = :orgId ORDER BY g.groupName"); q.setParameter("orgId", org.getId()); if (first != null) { q.setFirstResult(first.intValue()); } if (pageSize != null) { q.setMaxResults(pageSize.intValue()); } return (List<UserGroup>) q.getResultList(); } catch (Exception e) { return null; } }
From source file:com.taobao.ad.easyschedule.dao.reportjobrt.impl.JPAReportJobRtDAOImpl.java
@Override public Double getAverageRt(final Date startTime, final Date endTime) { Double avg = (Double) super.getJpaTemplate().execute(new JpaCallback() { @Override//from w w w .j a v a2s . com public Object doInJpa(EntityManager em) throws PersistenceException { return em.createQuery( "select avg(t.rt) from es_report_job_rt t where t.createTime<=?1 and t.createTime >?2") .setParameter(1, endTime).setParameter(2, startTime).getSingleResult(); } }); return avg == null ? 0 : avg; }
From source file:com.taobao.ad.easyschedule.dao.reportjobrt.impl.JPAReportJobRtDAOImpl.java
@Override public Integer getCount(final int status, final Date startTime, final Date endTime) { Long count = (Long) super.getJpaTemplate().execute(new JpaCallback() { @Override//from w w w. ja va2 s .co m public Object doInJpa(EntityManager em) throws PersistenceException { return em.createQuery( "select count(*) from es_report_job_rt t where t.createTime<=?1 and t.createTime >?2 and t.status=?3") .setParameter(1, endTime).setParameter(2, startTime).setParameter(3, status) .getSingleResult(); } }); return count == null ? 0 : count.intValue(); }