private Set<String> getKindScope(QuerySpecification qs) { Set<String> kindScope = new HashSet<>(4); findKindScopeFromQuery(qs.query, kindScope); if (kindScope.isEmpty()) { findFactoryScopeFromQuery(qs.query, kindScope); } if (kindScope.isEmpty()) { logger.fine(() -> String.format("Missing kind scope in query: %s", Utils.toJsonHtml(qs))); // Returning all scopes to allow do a UNION of all tables // Adding to existing kindScope mutable set to avoid Kryo cloning issues kindScope.addAll(this.schemaManager.getServiceDocuments()); } if (kindScope.isEmpty()) { throw new IllegalArgumentException("Cannot create SQL query without a kind scope"); } return kindScope; }
/** * Traverses the given query and find documentSelfLink constraints from which the factory query * scope is deducted. * * Takes all links into account no matter if they MUST_NOT_OCCUR - no need for such optimization * for now as our support for multiple kind scope will cope with that. */ private void findFactoryScopeFromQuery(Query query, Set<String> result) { if (query.booleanClauses != null) { for (Query innerQuery : query.booleanClauses) { findFactoryScopeFromQuery(innerQuery, result); } return; } if (query.term != null && ServiceDocument.FIELD_NAME_SELF_LINK.equals(query.term.propertyName) && !UriUtils.URI_WILDCARD_CHAR.equals(query.term.matchValue)) { String factoryLink = UriUtils.getParentPath(query.term.matchValue); if (factoryLink != null && !factoryLink.isEmpty() && !UriUtils.URI_PATH_CHAR.equals(factoryLink) && !factoryLink.contains(UriUtils.URI_WILDCARD_CHAR)) { String documentKind = this.schemaManager.getDocumentKindForFactoryLink(factoryLink); if (documentKind != null) { result.add(documentKind); } } } }