@Override public void visit(CountOption info) { this.countOption = info.getValue(); }
/** * This method applies count query option to the given entity collection. * * @param countOption Count option * @param entitySet Entity collection */ public static void applyCountSystemQueryOption(final CountOption countOption, final EntityCollection entitySet) { if (countOption.getValue()) { entitySet.setCount(entitySet.getEntities().size()); } }
/** * To get the $count value from the query. * @param uriInfo * @param sqlList * @param request * @return null if this is not a count call. Otherwise will return the count value. * @throws ODataApplicationException */ private Integer getcount(UriInfo uriInfo,List<String> sqlList,ODataRequest request) throws ODataApplicationException{ Integer count =null; try { //To execute the $count query. if(uriInfo.getCountOption() != null && uriInfo.getCountOption().getValue() == true) { String countSql = sqlList.get(1); if(countSql != null) { ResultSet rs = cdsprocessor.execute(countSql,conn,request,timings); if(rs.next()) { count=rs.getInt(1); } } } } catch (SQLException e) { throw new ODataApplicationException("Could not execute the count query", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), HeaderUtil.getlocale(request),e); } return count; }
throws IOException { if (countOption != null) { gen.writeBooleanField("isCount", countOption.getValue());
throws IOException { if (countOption != null) { gen.writeBooleanField("isCount", countOption.getValue());
ContextURLBuilder.create(options.getContextURL()).toASCIIString()); if (options != null && options.getCount() != null && options.getCount().getValue() && entitySet.getCount() != null) { writeCount(entitySet, writer);
if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount("", entityCollection.getCount(), json);
if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount("", entityCollection.getCount(), json);
writeContextURL(contextURL, json); if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount(delta.getCount(), json);
writeContextURL(contextURL, json); if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount(delta.getCount(), json);
writeContextURL(contextURL, json); if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount(delta.getCount(), json);
if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount("", entitySet.getCount(), json);
writeContextURL(contextURL, json); if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount(delta.getCount(), json);
if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount("", entitySet.getCount(), json);
protected void writeExpandedNavigationProperty(final ServiceMetadata metadata, final EdmNavigationProperty property, final Link navigationLink, final ExpandOption innerExpand, final Integer toDepth, final SelectOption innerSelect, final CountOption coutOption, final boolean writeNavigationCount, final boolean writeOnlyRef,final String xml10InvalidCharReplacement, final Set<String> ancestors, String name, final XMLStreamWriter writer) throws XMLStreamException, SerializerException { if (property.isCollection()) { if (navigationLink != null && navigationLink.getInlineEntitySet() != null) { writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM); if (writeNavigationCount) { writeCount(navigationLink.getInlineEntitySet(), writer); } else { if (coutOption != null && coutOption.getValue()) { writeCount(navigationLink.getInlineEntitySet(), writer); } writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, writeOnlyRef, name, ancestors); } writer.writeEndElement(); } } else { if (navigationLink != null && navigationLink.getInlineEntity() != null) { writeEntity(metadata, property.getType(), navigationLink.getInlineEntity(), null, innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, false, writeOnlyRef, name, ancestors); } } }
protected void writeExpandedNavigationProperty(final ServiceMetadata metadata, final EdmNavigationProperty property, final Link navigationLink, final ExpandOption innerExpand, final Integer toDepth, final SelectOption innerSelect, final CountOption coutOption, final boolean writeNavigationCount, final boolean writeOnlyRef,final String xml10InvalidCharReplacement, final Set<String> ancestors, String name, final XMLStreamWriter writer) throws XMLStreamException, SerializerException { if (property.isCollection()) { if (navigationLink != null && navigationLink.getInlineEntitySet() != null) { writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM); if (writeNavigationCount) { writeCount(navigationLink.getInlineEntitySet(), writer); } else { if (coutOption != null && coutOption.getValue()) { writeCount(navigationLink.getInlineEntitySet(), writer); } writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, writeOnlyRef, name, ancestors); } writer.writeEndElement(); } } else { if (navigationLink != null && navigationLink.getInlineEntity() != null) { writeEntity(metadata, property.getType(), navigationLink.getInlineEntity(), null, innerExpand, toDepth, innerSelect, xml10InvalidCharReplacement, writer, false, writeOnlyRef, name, ancestors); } } }
if (options != null && options.getCount() != null && options.getCount().getValue()) { writeInlineCount("", entitySet.getCount(), json);
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; }