当前位置: 首页>>代码示例>>Java>>正文


Java QueryManager类代码示例

本文整理汇总了Java中javax.jcr.query.QueryManager的典型用法代码示例。如果您正苦于以下问题:Java QueryManager类的具体用法?Java QueryManager怎么用?Java QueryManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QueryManager类属于javax.jcr.query包,在下文中一共展示了QueryManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrievePlanNodes

import javax.jcr.query.QueryManager; //导入依赖的package包/类
private NodeIterator retrievePlanNodes(long limit, long offset) throws RepositoryException {
    this.session.getWorkspace().getQueryManager();
    final QueryManager queryManager = this.session.getWorkspace().getQueryManager();
    final QueryObjectModelFactory factory = queryManager.getQOMFactory();

    final Source selector = factory.selector("scape:plan", "resourcesSelector");
    final Constraint constraints = factory.fullTextSearch("resourcesSelector", null, factory.literal(session.getValueFactory().createValue("*")));

    final Query query = factory.createQuery(selector, constraints, null, null);

    if (limit > 0) {
        query.setLimit(limit);
    }
    if (offset > 0) {
        query.setOffset(offset);
    }
    return query.execute().getNodes();
}
 
开发者ID:fasseg,项目名称:fcrepo4-scape,代码行数:19,代码来源:PlanList.java

示例2: queryJcrContent

import javax.jcr.query.QueryManager; //导入依赖的package包/类
String queryJcrContent(Session session) throws RepositoryException {

    // get query manager
    QueryManager queryManager = session.getWorkspace().getQueryManager();

    // query for all nodes with tag "JCR"
    Query query = queryManager.createQuery("/jcr:root/content/adaptto//*[tags='JCR']", Query.XPATH);

    // iterate over results
    QueryResult result = query.execute();
    NodeIterator nodes = result.getNodes();
    StringBuilder output = new StringBuilder();
    while (nodes.hasNext()) {
      Node node = nodes.nextNode();
      output.append("path=" + node.getPath() + "\n");
    }

    return output.toString();
  }
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:20,代码来源:JcrQuerySample.java

示例3: getPosts

import javax.jcr.query.QueryManager; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:33,代码来源:BlogServiceImpl.java

示例4: searchObjectOfType

import javax.jcr.query.QueryManager; //导入依赖的package包/类
/**
 * Search objects in Fedora with a given JCR Mixin Type using a simple term
 *
 * @param session
 *            the {@link Session} to use for the operation
 * @param mixinType
 *            the mixin type to look for
 * @param terms
 *            the search term to match objects against
 * @param offset
 *            the offset of the search results
 * @param limit
 *            the maximum number of search results
 * @return a {@link java.util.List} containing the paths of the found objects in
 *         Fedora
 * @throws RepositoryException
 *             if an error occurred searching in Fedora
 */
public List<String> searchObjectOfType(final Session session, final String mixinType, final String terms, final int offset, final int limit)
        throws RepositoryException {
    final QueryManager queryManager = session.getWorkspace().getQueryManager();

    final QueryObjectModelFactory factory = queryManager.getQOMFactory();

    final Source selector = factory.selector(mixinType, "resourcesSelector");
    final Constraint constraints = factory.fullTextSearch("resourcesSelector", null, factory.literal(session.getValueFactory().createValue(terms)));

    final Query query = factory.createQuery(selector, constraints, null, null);

    query.setLimit(limit);
    query.setOffset(offset);
    final QueryResult result = query.execute();
    final NodeIterator it = result.getNodes();
    final List<String> uris = new ArrayList<>();
    while (it.hasNext()) {
        Node n = it.nextNode();
        uris.add(n.getPath());
    }
    return uris;
}
 
开发者ID:fasseg,项目名称:fcrepo4-scape,代码行数:41,代码来源:ConnectorService.java

示例5: excSQL

import javax.jcr.query.QueryManager; //导入依赖的package包/类
private QueryResult excSQL(String sqlQuery, Boolean limit) throws Exception {

    SessionProvider sessionProvider = WCMCoreUtils.getUserSessionProvider();
    Session session = sessionProvider.getSession(WCMCoreUtils.getRepository()
                                                             .getConfiguration()
                                                             .getDefaultWorkspaceName(),
                                                 WCMCoreUtils.getRepository());

    // make SQL query
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    QueryImpl query = (QueryImpl) queryManager.createQuery(sqlQuery, Query.SQL);
    if (limit) {

      if (this.getQueryStart() != 0) {
        query.setOffset(getQueryStart());
        log.debug(" ================ start " + getQueryStart() + " ========================== ");
      }
      query.setLimit(UIAddOnSearchResult.ITEMS_PER_PAGE);

    }
    // execute query and fetch result
    QueryResult result = query.execute();
    return result;
      
  }
 
开发者ID:exo-addons,项目名称:marketplace-extension,代码行数:26,代码来源:UIAddOnSearchResult.java

示例6: executeJCRQuery

import javax.jcr.query.QueryManager; //导入依赖的package包/类
public static QueryResult executeJCRQuery (Session session, String theQuery) {
	//--- JCR Query REsult Obj
	QueryResult addonsResult = null;
	//--- Quary Manager Ins
	QueryManager queryManager = null;
	//--- Query IMPL Ins
	QueryImpl jcrQ = null;
	try {
		//--- make SQL query/*
		queryManager = session.getWorkspace().getQueryManager();
		jcrQ = (QueryImpl) queryManager.createQuery(theQuery, Query.SQL);
		// execute query and fetch result*/
		addonsResult = jcrQ.execute();

	} catch (Exception e) {
		log.error("Fail to execude JCR query [{}]",theQuery,e);

	}

	return addonsResult;
}
 
开发者ID:exo-addons,项目名称:marketplace-extension,代码行数:22,代码来源:AddOnService.java

示例7: queryForVanityUrlNode

import javax.jcr.query.QueryManager; //导入依赖的package包/类
/**
 * Query for a vanity url node.
 *
 * @param vanityUrl vanity url from request
 * @param siteName  site name from aggegation state
 * @return first vanity url node of result or null, if nothing found
 */
public Node queryForVanityUrlNode(final String vanityUrl, final String siteName) {
    Node node = null;

    try {
        Session jcrSession = MgnlContext.getJCRSession(VanityUrlModule.WORKSPACE);
        QueryManager queryManager = jcrSession.getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(QUERY, JCR_SQL2);
        query.bindValue(PN_VANITY_URL, new StringValue(vanityUrl));
        query.bindValue(PN_SITE, new StringValue(siteName));
        QueryResult queryResult = query.execute();
        NodeIterator nodes = queryResult.getNodes();
        if (nodes.hasNext()) {
            node = nodes.nextNode();
        }
    } catch (RepositoryException e) {
        LOGGER.error("Error message.", e);
    }

    return node;
}
 
开发者ID:aperto,项目名称:magnolia-vanity-url,代码行数:28,代码来源:VanityUrlService.java

示例8: list

import javax.jcr.query.QueryManager; //导入依赖的package包/类
public Iterator<String> list() throws MessagingException {
    try {
        Session session = login();
        try {
            Collection<String> keys = new ArrayList<String>();
            QueryManager manager = session.getWorkspace().getQueryManager();
            Query query = manager.createQuery("/jcr:root/" + MAIL_PATH + "//element(*,james:mail)", Query.XPATH);
            NodeIterator iterator = query.execute().getNodes();
            while (iterator.hasNext()) {
                String name = iterator.nextNode().getName();
                keys.add(Text.unescapeIllegalJcrChars(name));
            }
            return keys.iterator();
        } finally {
            session.logout();
        }
    } catch (RepositoryException e) {
        throw new MessagingException("Unable to list messages", e);
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:21,代码来源:JCRMailRepository.java

示例9: internalRemove

import javax.jcr.query.QueryManager; //导入依赖的package包/类
@Override
protected void internalRemove(String key) throws MessagingException {
    try {
        Session session = login();
        try {
            String name = ISO9075.encode(Text.escapeIllegalJcrChars(key));
            QueryManager manager = session.getWorkspace().getQueryManager();
            Query query = manager.createQuery("/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)", Query.XPATH);
            NodeIterator nodes = query.execute().getNodes();
            if (nodes.hasNext()) {
                while (nodes.hasNext()) {
                    nodes.nextNode().remove();
                }
                session.save();
                logger.info("Mail " + key + " removed from repository");
            } else {
                logger.warn("Mail " + key + " not found");
            }
        } finally {
            session.logout();
        }
    } catch (RepositoryException e) {
        throw new MessagingException("Unable to remove message: " + key, e);
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:26,代码来源:JCRMailRepository.java

示例10: getResourcesFromQuery

import javax.jcr.query.QueryManager; //导入依赖的package包/类
private List<Resource> getResourcesFromQuery(ResourceResolver resourceResolver, String language, String statement, String relPath) throws RepositoryException {
    final List<Resource> resources = new ArrayList<>();
    QueryManager queryManager = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager();
    NodeIterator nodeIter = queryManager.createQuery(statement, language).execute().getNodes();

    while (nodeIter.hasNext()) {
        Resource resource = resourceResolver.getResource(nodeIter.nextNode().getPath());
        final Resource relativeAwareResource = getRelativeAwareResource(resource, relPath);

        if (relativeAwareResource != null) {
            resources.add(relativeAwareResource);
        }
    }

    return resources;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:17,代码来源:QueryHelperImpl.java

示例11: getRepositoryCount

import javax.jcr.query.QueryManager; //导入依赖的package包/类
/**
 * @param repository the repository
 * @return a double of the size of the fedora:datastream binary content
 * @throws RepositoryException if repository exception occurred
 */
public static long getRepositoryCount(final Repository repository)
    throws RepositoryException {
    final Session session = repository.login();
    try {
        final QueryManager queryManager =
            session.getWorkspace().getQueryManager();

        final String querystring =
            "SELECT [" + JCR_PATH + "] FROM ["
                    + FEDORA_CONTAINER + "]";

        final QueryResult queryResults =
            queryManager.createQuery(querystring, JCR_SQL2).execute();

        return queryResults.getRows().getSize();
    } finally {
        session.logout();
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:25,代码来源:ServiceHelpers.java

示例12: getRepositorySize

import javax.jcr.query.QueryManager; //导入依赖的package包/类
/**
 * @param repository the repository
 * @return a double of the size of the fedora:datastream binary content
 * @throws RepositoryException if repository exception occurred
 */
public static long getRepositorySize(final Repository repository)
    throws RepositoryException {
    final Session session = repository.login();
    try {
        long sum = 0;
        final QueryManager queryManager =
                session.getWorkspace().getQueryManager();

        final String querystring =
                "SELECT [" + CONTENT_SIZE + "] FROM [" +
                        FEDORA_BINARY + "]";

        final QueryResult queryResults =
                queryManager.createQuery(querystring, JCR_SQL2).execute();

        for (final RowIterator rows = queryResults.getRows(); rows.hasNext(); ) {
            final Value value =
                    rows.nextRow().getValue(CONTENT_SIZE);
            sum += value.getLong();
        }
        return sum;
    } finally {
        session.logout();
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:31,代码来源:ServiceHelpers.java

示例13: testSimple

import javax.jcr.query.QueryManager; //导入依赖的package包/类
public void testSimple() throws Exception {
  MockRepositoryEventList mrel = new MockRepositoryEventList(
      "MockRepositoryEventLog1.txt");
  MockRepository r = new MockRepository(mrel);
  QueryManager qm = new MockJcrQueryManager(r.getStore());
  TraversalManager qtm = new JcrTraversalManager(qm);
  MockPusher pusher = new MockPusher(System.out);
  DocumentList documentList = qtm.startTraversal();
  int counter = 0;
  Document document = null;
  while ((document = documentList.nextDocument()) != null) {
    pusher.take(document);
    counter++;
  }
  Assert.assertEquals(4, counter);
  Assert.assertEquals(4, pusher.getTotalDocs());
  pusher.cancel();
  Assert.assertEquals(0, pusher.getTotalDocs());
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:20,代码来源:MockPusherTest.java

示例14: takeMultiFeed

import javax.jcr.query.QueryManager; //导入依赖的package包/类
private void takeMultiFeed(String expectedXml, String repository)
    throws Exception {
  String gsaExpectedResponse = GsaFeedConnection.SUCCESS_RESPONSE;
  String gsaActualResponse;

  MockRepositoryEventList mrel = new MockRepositoryEventList(repository);
  MockRepository r = new MockRepository(mrel);
  QueryManager qm = new MockJcrQueryManager(r.getStore());
  TraversalManager qtm = new JcrTraversalManager(qm);

  MockFeedConnection feedConnection = new MockFeedConnection();
  DocPusher dpusher = new DocPusher(feedConnection, "junit", fsli);
  DocumentList documentList = qtm.startTraversal();

  Document document = null;
  while ((document = documentList.nextDocument()) != null) {
    dpusher.take(document);
  }
  dpusher.flush();
  String resultXML = feedConnection.getFeed();
  Assert.assertEquals(expectedXml, resultXML);
  gsaActualResponse = dpusher.getGsaResponse();
  Assert.assertEquals(gsaExpectedResponse, gsaActualResponse);
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:25,代码来源:DocPusherTest.java

示例15: executeMockQuery

import javax.jcr.query.QueryManager; //导入依赖的package包/类
private void executeMockQuery(String workspace, String expectedQuery, List<Node> results) throws Exception {
    Session mockSession = mock(Session.class);
    Workspace mockWorkspace = mock(Workspace.class);
    QueryManager mockQueryManager = mock(QueryManager.class);
    Query mockQuery = mock(Query.class);
    QueryResult mockQueryResult = mock(QueryResult.class);

    doReturn(mockSession).when(mockWebContext).getJCRSession(workspace);
    doReturn(mockWorkspace).when(mockSession).getWorkspace();
    doReturn(mockQueryManager).when(mockWorkspace).getQueryManager();

    doReturn(mockQuery).when(mockQueryManager).createQuery(expectedQuery, Query.JCR_SQL2);
    doReturn(mockQueryResult).when(mockQuery).execute();
    doReturn(new NodeIteratorAdapter(results)).when(mockQueryResult).getNodes();
}
 
开发者ID:tricode,项目名称:magnolia-blog,代码行数:16,代码来源:BlogRenderableDefinitionTest.java


注:本文中的javax.jcr.query.QueryManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。