Added pagination to prepared query

This commit is contained in:
luca.frosini 2023-09-27 15:12:36 +02:00
parent 5741f52072
commit 3f1a4f5795
1 changed files with 30 additions and 4 deletions

View File

@ -559,7 +559,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
*/ */
} }
/* /*
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction, public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException { boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
@ -569,6 +568,13 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
ArrayNode arrayNode = objectMapper.createArrayNode(); ArrayNode arrayNode = objectMapper.createArrayNode();
ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get();
int limit = requestInfo.getLimit();
int offset = requestInfo.getOffset();
int position = -1;
int count = 0;
Iterable<?> references = null; Iterable<?> references = null;
if(referenceUUID != null) { if(referenceUUID != null) {
@ -589,7 +595,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
if(polymorphic && getOClass().isSubClassOf(referenceType)) { if(polymorphic && getOClass().isSubClassOf(referenceType)) {
// OK // OK
} else { } else {
String error = String.format("Referenced instace with UUID %s is not a %s", referenceUUID, referenceType); String error = String.format("Referenced instance with UUID %s is not a %s", referenceUUID, referenceType);
throw new InvalidQueryException(error); throw new InvalidQueryException(error);
} }
} }
@ -599,7 +605,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
references = vertexes; references = vertexes;
} else { } else {
String error = String.format("Referenced instace with UUID %s is not a %s", referenceUUID, referenceType); String error = String.format("Referenced instance with UUID %s is not a %s", referenceUUID, referenceType);
throw new InvalidQueryException(error); throw new InvalidQueryException(error);
} }
@ -609,6 +615,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
Set<ORID> analysed = new HashSet<>(); Set<ORID> analysed = new HashSet<>();
outerloop:
for(Object r : references) { for(Object r : references) {
OVertex v = (OVertex) r; OVertex v = (OVertex) r;
@ -697,6 +704,15 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
continue; continue;
} }
/*
* This is the only position where we can put
* pagination check because we need matching results
*/
if(++position < offset) {
continue;
}
/* /*
JsonNode jsonNode; JsonNode jsonNode;
if(includeRelationInResult) { if(includeRelationInResult) {
@ -708,9 +724,19 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
} }
*/ */
entityManagement.setAsEntryPoint(); entityManagement.setAsEntryPoint();
JsonNode node = entityManagement.serializeAsJsonNode();
JsonNode node = entityManagement.serializeAsJsonNode();
arrayNode.add(node); arrayNode.add(node);
/*
* This is the only position where we can put
* pagination check because we need matching results
*/
if(limit > 0 && ++count >= limit) {
break outerloop;
}
} catch(ResourceRegistryException e) { } catch(ResourceRegistryException e) {
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
vertex.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); vertex.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);