@Override
public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
- final Class<T> targetClass) {
+ final int queryResultLimit, final Class<T> targetClass) {
final CpsPathQuery cpsPathQuery = getCpsPathQuery(cpsPath);
if (!cpsPathQuery.hasAttributeAxis()) {
throw new IllegalArgumentException(
final String attributeName = cpsPathQuery.getAttributeAxisAttributeName();
final List<DataNode> dataNodes = queryDataNodes(dataspaceName, anchorName, cpsPath,
- FetchDescendantsOption.OMIT_DESCENDANTS);
+ FetchDescendantsOption.OMIT_DESCENDANTS, queryResultLimit);
return dataNodes.stream()
.map(dataNode -> {
final Object attributeValue = dataNode.getLeaves().get(attributeName);
*/
<T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class<T> targetClass);
+ /**
+ * Get data leaf for the given dataspace and anchor by cps path.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param cpsPath cps path
+ * @param queryResultLimit the maximum number of data nodes to return; if less than 1, returns all matching nodes
+ * @param targetClass class of the expected data type
+ * @return a collection of data objects of expected type
+ */
+ <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, int queryResultLimit,
+ Class<T> targetClass);
+
/**
* Get data nodes for the given dataspace across all anchors by cps path.
*
@Override
public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
final Class<T> targetClass) {
+ return queryDataLeaf(dataspaceName, anchorName, cpsPath, NO_LIMIT, targetClass);
+ }
+
+ @Override
+ public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
+ final int queryResultLimit, final Class<T> targetClass) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- return cpsDataPersistenceService.queryDataLeaf(dataspaceName, anchorName, cpsPath, targetClass);
+ return cpsDataPersistenceService.queryDataLeaf(dataspaceName, anchorName, cpsPath, queryResultLimit,
+ targetClass);
}
@Override
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @param cpsPath cps path
+ * @param queryResultLimit limits the number of returned entities (if less than 1 returns all)
* @param targetClass class of the expected data type
* @return a collection of data objects of expected type
*/
- <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class<T> targetClass);
+ <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, int queryResultLimit,
+ Class<T> targetClass);
/**
* Get a datanode by dataspace name and cps path across all anchors.
and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName'
1 * mockCpsValidator.validateNameCharacters(dataspaceName)
where: 'all fetch descendants options are supported'
- fetchDescendantsOption << [FetchDescendantsOption.OMIT_DESCENDANTS, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS,
- FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)]
+ fetchDescendantsOption << [FetchDescendantsOption.OMIT_DESCENDANTS, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS,
+ FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)]
}
def 'Query total anchors for dataspace and cps path.'() {
def 'Query data leaf.'() {
when: 'a query for a specific leaf is executed'
objectUnderTest.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', Object.class)
- then: 'solution is not implemented yet'
- 1 * mockCpsDataPersistenceService.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', Object.class)
+ then: 'the persistence service is called once with the correct parameters'
+ 1 * mockCpsDataPersistenceService.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', 0, Object.class)
}
}
assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR_1, BOOKSTORE_ANCHOR_2].toSet()
}
- def 'Query with a limit of #limit.' () {
- when:
+ def 'Query data nodes with a limit of #limit.' () {
+ when: 'a query for data nodes is executed with a result limit'
def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories', OMIT_DESCENDANTS, limit)
then: 'the expected number of nodes is returned'
assert countDataNodesInTree(result) == expectedNumberOfResults
0 || 5
-1 || 5
}
+
+ def 'Query data leaf with a limit of #limit.' () {
+ when: 'a query for data leaf is executed with a result limit'
+ def result = objectUnderTest.queryDataLeaf(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories/@name', limit, String)
+ then: 'the expected number of leaf values is returned'
+ assert result.size() == expectedNumberOfResults
+ where: 'the following parameters are used'
+ limit || expectedNumberOfResults
+ 1 || 1
+ 2 || 2
+ 0 || 5
+ -1 || 5
+ }
}