From 08fca98875b098fb4dfdee11144d7ed4ad78a9e8 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Wed, 27 Sep 2023 16:23:35 +0200 Subject: [PATCH] Changed the way to paginate results due to missing skip in TRAVERSE command --- .../queries/json/JsonQuery.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java index 3e7bebe..cea2525 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/queries/json/JsonQuery.java @@ -117,13 +117,22 @@ public class JsonQuery { int limit = requestInfo.getLimit(); int offset = requestInfo.getOffset(); + + int position = -1; + int count = 0; + StringBuffer stringBuffer = createQuery(); - stringBuffer.append(" SKIP :offset"); - stringBuffer.append(" LIMIT :limit"); + /* + * TRAVERSE does not support SKIP + * so we need to use post filtering strategy + */ + + // stringBuffer.append(" SKIP :offset"); + // stringBuffer.append(" LIMIT :limit"); Map map = new HashMap<>(); - map.put("offset", offset); - map.put("limit", limit); + // map.put("offset", offset); + // map.put("limit", limit); String query = stringBuffer.toString(); @@ -135,6 +144,9 @@ public class JsonQuery { while(resultSet.hasNext()) { OResult oResult = resultSet.next(); + if(++position < offset) { + continue; + } OElement element = ElementManagementUtility.getElementFromOptional(oResult.getElement()); try { @@ -151,6 +163,9 @@ public class JsonQuery { erManagement.setAsEntryPoint(); jsonNodeResult = erManagement.serializeAsJsonNode(); arrayNode.add(jsonNodeResult); + if(limit > 0 && ++count >= limit) { + break; + } continue; } @@ -159,6 +174,9 @@ public class JsonQuery { erManagement.setAsEntryPoint(); jsonNodeResult = erManagement.serializeAsJsonNode(); arrayNode.add(jsonNodeResult); + if(limit > 0 && ++count >= limit) { + break; + } continue; }