-DDYNAMODBTEST_REGION=REGION-ID
-DDYNAMODBTEST_ACCESS=ACCESS-KEY
-DDYNAMODBTEST_SECRET=SECRET
+
+--add-opens=java.base/java.lang=ALL-UNNAMED
```
+
+The `--add-opens` parameter is necessary also with the local temporary DynamoDB server, otherwise the mockito will fail at runtime with (`java.base does not "opens java.lang" to unnamed module`).
+
}
addFilterbyItemAndTimeFilter(queryBuilder, expectedTableSchema, itemName, filter);
addStateFilter(queryBuilder, expectedTableSchema, item, dtoClass, filter, unitProvider);
+ addLimit(queryBuilder, filter);
addProjection(dtoClass, expectedTableSchema, queryBuilder);
return queryBuilder.build();
}
}
}
+ /**
+ * Add optimization to limit amount of data queried from DynamoDB
+ *
+ * DynamoDB allows to limit the amount of items read by the query ("Limit" parameter) - additional items are
+ * paginated in the raw DynamoDB responses. We can use this to optimize the read capacity.
+ *
+ * DynamoDB FilterExpression is applied after the query finishes but before results are returned. The query
+ * still consumes the same read capacity. It is also to note here that the query might return less than "Limit"
+ * items, and the results are paginated. Since the final openHAB pagination is done in the persistence service, the
+ * pagination of the DynamoDB remains as a hidden implementation detail.
+ *
+ * @param queryBuilder builder for DynamoDB query
+ * @param filter openHAB filter
+ */
+ private static void addLimit(QueryEnhancedRequest.Builder queryBuilder, final FilterCriteria filter) {
+ boolean pageSizeSpecified = filter.getPageSize() != Integer.MAX_VALUE;
+ if (pageSizeSpecified) {
+ queryBuilder.limit(filter.getPageSize());
+ }
+ }
+
private static void addStateFilter(QueryEnhancedRequest.Builder queryBuilder,
ExpectedTableSchema expectedTableSchema, Item item, Class<? extends DynamoDBItem<?>> dtoClass,
FilterCriteria filter, UnitProvider unitProvider) {