Changed the way to paginate results due to missing skip in TRAVERSE

command
This commit is contained in:
luca.frosini 2023-09-27 16:23:35 +02:00
parent e5106cd6c0
commit 08fca98875
1 changed files with 22 additions and 4 deletions

View File

@ -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<String, Object> 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;
}