public Integer getTop() { if (topOption == null) { return null; } return topOption.getValue(); }
/** * This method applies top query option to the given entity collection. * * @param topOption Top option * @param entitySet Entity Collection * @throws ODataApplicationException */ public static void applyTopSystemQueryOption(final TopOption topOption, final EntityCollection entitySet) throws ODataApplicationException { if (topOption.getValue() >= 0) { reduceToSize(entitySet, topOption.getValue()); } else { throw new ODataApplicationException("Top value must be positive", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT); } }
private List<Entity> applyPagination(UriInfo uriInfo,List<Entity> entityList) { List<Entity> paginatedEntityList=entityList.stream() .skip( uriInfo.getSkipOption()!=null?uriInfo.getSkipOption().getValue():0) .limit( uriInfo.getTopOption()!=null?uriInfo.getTopOption().getValue():0) .collect(Collectors.toList()); return paginatedEntityList; }
gen.writeNumberField("top", topOption.getValue());
gen.writeNumberField("top", topOption.getValue());
final Integer topValue = uriInfo.getTopOption() != null ? uriInfo.getTopOption().getValue() : null;
eInfo.setLeveltop(expandItems.get(i).getTopOption().getValue());
/** * Process a expand query, which contains a $skip and/or a $top option.<p> * This is a tricky problem, as it can not be done easily with SQL. It could be that a database offers special * solutions. * There is an worth reading blog regards this topic: * <a href="http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/">How to select * the first/least/max row per group in SQL</a> * @return query result * @throws ODataApplicationException */ private JPAExpandQueryResult executeExpandTopSkipQuery() throws ODataApplicationException { // TODO make this replacable e.g. by UNION ALL or use of window functions final int handle = debugger.startRuntimeMeasurement(this, "executeExpandTopSkipQuery"); long skip = 0; long top = Long.MAX_VALUE; final TypedQuery<Tuple> tupleQuery = createTupleQuery(); // Simplest solution for the problem. Read all and throw away, what is not requested final List<Tuple> intermediateResult = tupleQuery.getResultList(); if (uriResource.getSkipOption() != null) skip = uriResource.getSkipOption().getValue(); if (uriResource.getTopOption() != null) top = uriResource.getTopOption().getValue(); Map<String, List<Tuple>> result = convertResult(intermediateResult, assoziation, skip, top); debugger.stopRuntimeMeasurement(handle); return new JPAExpandQueryResult(result, count(), jpaEntity); }
public List<String> generateCDSStatement(UriInfo uriInfo,ODataRequest request, List<ApplyTransformationsPerGroup> applyTrafoList) throws CDSRuntimeException{ checkForUnimplementedFeatures(uriInfo, request); List<String> sqlList = new ArrayList<String>(); if(uriInfo.getExpandOption()!=null&&uriInfo.getExpandOption().getExpandItems()!=null&&!uriInfo.getExpandOption().getExpandItems().isEmpty()){ checkForUnimplementedFeaturesWithinExpand(uriInfo.getExpandOption().getExpandItems(), request); } qH=new QueryHelperV4(uriInfo, request, applyTrafoList); if(uriInfo.getTopOption()!=null){ qH.setTopValue((long)uriInfo.getTopOption().getValue()); } if(uriInfo.getSkipOption()!=null){ qH.setSkipValue((long)uriInfo.getSkipOption().getValue()); } if(pageSize!=null){ modTopSkipforPagination(qH); } CDSQueryGenerator cdsq=new CDSQueryGenerator(qH); String sql= cdsq.generateSQl(); sqlList.add(sql); if(uriInfo.getCountOption() != null && uriInfo.getCountOption().getValue() == true) { qH.getEntityInfo().setCountStar(true); String countSql = new CDSQueryGenerator(qH).generateSQl(); sqlList.add(countSql); } return sqlList; }
expandResource.setTop(ei.getTopOption().getValue());