Skip to content

Enhanced Filtering and Pagination Capabilities for Java Operations

Introduction

Introduce support for filtering collections using the $filter, $top, and $skip query options in Java based projection operatation. This provides support for the developer to increase the efficiency and accuracy of the data retrieval by seamlessly integrating filtering, pagination, and record skipping directly at the data source level, this enhancement optimizes the data access process.

This document serves as a guide to give insights into the seamless integration of Java Projections and to offer practical guidelines on harnessing these capabilities to their fullest potential.

Overview

By introducing support for $filter, $top, and $skip within Java projections, clients gain the ability to precisely request tailored data from collections hosted on the server. These versatile query options provide a means for efficient and adaptable data retrieval, resulting in notable enhancements to both application performance and responsiveness.

Parameters in the Request

When initiating a server request using Java projections, the parameters map will now encompass the following key elements:

FilterExpression: This key returns the filter criteria ($filter) sent from the client. This can be used to filter data according to specific criteria.

TopQueryFunction: This key serves to restrict the number of records fetched from the collection, assuring that the server retrieves solely the specified top N records.

SkipQueryFunction: By using this key, users can bypass a designated count of initial records within the collection. This functionality facilitates the smooth pagination of substantial result sets.

These incorporated elements in the parameters map enhance the flexibility and precision of data retrieval, making the interaction between clients and the server more efficient and tailored to specific requirements.

Utilizing $filter, $top, and $skip

Developers can capitalize on the newly introduced query options within Java projections to fine-tune data retrieval in alignment with their unique needs. Please note that all of these parameters are optional and the code should be written keeping it in mind.

Presented below are illustrative examples showcasing how each option can be effectively harnessed:

$filter

In order to get the value passed for the $filter Expression, a developer can access the value associated with the “FilterExpression” key in the params map as follows.

{
    Expression filterExpression = (Expression) params.get("FilterExpression");
}

Upon gaining access to the filter Expression, the developer's next step involves the creation of a new class that implements the Olingo ExpressionVisitor interface. The ExpressionVisitor interface is a fundamental component of the Olingo library (used in the implementation of the OData Protocol), specifically designed for the interpretation and processing of OData query expressions. This class empowers developers to navigate through and comprehensively analyze OData query expressions, facilitating their efficient interpretation.

org.apache.olingo.server.api.uri.queryoption.expression package contains classes and interfaces which are needed to implement ExpressionVisitor interface.

Refer the sample Visitor Implemented
Refer https://olingo.apache.org/doc/odata2/tutorials/Olingo_Tutorial_AdvancedRead_FilterVisitor.html for an example.

$top

To retrieve the value passed for the $top query option, developers can access the value associated with the "TopQueryOption" key in the params map using the following approach:

{
    int topLimit = params.containsKey("TopQueryOption") ? (int) params.get("TopQueryOption") : 0;}
$skip

To retrieve the value passed for the $skip query option, developers can access the value associated with the "SkipQueryOption" key in the params map using the following approach:

{
    int skipLimit = params.containsKey("SkipQueryOption") ? (int) params.get("SkipQueryOption") : 0;}