List of usage examples for javax.persistence Query getResultList
List getResultList();
From source file:es.ucm.fdi.dalgs.learningGoal.repository.LearningGoalRepository.java
public LearningGoal existByCode(String code) { Query query = em.createQuery("Select l from LearningGoal l where l.info.code=?1"); query.setParameter(1, code);//from w w w .ja va2s . co m if (query.getResultList().isEmpty()) return null; else return (LearningGoal) query.getSingleResult(); }
From source file:com.intuit.tank.dao.UpdateScriptGroupsTest.java
@Test(groups = { "manual" }) public void upgrade() { EntityManager em = dao.getEM();// w w w.java2 s. co m Query query = em.createNativeQuery( "select id, workload_id from script_group where test_plan_id is null order by position"); @SuppressWarnings("unchecked") List<Object[]> results = query.getResultList(); for (Object[] set : results) { for (Object o : set) { Integer id = (Integer) set[0]; Integer workloadId = (Integer) set[1]; System.out.print(o); System.out.print(", "); if (workloadId != null) { updateScriptGroup(id, workloadId); } else { deleteScriptGroup(id); } } System.out.print('\n'); } for (Workload w : workloadMap.values()) { workloadDao.saveOrUpdate(w); } }
From source file:eu.planets_project.tb.impl.persistency.ServiceRecordPersistencyImpl.java
@SuppressWarnings("unchecked") public ServiceRecordImpl findServiceRecordByHashcode(String hashcode) { log.info("Looking for service records matching hashcode: " + hashcode); Query query = manager.createQuery("from ServiceRecordImpl where serviceHash=:hashcode"); query.setParameter("hashcode", hashcode); List<ServiceRecordImpl> results = (List<ServiceRecordImpl>) query.getResultList(); if (results == null || results.size() == 0) return null; log.info("Found " + results.size() + " services with the given hashcode."); return results.get(0); }
From source file:gov.nih.nci.integration.dao.DefaultIHubMessageDao.java
/** * getAllByReferenceMessageId//from w ww . j a v a2 s.c om * * @param refMsgId - messageId * @return List<IHubMessage> - list of IHubMessae entities */ @SuppressWarnings("unchecked") public List<IHubMessage> getAllByReferenceMessageId(Long refMsgId) { final Query msgsQuery = this.getEm().createQuery("from " + getDomainClass().getSimpleName() + " iHubMsg where iHubMsg.referenceMessageId = :referenceMessageId "); msgsQuery.setParameter("referenceMessageId", refMsgId); return msgsQuery.getResultList(); }
From source file:com.grummages.app.rest.entity.service.UsersRESTFacade.java
private List<Users> find(boolean all, int maxResults, int firstResult) { try {//from w ww. j a v a 2 s .c o m Query query = entityManager.createQuery("SELECT object(o) FROM Users AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }
From source file:vlove.dao.impl.GenericDaoImpl.java
/** * @see vlove.dao.GenericDao#nativeQuery(String, Map, Integer) */// w ww . j av a 2s .c om @Override public <T> List<T> nativeQuery(String query, Map<String, Object> parameters, Integer maxResults) { Query q = em.createNativeQuery(query); if (maxResults != null) { q.setMaxResults(maxResults); } applyParameters(q, parameters); return q.getResultList(); }
From source file:fi.vm.sade.organisaatio.dao.impl.OrganisaatioNimiDAOImpl.java
@Override public OrganisaatioNimi findCurrentNimi(Organisaatio organisaatio) { if (organisaatio == null) { throw new IllegalArgumentException("organisaatio cannot be null"); }//www . jav a2s .c o m LOG.info("findCurrentNimi({})", new Object[] { organisaatio.getId() }); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String s = "SELECT n FROM OrganisaatioNimi n " + "WHERE " + "organisaatio_id = " + organisaatio.getId() + " AND " + "alkupvm = (SELECT MAX (o.alkuPvm) " + "FROM OrganisaatioNimi o " + "WHERE " + "organisaatio_id = " + organisaatio.getId() + " AND " + "alkupvm <= '" + df.format(new Date()) + "')"; Query q = getEntityManager().createQuery(s); List<OrganisaatioNimi> organisaatioNimet = (List<OrganisaatioNimi>) q.getResultList(); LOG.info("findCurrentNimi() result size: " + organisaatioNimet.size()); if (organisaatioNimet.size() == 1) { return organisaatioNimet.get(0); } LOG.info("findNimi({}) --> OrganisaatioNimi not found", new Object[] { organisaatio.getId() }); return null; }
From source file:org.syncope.core.persistence.dao.impl.ResourceDAOImpl.java
@Override public List<ExternalResource> findAllByPriority() { Query query = entityManager.createQuery("SELECT e " + "FROM " + ExternalResource.class.getSimpleName() + " e " + "ORDER BY e.propagationPriority"); return query.getResultList(); }
From source file:be.fedict.eid.pkira.blm.model.contracts.ContractQuery.java
@SuppressWarnings("unchecked") public List<AbstractContract> findContractsByFilter(String userRrn, ContractsFilter contractsFilter, Ordering ordering, Paging paging) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT contract FROM "); appendFromAndWhere(contractsFilter, queryString); appendOrderBy(ordering, queryString); Query query = getEntityManager().createQuery(queryString.toString()); addQueryParameters(userRrn, contractsFilter, query); setPaging(paging, query);// w ww .j av a 2 s. c om return query.getResultList(); }
From source file:com.grummages.app.rest.entity.service.AddressRESTFacade.java
private List<Address> find(boolean all, int maxResults, int firstResult) { try {//from w w w .j a v a 2s .c om Query query = entityManager.createQuery("SELECT object(o) FROM Address AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }