javax.jcr.query.QueryManager Java Examples
The following examples show how to use
javax.jcr.query.QueryManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlogServiceImpl.java From publick-sling-blog with Apache License 2.0 | 7 votes |
/** * Get blog posts with pagination * * @param offset The starting point of blog posts to return. * @param limit The number of blog posts to return. * @return The blog posts. */ public NodeIterator getPosts(Long offset, Long limit) { NodeIterator nodes = null; if (session != null) { try { QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(BLOG_QUERY, Query.JCR_SQL2); if (offset != null) { query.setOffset(offset); } if (limit != null) { query.setLimit(limit); } QueryResult result = query.execute(); nodes = result.getNodes(); } catch (RepositoryException e) { LOGGER.error("Could not search repository", e); } } return nodes; }
Example #2
Source File: CatalogDataResourceProviderManagerImpl.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
/** * Find all existing virtual catalog data roots using all query defined in service configuration. * * @param resolver Resource resolver * @return all virtual catalog roots */ @SuppressWarnings("unchecked") private List<Resource> findDataRoots(ResourceResolver resolver) { List<Resource> allResources = new ArrayList<>(); for (String queryString : this.findAllQueries) { if (!StringUtils.contains(queryString, "|")) { throw new IllegalArgumentException("Query string does not contain query syntax seperated by '|': " + queryString); } String queryLanguage = StringUtils.substringBefore(queryString, "|"); String query = StringUtils.substringAfter(queryString, "|"); // data roots are JCR nodes, so we prefer JCR query because the resource resolver appears to be unreliable // when we are in the middle of registering/unregistering resource providers try { Session session = resolver.adaptTo(Session.class); Workspace workspace = session.getWorkspace(); QueryManager qm = workspace.getQueryManager(); Query jcrQuery = qm.createQuery(query, queryLanguage); QueryResult result = jcrQuery.execute(); NodeIterator nodes = result.getNodes(); while (nodes.hasNext()) { Node node = nodes.nextNode(); Resource resource = resolver.getResource(node.getPath()); if (resource != null) { allResources.add(resource); } } } catch (RepositoryException x) { log.error("Error finding data roots", x); } } dataRoots = allResources; return allResources; }
Example #3
Source File: JCRQueryBuilder.java From jackalope with Apache License 2.0 | 5 votes |
public QueryManager build() { List<Query> queries = new ArrayList<>(); for (QueryBuilder queryBuilder : queryBuilders) queries.add(queryBuilder.build()); QueryManager queryManager = new QueryManagerImpl(queries.toArray(new Query[queries.size()])); ((WorkspaceImpl)session.getWorkspace()).setQueryManager(queryManager); return queryManager; }
Example #4
Source File: WorkspaceWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public QueryManager getQueryManager() throws RepositoryException { return new QueryManagerWrapper(this.sessionWrapper, delegate.getQueryManager()); }
Example #5
Source File: QueryManagerWrapper.java From sling-whiteboard with Apache License 2.0 | 4 votes |
public QueryManagerWrapper(SessionWrapper<?> sessionWrapper, QueryManager delegate) { super(sessionWrapper, delegate); }
Example #6
Source File: WorkspaceImpl.java From jackalope with Apache License 2.0 | 4 votes |
@Override public QueryManager getQueryManager() throws RepositoryException { return queryManager; }
Example #7
Source File: WorkspaceImpl.java From jackalope with Apache License 2.0 | 4 votes |
public void setQueryManager(QueryManager queryManager) { this.queryManager = queryManager; }
Example #8
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 4 votes |
@Override public void populateStatistics(RepositorySession repositorySession, MetadataRepository repository, String repositoryId, RepositoryStatistics repositoryStatistics) throws MetadataRepositoryException { if (!(repository instanceof JcrMetadataRepository)) { throw new MetadataRepositoryException( "The statistics population is only possible for JcrMetdataRepository implementations"); } Session session = getSession(repositorySession); // TODO: these may be best as running totals, maintained by observations on the properties in JCR try { QueryManager queryManager = session.getWorkspace().getQueryManager(); // TODO: Check, if this is still the case - Switched to Jackrabbit OAK with archiva 3.0 // Former statement: JCR-SQL2 query will not complete on a large repo in Jackrabbit 2.2.0 - see JCR-2835 // Using the JCR-SQL2 variants gives // "org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1024" // String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])"; // Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact] " + whereClause, // Query.JCR_SQL2 ); String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])"; Query query = queryManager.createQuery("SELECT type,size FROM [" + ARTIFACT_NODE_TYPE + "] " + whereClause, Query.JCR_SQL2); QueryResult queryResult = query.execute(); Map<String, Integer> totalByType = new HashMap<>(); long totalSize = 0, totalArtifacts = 0; for (Row row : JcrUtils.getRows(queryResult)) { Node n = row.getNode(); log.debug("Result node {}", n); totalSize += row.getValue("size").getLong(); String type; if (n.hasNode(MavenArtifactFacet.FACET_ID)) { Node facetNode = n.getNode(MavenArtifactFacet.FACET_ID); type = facetNode.getProperty("type").getString(); } else { type = "Other"; } Integer prev = totalByType.get(type); totalByType.put(type, prev != null ? prev + 1 : 1); totalArtifacts++; } repositoryStatistics.setTotalArtifactCount(totalArtifacts); repositoryStatistics.setTotalArtifactFileSize(totalSize); for (Map.Entry<String, Integer> entry : totalByType.entrySet()) { log.info("Setting count for type: {} = {}", entry.getKey(), entry.getValue()); repositoryStatistics.setTotalCountForType(entry.getKey(), entry.getValue()); } // The query ordering is a trick to ensure that the size is correct, otherwise due to lazy init it will be -1 // query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 ); query = queryManager.createQuery("SELECT * FROM [archiva:project] " + whereClause + " ORDER BY [jcr:score]", Query.JCR_SQL2); repositoryStatistics.setTotalProjectCount(query.execute().getRows().getSize()); // query = queryManager.createQuery( // "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 ); query = queryManager.createQuery( "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL ORDER BY [jcr:score]", Query.JCR_SQL2); repositoryStatistics.setTotalGroupCount(query.execute().getRows().getSize()); } catch (RepositoryException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }