Search code examples
countodataolingo

Implement $count with Olingo V2


I am trying to implement the $count functionality in my OData V2 service, using Olingo.

I can't find any resources which explain how to do this - the Olingo documentation only explains how to do it for V4, and even so it's not clear. I have done lots of research but so far unsuccessfully.

Can someone point me to a place which explains this, or explain it for me ?

Many thanks!


Solution

  • You need to implement the "countEntitySet" or "countEntityLinks" method in your processor similar to the "readEntitySet" method.

    In order to write the response you can use the method: EntityProvider.writeText(...) method and pass the number as a String.

    Here is the example from the Olingo Test-Scenario: https://github.com/apache/olingo-odata2/blob/597465569fdd15976d0486711d4a38f93a7c6696/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java#L226