@Test public void buildQueryWithTopSkipInline() { EdmMapping mapping = (EdmMapping) mockMapping(); try { GetEntitySetUriInfo uriInfo = (GetEntitySetUriInfo) mockURIInfoWithTopSkipInline(mapping); builder.getCount(uriInfo); assertNotNull(uriInfo.getCustomQueryOptions().get("count")); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public void getCount(GetEntitySetUriInfo uriInfo) throws ODataJPARuntimeException { JPAQueryInfo queryInfo = new JPAQueryInfo(); Query query = null; UriInfoImpl info = (UriInfoImpl)uriInfo; boolean count = info.isCount(); info.setCount(true); try { ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo); if (listener != null) { query = listener.getQuery((GetEntitySetCountUriInfo)uriInfo, em); if(query != null){ JPQLContextType contextType = determineJPQLContextType(info, UriInfoType.GetEntitySetCount); JPQLContext jpqlContext = buildJPQLContext(contextType, info); JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext).build(); jpqlContext.setJPQLStatement(jpqlStatement.toString()); query = getParameterizedQueryForListeners(jpqlContext, query); } } if (query == null) { query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntitySetCount); } else { queryInfo.setTombstoneQuery(true); } } catch (Exception e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e); } finally { JPQLContext.removeJPQLContext(); ODataExpressionParser.removePositionalParametersThreadLocal(); } queryInfo.setQuery(query); Query countQuery = queryInfo.getQuery(); List<Object> countList = countQuery.getResultList(); info.setCount(count); if(countList!= null && !countList.isEmpty()){ String countNumber = countList.get(0).toString(); Map<String, String> customQueryOptions = new HashMap<String, String>(); customQueryOptions.put("count", countNumber); info.setCustomQueryOptions(customQueryOptions); } }
JPAQueryBuilder { public void getCount(GetEntitySetUriInfo uriInfo) throws ODataJPARuntimeException { JPAQueryInfo queryInfo = new JPAQueryInfo(); Query query = null; UriInfoImpl info = (UriInfoImpl)uriInfo; boolean count = info.isCount(); info.setCount(true); try { ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo); if (listener != null) { query = listener.getQuery((GetEntitySetCountUriInfo)uriInfo, em); if(query != null){ JPQLContextType contextType = determineJPQLContextType(info, UriInfoType.GetEntitySetCount); JPQLContext jpqlContext = buildJPQLContext(contextType, info); JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext).build(); jpqlContext.setJPQLStatement(jpqlStatement.toString()); query = getParameterizedQueryForListeners(jpqlContext, query); } } if (query == null) { query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntitySetCount); } else { queryInfo.setTombstoneQuery(true); } } catch (Exception e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e); } finally { JPQLContext.removeJPQLContext(); ODataExpressionParser.removePositionalParametersThreadLocal(); } queryInfo.setQuery(query); Query countQuery = queryInfo.getQuery(); List<Object> countList = countQuery.getResultList(); info.setCount(count); if(countList!= null && !countList.isEmpty()){ String countNumber = countList.get(0).toString(); Map<String, String> customQueryOptions = new HashMap<String, String>(); customQueryOptions.put("count", countNumber); info.setCustomQueryOptions(customQueryOptions); } } }
JPAQueryBuilder { public void getCount(GetEntitySetUriInfo uriInfo) throws ODataJPARuntimeException { JPAQueryInfo queryInfo = new JPAQueryInfo(); Query query = null; UriInfoImpl info = (UriInfoImpl)uriInfo; boolean count = info.isCount(); info.setCount(true); try { ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo); if (listener != null) { query = listener.getQuery((GetEntitySetCountUriInfo)uriInfo, em); if(query != null){ JPQLContextType contextType = determineJPQLContextType(info, UriInfoType.GetEntitySetCount); JPQLContext jpqlContext = buildJPQLContext(contextType, info); JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext).build(); jpqlContext.setJPQLStatement(jpqlStatement.toString()); query = getParameterizedQueryForListeners(jpqlContext, query); } } if (query == null) { query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntitySetCount); } else { queryInfo.setTombstoneQuery(true); } } catch (Exception e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e); } finally { JPQLContext.removeJPQLContext(); ODataExpressionParser.removePositionalParametersThreadLocal(); } queryInfo.setQuery(query); Query countQuery = queryInfo.getQuery(); List<Object> countList = countQuery.getResultList(); info.setCount(count); if(countList!= null && !countList.isEmpty()){ String countNumber = countList.get(0).toString(); Map<String, String> customQueryOptions = new HashMap<String, String>(); customQueryOptions.put("count", countNumber); info.setCustomQueryOptions(customQueryOptions); } } JPAQueryBuilder(ODataJPAContext odataJPAContext); }
JPAQueryBuilder { public void getCount(GetEntitySetUriInfo uriInfo) throws ODataJPARuntimeException { JPAQueryInfo queryInfo = new JPAQueryInfo(); Query query = null; UriInfoImpl info = (UriInfoImpl)uriInfo; boolean count = info.isCount(); info.setCount(true); try { ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo); if (listener != null) { query = listener.getQuery((GetEntitySetCountUriInfo)uriInfo, em); if(query != null){ JPQLContextType contextType = determineJPQLContextType(info, UriInfoType.GetEntitySetCount); JPQLContext jpqlContext = buildJPQLContext(contextType, info); JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext).build(); jpqlContext.setJPQLStatement(jpqlStatement.toString()); query = getParameterizedQueryForListeners(jpqlContext, query); } } if (query == null) { query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntitySetCount); } else { queryInfo.setTombstoneQuery(true); } } catch (Exception e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e); } finally { JPQLContext.removeJPQLContext(); ODataExpressionParser.removePositionalParametersThreadLocal(); } queryInfo.setQuery(query); Query countQuery = queryInfo.getQuery(); List<Object> countList = countQuery.getResultList(); info.setCount(count); if(countList!= null && !countList.isEmpty()){ String countNumber = countList.get(0).toString(); Map<String, String> customQueryOptions = new HashMap<String, String>(); customQueryOptions.put("count", countNumber); info.setCustomQueryOptions(customQueryOptions); } } JPAQueryBuilder(ODataJPAContext odataJPAContext); JPAQueryInfo build(GetEntitySetUriInfo uriInfo); void getCount(GetEntitySetUriInfo uriInfo); Query build(GetEntityUriInfo uriInfo); Query build(GetEntitySetCountUriInfo uriInfo); Query build(GetEntityCountUriInfo uriInfo); Query build(DeleteUriInfo uriInfo); Query build(PutMergePatchUriInfo uriInfo); ODataJPAQueryExtensionEntityListener getODataJPAQueryEntityListener(UriInfo uriInfo); ODataJPATombstoneEntityListener getODataJPATombstoneEntityListener(UriInfo uriParserResultView); JPQLContext buildJPQLContext(JPQLContextType contextType, UriInfo uriParserResultView); JPQLContextType determineJPQLContextType(UriInfo uriParserResultView, UriInfoType type); }
JPAQueryBuilder { public void getCount(GetEntitySetUriInfo uriInfo) throws ODataJPARuntimeException { JPAQueryInfo queryInfo = new JPAQueryInfo(); Query query = null; UriInfoImpl info = (UriInfoImpl)uriInfo; boolean count = info.isCount(); info.setCount(true); try { ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo); if (listener != null) { query = listener.getQuery((GetEntitySetCountUriInfo)uriInfo, em); if(query != null){ JPQLContextType contextType = determineJPQLContextType(info, UriInfoType.GetEntitySetCount); JPQLContext jpqlContext = buildJPQLContext(contextType, info); JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext).build(); jpqlContext.setJPQLStatement(jpqlStatement.toString()); query = getParameterizedQueryForListeners(jpqlContext, query); } } if (query == null) { query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntitySetCount); } else { queryInfo.setTombstoneQuery(true); } } catch (Exception e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e); } finally { JPQLContext.removeJPQLContext(); ODataExpressionParser.removePositionalParametersThreadLocal(); } queryInfo.setQuery(query); Query countQuery = queryInfo.getQuery(); List<Object> countList = countQuery.getResultList(); info.setCount(count); if(countList!= null && !countList.isEmpty()){ String countNumber = countList.get(0).toString(); Map<String, String> customQueryOptions = new HashMap<String, String>(); customQueryOptions.put("count", countNumber); info.setCustomQueryOptions(customQueryOptions); } } JPAQueryBuilder(ODataJPAContext odataJPAContext); JPAQueryInfo build(GetEntitySetUriInfo uriInfo); void getCount(GetEntitySetUriInfo uriInfo); Query build(GetEntityUriInfo uriInfo); Query build(GetEntitySetCountUriInfo uriInfo); Query build(GetEntityCountUriInfo uriInfo); Query build(DeleteUriInfo uriInfo); Query build(PutMergePatchUriInfo uriInfo); ODataJPAQueryExtensionEntityListener getODataJPAQueryEntityListener(UriInfo uriInfo); ODataJPATombstoneEntityListener getODataJPATombstoneEntityListener(UriInfo uriParserResultView); JPQLContext buildJPQLContext(JPQLContextType contextType, UriInfo uriParserResultView); JPQLContextType determineJPQLContextType(UriInfo uriParserResultView, UriInfoType type);  }