BUG-544850: Allow to set limit (max number of rows returned) on ODSQuery
Signed-off-by: Fabian Dreier <fabian.dreier@karakun.com>
diff --git a/src/main/java/org/eclipse/mdm/api/odsadapter/query/ODSQuery.java b/src/main/java/org/eclipse/mdm/api/odsadapter/query/ODSQuery.java
index dc10886..38748ca 100644
--- a/src/main/java/org/eclipse/mdm/api/odsadapter/query/ODSQuery.java
+++ b/src/main/java/org/eclipse/mdm/api/odsadapter/query/ODSQuery.java
@@ -92,6 +92,8 @@
private final ApplElemAccess applElemAccess;
+ private int limit;
+
// ======================================================================
// Constructors
// ======================================================================
@@ -103,6 +105,7 @@
*/
ODSQuery(ApplElemAccess applElemAccess) {
this.applElemAccess = applElemAccess;
+ limit = 0;
}
// ======================================================================
@@ -121,6 +124,15 @@
* {@inheritDoc}
*/
@Override
+ public Query limit(int limit) {
+ this.limit = limit;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Query select(Attribute attribute, Aggregation aggregation) {
EntityType entityType = attribute.getEntityType();
entityTypesByID.put(Long.toString(ODSConverter.fromODSLong(((ODSEntityType) entityType).getODSID())),
@@ -219,7 +231,7 @@
List<Result> results = new ArrayList<>();
long start = System.currentTimeMillis();
- for (Result result : new ResultFactory(entityTypesByID, applElemAccess.getInstancesExt(qse, 0)[0])) {
+ for (Result result : new ResultFactory(entityTypesByID, applElemAccess.getInstancesExt(qse, limit)[0])) {
results.add(result);
}
long stop = System.currentTimeMillis();