本文整理汇总了Java中javax.jcr.query.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于javax.jcr.query包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrievePlanNodes
import javax.jcr.query.Query; //导入依赖的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();
}
示例2: queryJcrContent
import javax.jcr.query.Query; //导入依赖的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();
}
示例3: getWrappedNodesFromQuery
import javax.jcr.query.Query; //导入依赖的package包/类
/**
* Query news items using JCR SQL2 syntax.
*
* @param query Query string
* @param maxResultSize Max results returned
* @param pageNumber paging number
* @param nodeTypeName Node type
* @return List List of news item nodes
* @throws javax.jcr.RepositoryException Repository Exceotopn
*/
public static List<Node> getWrappedNodesFromQuery(String query, int maxResultSize, int pageNumber, String nodeTypeName) throws RepositoryException {
final List<Node> itemsListPaged = new ArrayList<>(0);
final NodeIterator items = QueryUtil.search(NewsRepositoryConstants.COLLABORATION, query, Query.JCR_SQL2, nodeTypeName);
// Paging result set
final int startRow = (maxResultSize * (pageNumber - 1));
if (startRow > 0) {
try {
items.skip(startRow);
} catch (NoSuchElementException e) {
LOGGER.error("No more news items found beyond this item number: {}", startRow);
}
}
int count = 1;
while (items.hasNext() && count <= maxResultSize) {
itemsListPaged.add(new I18nNodeWrapper(items.nextNode()));
count++;
}
return itemsListPaged;
}
示例4: executeQuery
import javax.jcr.query.Query; //导入依赖的package包/类
/**
* Execute JCR query returning Nodes matching given statement and return node type
*
* @param statement JCR query string
* @param workspace Search in JCR workspace like website
* @param returnItemType Return nodes based on primary node type
* @return List<Node>
* @throws javax.jcr.RepositoryException
*/
private static List<Node> executeQuery(final String statement,
final String workspace,
final String returnItemType) throws RepositoryException {
List<Node> nodeList = new ArrayList<>(0);
NodeIterator items = QueryUtil.search(workspace, statement, Query.JCR_SQL2, returnItemType);
LOGGER.debug("Query Executed: {}", statement);
while (items.hasNext()) {
Node node = items.nextNode();
nodeList.add(new I18nNodeWrapper(node));
}
return nodeList;
}
示例5: getWrappedNodesFromQuery
import javax.jcr.query.Query; //导入依赖的package包/类
private static List<Node> getWrappedNodesFromQuery(String query, int maxResultSize, int pageNumber, String nodeTypeName, String workspace) throws RepositoryException {
final List<Node> itemsListPaged = new ArrayList<>(0);
final NodeIterator items = QueryUtil.search(workspace, query, Query.JCR_SQL2, nodeTypeName);
// Paging result set
final int startRow = (maxResultSize * (pageNumber - 1));
if (startRow > 0) {
try {
items.skip(startRow);
} catch (NoSuchElementException e) {
LOGGER.info("No more blog items found beyond this item number: {}", startRow);
}
}
int count = 1;
while (items.hasNext() && count <= maxResultSize) {
itemsListPaged.add(new I18nNodeWrapper(items.nextNode()));
count++;
}
return itemsListPaged;
}
示例6: getPosts
import javax.jcr.query.Query; //导入依赖的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;
}
示例7: searchObjectOfType
import javax.jcr.query.Query; //导入依赖的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;
}
示例8: getReferences
import javax.jcr.query.Query; //导入依赖的package包/类
/**
* Searches all reference properties to the specified {@code tree} that match
* the given name and node type constraints.
*
* @param weak if {@code true} only weak references are returned. Otherwise only
* hard references are returned.
* @param tree The tree for which references should be searched.
* @param propertyName A name constraint for the reference properties;
* {@code null} if no constraint should be enforced.
* @param nodeTypeNames Node type constraints to be enforced when using
* for reference properties; the specified names are expected to be internal
* oak names.
* @return A set of oak paths of those reference properties referring to the
* specified {@code tree} and matching the constraints.
*/
@Nonnull
public Iterable<String> getReferences(boolean weak, Tree tree, final String propertyName, final String... nodeTypeNames) {
if (!nodeTypeManager.isNodeType(tree, JcrConstants.MIX_REFERENCEABLE)) {
return Collections.emptySet(); // shortcut
}
final String uuid = getIdentifier(tree);
String reference = weak ? PropertyType.TYPENAME_WEAKREFERENCE : PropertyType.TYPENAME_REFERENCE;
String pName = propertyName == null ? "*" : propertyName; // TODO: sanitize against injection attacks!?
Map<String, ? extends PropertyValue> bindings = Collections.singletonMap("uuid", PropertyValues.newString(uuid));
try {
Result result = root.getQueryEngine().executeQuery(
"SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference + "') = $uuid",
Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, NO_MAPPINGS);
return findPaths(result, uuid, propertyName, nodeTypeNames,
weak ? Type.WEAKREFERENCE : Type.REFERENCE,
weak ? Type.WEAKREFERENCES : Type.REFERENCES
);
} catch (ParseException e) {
log.error("query failed", e);
return Collections.emptySet();
}
}
示例9: resolveUUID
import javax.jcr.query.Query; //导入依赖的package包/类
private String resolveUUID(PropertyValue uuid) {
try {
Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid);
Result result = root.getQueryEngine().executeQuery(
"SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id", Query.JCR_SQL2,
Long.MAX_VALUE, 0, bindings, NO_MAPPINGS);
String path = null;
for (ResultRow rr : result.getRows()) {
if (path != null) {
log.error("multiple results for identifier lookup: " + path + " vs. " + rr.getPath());
return null;
} else {
path = rr.getPath();
}
}
return path;
} catch (ParseException ex) {
log.error("query failed", ex);
return null;
}
}
示例10: query
import javax.jcr.query.Query; //导入依赖的package包/类
@Test
public void query() throws Exception {
Tree t = root.getTree("/");
t.addChild("a").addChild("n").setProperty("myProp", "foo");
t.addChild("b").addChild("n").setProperty("myProp", "bar");
t.addChild("c").addChild("x").setProperty("myProp", "foo");
t.setProperty("myProp", "foo");
root.commit();
setTravesalEnabled(false);
assertQuery("select [jcr:path] from [nt:base] where [n/myProp] is not null",
ImmutableList.of("/a", "/b"));
List<String> lines = executeQuery(
"explain select [jcr:path] from [nt:base] where [n/myProp] is not null",
Query.JCR_SQL2);
assertEquals(1, lines.size());
// make sure it used the property index
assertTrue(lines.get(0).contains("property myProp"));
assertQuery(
"select [jcr:path] from [nt:base] where [n/myProp] = 'foo'",
ImmutableList.of("/a"));
setTravesalEnabled(false);
}
示例11: getGroupNodeByName
import javax.jcr.query.Query; //导入依赖的package包/类
/**
* Gets the Node for the specified name. If no node with the specified name exists, null is returned.
*
* @param groupName the name of the Group to return
* @return the Node with name groupName
*/
public Node getGroupNodeByName(final String groupName) {
final String escapedGroupName = Text.escapeIllegalJcr10Chars(ISO9075.encode(NodeNameCodec.encode(groupName, true)));
final String queryString = QUERY_GROUP.replace("{}", escapedGroupName);
try {
@SuppressWarnings("deprecation") final Query query = getQueryManager().createQuery(queryString, Query.SQL);
final QueryResult queryResult = query.execute();
final NodeIterator iterator = queryResult.getNodes();
if (!iterator.hasNext()) {
return null;
}
final Node node = iterator.nextNode();
return node;
} catch (RepositoryException e) {
log.error("Unable to check if group '{}' exists, returning true", groupName, e);
return null;
}
}
示例12: excSQL
import javax.jcr.query.Query; //导入依赖的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;
}
示例13: executeJCRQuery
import javax.jcr.query.Query; //导入依赖的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;
}
示例14: queryForVanityUrlNode
import javax.jcr.query.Query; //导入依赖的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;
}
示例15: list
import javax.jcr.query.Query; //导入依赖的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);
}
}