Java Code Examples for org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo#getTop()

The following examples show how to use org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo#getTop() . 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: JPAProcessorImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private List<Object> handlePaging(final List<Object> result, final GetEntitySetUriInfo uriParserResultView) {
  if (result == null) {
    return null;
  }
  JPAPageBuilder pageBuilder = new JPAPageBuilder();
  pageBuilder.pageSize(oDataJPAContext.getPageSize())
      .entities(result)
      .skipToken(uriParserResultView.getSkipToken());

  // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call
  if (uriParserResultView.getSkip() != null) {
    pageBuilder.skip(uriParserResultView.getSkip().intValue());
  }

  if (uriParserResultView.getTop() != null) {
    pageBuilder.top(uriParserResultView.getTop().intValue());
  }

  JPAPage page = pageBuilder.build();
  oDataJPAContext.setPaging(page);

  return page.getPagedEntities();
}
 
Example 2
Source File: JPAProcessorImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private List<Object> handlePaging(final Query query, final GetEntitySetUriInfo uriParserResultView) {

    JPAPageBuilder pageBuilder = new JPAPageBuilder();
    pageBuilder.pageSize(oDataJPAContext.getPageSize())
        .query(query)
        .skipToken(uriParserResultView.getSkipToken());

    // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call
    if (uriParserResultView.getSkip() != null) {
      pageBuilder.skip(uriParserResultView.getSkip().intValue());
    }

    if (uriParserResultView.getTop() != null) {
      pageBuilder.top(uriParserResultView.getTop().intValue());
    }

    JPAPage page = pageBuilder.build();
    oDataJPAContext.setPaging(page);

    return page.getPagedEntities();

  }
 
Example 3
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  final InlineCount inlineCountType = uriInfo.getInlineCount();
  final Integer count = applySystemQueryOptions(
      entitySet,
      data,
      uriInfo.getFilter(),
      inlineCountType,
      uriInfo.getOrderBy(),
      uriInfo.getSkipToken(),
      uriInfo.getSkip(),
      uriInfo.getTop());

  ODataContext context = getContext();
  String nextLink = null;

  // Limit the number of returned entities and provide a "next" link
  // if there are further entities.
  // Almost all system query options in the current request must be carried
  // over to the URI for the "next" link, with the exception of $skiptoken
  // and $skip.
  if (data.size() > SERVER_PAGING_SIZE) {
    if (uriInfo.getOrderBy() == null
        && uriInfo.getSkipToken() == null
        && uriInfo.getSkip() == null
        && uriInfo.getTop() == null) {
      sortInDefaultOrder(entitySet, data);
    }

    nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString();
    nextLink = percentEncodeNextLink(nextLink);
    nextLink += (nextLink.contains("?") ? "&" : "?")
        + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));

    while (data.size() > SERVER_PAGING_SIZE) {
      data.remove(SERVER_PAGING_SIZE);
    }
  }

  final EdmEntityType entityType = entitySet.getEntityType();
  List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
  for (final Object entryData : data) {
    values.add(getStructuralTypeValueMap(entryData, entityType));
  }

  final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .inlineCountType(inlineCountType)
      .inlineCount(count)
      .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
      .callbacks(getCallbacks(data, entityType))
      .nextLink(nextLink)
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
  final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}
 
Example 4
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  final InlineCount inlineCountType = uriInfo.getInlineCount();
  final Integer count = applySystemQueryOptions(
      entitySet,
      data,
      uriInfo.getFilter(),
      inlineCountType,
      uriInfo.getOrderBy(),
      uriInfo.getSkipToken(),
      uriInfo.getSkip(),
      uriInfo.getTop());

  ODataContext context = getContext();
  String nextLink = null;

  // Limit the number of returned entities and provide a "next" link
  // if there are further entities.
  // Almost all system query options in the current request must be carried
  // over to the URI for the "next" link, with the exception of $skiptoken
  // and $skip.
  if (data.size() > SERVER_PAGING_SIZE) {
    if (uriInfo.getOrderBy() == null
        && uriInfo.getSkipToken() == null
        && uriInfo.getSkip() == null
        && uriInfo.getTop() == null) {
      sortInDefaultOrder(entitySet, data);
    }

    nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString();
    nextLink = percentEncodeNextLink(nextLink);

    nextLink += (nextLink.contains("?") ? "&" : "?")
        + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));

    while (data.size() > SERVER_PAGING_SIZE) {
      data.remove(SERVER_PAGING_SIZE);
    }
  }

  final EdmEntityType entityType = entitySet.getEntityType();
  List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
  for (final Object entryData : data) {
    values.add(getStructuralTypeValueMap(entryData, entityType));
  }

  final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .inlineCountType(inlineCountType)
      .inlineCount(count)
      .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
      .callbacks(getCallbacks(data, entityType))
      .nextLink(nextLink)
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
  final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return ODataResponse.fromResponse(response).build();
}