Java Code Examples for javax.persistence.Query#getResultList()

The following examples show how to use javax.persistence.Query#getResultList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: getFidoPolicy.java    From fido2 with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
    public Collection<FidoPolicies> getAllActive() {
        try {
            Query q = em.createNamedQuery("FidoPolicies.findByStatus");
            q.setHint("javax.persistence.cache.storeMode", "REFRESH");
            q.setParameter("status", "Active");
            Collection<FidoPolicies> fidoPoliciesColl = q.getResultList();
            Collection<FidoPolicies> validPoliciesColl = fidoPoliciesColl;
//            if(!fidoPoliciesColl.isEmpty()){      //TODO verify signature
//                for (FidoPolicies fp : fidoPoliciesColl) {
//                    if(fp!=null){
//                        try {
//                            verifyDBRecordSignature(did, fp);
//                        } catch (SKFEException ex) {
//                            validPoliciesColl.remove(fp);
//                        }
//                    }
//                }
//            }
            return validPoliciesColl;
        } catch (NoResultException ex) {
            return null;
        }
    }
 
Example 2
Source File: CumulativeLiveSalesFacadeREST.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/recent/")
@Produces({"application/xml", "application/json"})
public List<TransitCumulativeSales> findRecent() {     
    Query baseRangeQuery = em.createQuery(BASE_RANGE_QUERY); 
    //Query baseRangeQuery = getEntityManager().createQuery(BASE_RANGE_QUERY);
    baseRangeQuery.setMaxResults(200);
    List<TransitCumulativeSales> result = new ArrayList<TransitCumulativeSales>();
    List<Object[]> resultList = baseRangeQuery.getResultList();
    System.out.print("hello world");
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        TransitCumulativeSales t = new TransitCumulativeSales();
        t.setStartDailySalesId((Integer)o[0]);
        t.setEndDailySalesId((Integer)o[1]);
        t.setCost((Double)o[2]);
        t.setSales((Double) o[3]);
        t.setDate((Date)o[4]);
        result.add(t);
    }
    return result;
}
 
Example 3
Source File: CommentServiceBean.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 分页查询评论内容
 * @param firstIndex
 * @param maxResult
 * @param userName 用户名称
 * @param isStaff 是否为员工
 * @return
 */
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<String> findCommentContentByPage(int firstIndex, int maxResult,String userName,boolean isStaff){
	List<String> topicContentList = new ArrayList<String>();//key:话题Id  value:话题内容
	
	String sql = "select o.content from Comment o where o.userName=?1 and o.isStaff=?2";
	Query query = em.createQuery(sql);	
	query.setParameter(1, userName);
	query.setParameter(2, isStaff);
	//索引开始,即从哪条记录开始
	query.setFirstResult(firstIndex);
	//获取多少条数据
	query.setMaxResults(maxResult);
	
	List<Object> objectList = query.getResultList();
	if(objectList != null && objectList.size() >0){
		for(int i = 0; i<objectList.size(); i++){
			String content = (String)objectList.get(i);
			topicContentList.add(content);
		}
	}
	
	return topicContentList;
}
 
Example 4
Source File: FlowDaoImpl.java    From WIFIProbe with Apache License 2.0 6 votes vote down vote up
/**
 * Customer flow statistic method
 *
 * @param startHour start hour
 * @param threshold {@link QueryThreshold} of query
 *                  sum value of threshold hours
 * @param statRange range <em>THRESHOLD</em> number of statistic(NOT hour number)
 * @param probeId   id of probe device
 * @return list of {@link FlowVo} with size equals to statRange
 */
@Override
public List<FlowVo> getFlowStat(int startHour, QueryThreshold threshold, int statRange, String probeId) {
    String isProbeSelected = probeId==null || probeId.isEmpty()? "": "AND wifiProb = :probeId ";
    String sqlQuery = "SELECT wifiProb,DATE_FORMAT(hour,:dateFormat),sum(inNoOutWifi), " +
            "sum(inNoOutStore),sum(outNoInWifi),sum(outNoInStore),sum(inAndOutWifi),sum(intAndOutStore), " +
            "sum(stayInWifi), sum(stayInStore), avg(jumpRate), avg(deepVisit), avg(inStoreRate)" +
            "FROM flow " +
            "WHERE UNIX_TIMESTAMP(hour) >= (:startHour*3600) " + isProbeSelected+
            " GROUP BY wifiProb,DATE_FORMAT(hour,:dateFormat) " +
            "LIMIT 0,:statRange";
    Query query = entityManager.createNativeQuery(sqlQuery);
    query.setParameter("dateFormat", ThresholdUtil.convertToString(threshold));
    query.setParameter("startHour",startHour);
    if (!isProbeSelected.isEmpty()) query.setParameter("probeId",probeId);
    query.setParameter("statRange",statRange>=1? statRange: 10);
    List resultList = query.getResultList();
    List<FlowVo> flowVos = new LinkedList<>();
    for (Object object: resultList) {
        flowVos.add((FlowVo) ObjectMapper.arrayToObject(FlowVo.class,object));
    }
    return flowVos;
}
 
Example 5
Source File: TriggerServiceBean.java    From development with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings(value = "unchecked")
private List<VOTriggerProcess> getActionsForQuery(String namedQuery) {
    List<VOTriggerProcess> list = new ArrayList<>();
    PlatformUser currentUser = dm.getCurrentUser();
    Query query = dm.createNamedQuery(namedQuery);
    try {
        query.setParameter("userKey", Long.valueOf(currentUser.getKey()));
    } catch (IllegalArgumentException ie) {
        logger.logDebug("Parameter is not needed");
    }
    query.setParameter("organizationKey",
        Long.valueOf(currentUser.getOrganization().getKey()));
    LocalizerFacade localizerFacade = new LocalizerFacade(localizer,
        currentUser.getLocale());
    for (TriggerProcess triggerProcess : ((Collection<TriggerProcess>) query
        .getResultList())) {
        list.add(TriggerProcessAssembler.toVOTriggerProcess(triggerProcess,
            localizerFacade));
    }

    return list;
}
 
Example 6
Source File: HelpTypeServiceBean.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 根据Id组查询子分类
 * @param idGroup 帮助分类Id组
 * @return
 */
@Transactional(readOnly=true, propagation=Propagation.NOT_SUPPORTED)
public List<HelpType> findChildHelpTypeByIdGroup(String idGroup){
	Query query = em.createQuery("select o from HelpType o where o.parentIdGroup like ?1")
	.setParameter(1,idGroup+'%' );
	List<HelpType> list = query.getResultList();
	return list;
}
 
Example 7
Source File: PreProcessResultDAOImpl.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Collection<PreProcessResult> findPreProcessResultFromAudit(Audit audit) {
    Query query = entityManager.createQuery("SELECT ppr FROM "
            + getEntityClass().getName() + " ppr "
            + " WHERE "
            + " ppr.audit = :audit");
    query.setParameter("audit", audit);
    return query.getResultList();
}
 
Example 8
Source File: ContentDAOImpl.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param ssp
 * @return the list of ids of related contents for a given ssp
 */
private List<Long> findRelatedContentFromSsp(SSP ssp) {
    Query query = entityManager.createQuery(
            "select rc.id FROM "
            + RelatedContentImpl.class.getName() + RELATED_CONTENT_KEY
            + JOIN_PARENT_CONTENT_SET
            + " WHERE s.id =:idSSP");
    query.setParameter("idSSP", ssp.getId());
    return query.getResultList();
}
 
Example 9
Source File: UserServiceBean.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 查询所有禁止的用户名称
 * @return
 */
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<DisableUserName> findAllDisableUserName(){
	Query query =  em.createQuery("select o from DisableUserName o");
	List<DisableUserName> disableUserNameList = query.getResultList();
	return disableUserNameList;
}
 
Example 10
Source File: LiveSalesListFacadeREST.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/producttype/{id}")
public List<LiveSalesList> findRecentProductType(@PathParam("id") Integer productTypeId) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.equal(liveSalesList.get(LiveSalesList_.productTypeId), productTypeId));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
Example 11
Source File: CommonDAOSpringImpl.java    From EasyEE with MIT License 5 votes vote down vote up
@Override
public List findByCache(String jpql, Map<String, Object> values) {

	String cacheRegion = null;
	if (null != DEFAULT_QUERY_CACHE_REGION || (!"".equals(DEFAULT_QUERY_CACHE_REGION))) {
		cacheRegion = DEFAULT_QUERY_CACHE_REGION;
	}
	Query q = createQuery(entityManager, jpql, true, cacheRegion, values);
	List list = q.getResultList();
	return list;
}
 
Example 12
Source File: QueryExecutor.java    From tutorials with MIT License 5 votes vote down vote up
public static List<String[]> executeNativeQueryWithCastCheck(String statement, EntityManager em) {
    Query query = em.createNativeQuery(statement);
    List results = query.getResultList();

    if (results.isEmpty()) {
        return new ArrayList<>();
    }

    if (results.get(0) instanceof String) {
        return ((List<String>) results).stream().map(s -> new String[] { s }).collect(Collectors.toList());
    } else {
        return (List<String[]>) results;
    }
}
 
Example 13
Source File: CommonDAOSpringImpl.java    From EasyEE with MIT License 5 votes vote down vote up
@Override
public List find(String jpql, Map<String, Object> values) {

	Query q = createQuery(entityManager, jpql, false, null, values);
	List list = q.getResultList();
	return list;

}
 
Example 14
Source File: FooServiceSortingIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public final void whenSortingByOneAttributeSetOrder_thenSortedPrintResult() {
    final String jql = "Select f from Foo as f order by f.id desc";
    final Query sortQuery = entityManager.createQuery(jql);
    final List<Foo> fooList = sortQuery.getResultList();
    for (final Foo foo : fooList) {
        System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
    }
}
 
Example 15
Source File: AbstractAnyDAO.java    From syncope with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<A> findByResource(final ExternalResource resource) {
    Query query = entityManager().createQuery("SELECT e FROM " + anyUtils().anyClass().getSimpleName() + " e "
            + "WHERE :resource MEMBER OF e.resources");
    query.setParameter("resource", resource);

    return query.getResultList();
}
 
Example 16
Source File: DeveloperAuthorshipInfoDAO.java    From Truck-Factor with MIT License 4 votes vote down vote up
public List<String> projectsAlreadyCalculated(){
	String hql = "SELECT dai.repositoryname FROM developerauthorshipinfo dai GROUP BY dai.repositoryname;";
	Query q = em.createNativeQuery(hql);
	return q.getResultList();
}
 
Example 17
Source File: TemplateServiceBean.java    From bbs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 查询所有已导入的模板
 * @return
 */
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
public List<Templates> findAllTemplates(){
	Query query = em.createQuery("select o from Templates o");
	return query.getResultList();
}
 
Example 18
Source File: JpaUserDao.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public List<User> getAll() {
    Query query = entityManager.createQuery("SELECT e FROM User e");
    return query.getResultList();
}
 
Example 19
Source File: Movies.java    From tomee with Apache License 2.0 4 votes vote down vote up
@PermitAll
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Movie> getMovies() throws Exception {
    Query query = entityManager.createQuery("SELECT m from Movie as m");
    return query.getResultList();
}
 
Example 20
Source File: QuestionRowLabelDAOImpl.java    From JDeSurvey with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Transactional
public Set<QuestionRowLabel> findByQuestionId(Long id)	throws DataAccessException {
	Query query = createNamedQuery("QuestionRowLabel.findByQuestionId", -1,-1, id);
	return new LinkedHashSet<QuestionRowLabel>(query.getResultList());
}