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


Java QueryManager.createQuery方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: findByXPath

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
/**
 * Find JCR nodes that match the xpath supplied, and map to objects.
 * 
 * @param xpath the XPath for finding the nodes
 * @param nodeFilter the NodeFilter to apply when updating child nodes and references
 * @param startIndex the zero based index of the first item to return
 * @param resultSize the number of items to return
 * @return a list of all objects found
 */
protected List<T> findByXPath(String xpath, NodeFilter nodeFilter, long startIndex, long resultSize) {
    try {
        QueryManager queryManager = getSession().getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(xpath, Query.XPATH);
        QueryResult result = query.execute();
        NodeIterator nodeIterator = result.getNodes();
        nodeIterator.skip(startIndex);
        return toList(nodeIterator, nodeFilter, resultSize);
    } catch (RepositoryException e) {
        throw new JcrMappingException("Could not find nodes by XPath", e);
    }
}
 
开发者ID:dooApp,项目名称:jcromfx,代码行数:22,代码来源:AbstractJcrDAO.java

示例9: findBySql

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
/**
 * Find JCR nodes that match the SQL supplied, and map to objects.
 * 
 * @param sql the SQL for finding the nodes
 * @param nodeFilter the NodeFilter to apply when updating child nodes and references
 * @param startIndex the zero based index of the first item to return
 * @param resultSize the number of items to return
 * @return a list of all objects found
 */
protected List<T> findBySql(String sql, NodeFilter nodeFilter, long startIndex, long resultSize) {
    try {
        QueryManager queryManager = getSession().getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(sql, Query.JCR_SQL2);
        QueryResult result = query.execute();
        NodeIterator nodeIterator = result.getNodes();
        nodeIterator.skip(startIndex);
        return toList(nodeIterator, nodeFilter, resultSize);
    } catch (RepositoryException e) {
        throw new JcrMappingException("Could not find nodes by SQL", e);
    }
}
 
开发者ID:dooApp,项目名称:jcromfx,代码行数:22,代码来源:AbstractJcrDAO.java

示例10: dependentPagesAvailable

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
private boolean dependentPagesAvailable(String nodeId) throws RepositoryException {
    QueryManager queryManager = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE)
            .getWorkspace().getQueryManager();
    String expression = "SELECT * FROM [mgnl:page] WHERE [mgnl:supplierPage] = '" + nodeId + "'";
    Query query = queryManager.createQuery(expression, Query.JCR_SQL2);
    QueryResult result = query.execute();
    return result.getRows().hasNext();
}
 
开发者ID:magnoliales,项目名称:magnolia-handlebars,代码行数:9,代码来源:IsNotSupplierPageRule.java

示例11: getEventsByType

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
private List<CalendarEvent> getEventsByType(Node calendarHome, int type, java.util.Calendar date) throws Exception {
  List<CalendarEvent> events = new ArrayList<CalendarEvent>();
  QueryManager qm = calendarHome.getSession().getWorkspace().getQueryManager();
  Query query = qm.createQuery("select * from exo:calendarEvent where (jcr:path like '" + calendarHome.getPath() + "/%') and (exo:lastModifiedDate > TIMESTAMP '" + ISO8601.format(date) + "')", Query.SQL);
  QueryResult result = query.execute();
  NodeIterator it = result.getNodes();
  CalendarEvent calEvent;
  while (it.hasNext()) {
    calEvent = storage.getEvent(it.nextNode());
    calEvent.setCalType(String.valueOf(type));
    events.add(calEvent);
  }
  return events;
}
 
开发者ID:exo-addons,项目名称:exchange-extension,代码行数:15,代码来源:ExoStorageService.java

示例12: fetchResults

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
private ResultsPage fetchResults(int limit, int offset) throws ReportException {
  prepareStatement();
  ResourceResolver resolver = request.getResourceResolver();
  Session session = resolver.adaptTo(Session.class);
  List<Object> results = new ArrayList<>();
  try {
    QueryManager queryMgr = session.getWorkspace().getQueryManager();

    Query query = queryMgr.createQuery(statement, config.getQueryLanguage());

    if (page != -1) {
      log.debug("Fetching results with limit {} and offset {}", new Object[] { limit, offset });
      query.setLimit(limit);
      query.setOffset(offset);
    } else {
      log.debug("Fetching all results");
    }
    QueryResult result = query.execute();
    NodeIterator nodes = result.getNodes();

    while (nodes.hasNext()) {
      results.add(resolver.getResource(nodes.nextNode().getPath()));
    }
  } catch (RepositoryException re) {
    log.error("Exception executing search results", re);
    throw new ReportException("Exception executing search results", re);
  }
  return new ResultsPage(results, config.getPageSize(), page);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:30,代码来源:QueryReportExecutor.java

示例13: getDetails

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
@Override
public String getDetails() throws ReportException {
  Map<String, String> details = new LinkedHashMap<String, String>();
  details.put("Language", config.getQueryLanguage());
  details.put("Page", Integer.toString(page));
  details.put("Page Size", Integer.toString(config.getPageSize()));
  details.put("Query", statement);

  try {
    final QueryManager queryManager = request.getResourceResolver().adaptTo(Session.class).getWorkspace()
        .getQueryManager();
    final Query query = queryManager.createQuery("explain " + statement, config.getQueryLanguage());
    final QueryResult queryResult = query.execute();

    final RowIterator rows = queryResult.getRows();
    while (rows.hasNext()) {
      final Row row = rows.nextRow();

      String[] cols = queryResult.getColumnNames();
      Value[] values = row.getValues();

      for (int i = 0; i < cols.length; i++) {
        details.put(cols[i], values[i].getString());
      }
    }

  } catch (RepositoryException re) {
    log.error("Exception getting details", re);
    throw new ReportException("Exception getting details", re);
  }
  StringBuilder sb = new StringBuilder();
  for (Entry<String, String> entry : details.entrySet()) {
    sb.append("<dt>" + StringEscapeUtils.escapeHtml(entry.getKey()) + "</dt>");
    sb.append("<dd>" + StringEscapeUtils.escapeHtml(entry.getValue()) + "</dd>");
  }

  return "<dl>" + sb.toString() + "</dl>";
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:39,代码来源:QueryReportExecutor.java

示例14: isTraversal

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
@Override
public boolean isTraversal(ResourceResolver resourceResolver, String language, String statement) throws RepositoryException {
    final QueryManager queryManager = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager();

    final Query query = queryManager.createQuery("explain " + statement, language);
    final QueryResult queryResult = query.execute();

    final RowIterator rows = queryResult.getRows();
    final Row firstRow = rows.nextRow();

    final String plan = firstRow.getValue("plan").getString();
    return StringUtils.contains(plan, " /* traverse ");
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:14,代码来源:QueryHelperImpl.java

示例15: getGroupOptions

import javax.jcr.query.QueryManager; //导入方法依赖的package包/类
/**
 * Creates a JSON array of the User Groups principals in the system.
 * @param resourceResolver the security context used to collect the groups.
 * @return a JSON Array of all the user group principals name that the resourceResolver can read.
 * @throws RepositoryException
 */
private JsonArray getGroupOptions(ResourceResolver resourceResolver) throws RepositoryException {
    final JsonArray jsonArray = new JsonArray();
    final QueryManager queryManager = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager();
    final Query query = queryManager.createQuery(QUERY, Query.JCR_SQL2);
    final NodeIterator nodeIter = query.execute().getNodes();

    while (nodeIter.hasNext()) {
        Resource resource = resourceResolver.getResource(nodeIter.nextNode().getPath());
        jsonArray.add(new JsonPrimitive(resource.getValueMap().get("rep:principalName", "Unknown")));
    }

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


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