本文整理汇总了Java中javax.jcr.query.QueryResult类的典型用法代码示例。如果您正苦于以下问题:Java QueryResult类的具体用法?Java QueryResult怎么用?Java QueryResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryResult类属于javax.jcr.query包,在下文中一共展示了QueryResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryJcrContent
import javax.jcr.query.QueryResult; //导入依赖的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();
}
示例2: executeQuery
import javax.jcr.query.QueryResult; //导入依赖的package包/类
@Override
protected QueryResult executeQuery(String statement, String language, long limit, long offset) throws RepositoryException {
log.debug("ST: {}", statement);
String[] segments = StringUtils.split(path, "/");
// templates needs 2 queries - one for website and one for config
if ("templates".equals(segments[2])) {
// pages
QueryResult res1 = super.executeQuery(statement, language, limit, offset);
// config
this.setWorkspace(RepositoryConstants.CONFIG);
statement = StringUtils.substringBefore(statement, " where ") + " where"
// id references (availability, autogeneration, ...)
+ " contains(t.*,'" + segments[1] + ":" + StringUtils.substringAfter(path, "/templates/") + "')"
// extends
+ buildExtends(path);
log.debug("ST2: {}", statement);
QueryResult res2 = super.executeQuery(statement, language, limit, offset);
return new AggregatedQueryResult(res1, res2);
}
this.setWorkspace(RepositoryConstants.CONFIG);
return super.executeQuery(statement, language, limit, offset);
}
示例3: getPosts
import javax.jcr.query.QueryResult; //导入依赖的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;
}
示例4: searchObjectOfType
import javax.jcr.query.QueryResult; //导入依赖的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;
}
示例5: getGroupNodeByName
import javax.jcr.query.QueryResult; //导入依赖的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;
}
}
示例6: excSQL
import javax.jcr.query.QueryResult; //导入依赖的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;
}
示例7: getDBResource
import javax.jcr.query.QueryResult; //导入依赖的package包/类
private void getDBResource(String sqlQuery) throws Exception {
QueryResult result = this.excSQL(sqlQuery, true);
NodeIterator it = result.getNodes();
while (it.hasNext()) {
Node findedNode = it.nextNode();
if (super.getChildById(findedNode.getUUID()) == null) {
UIAddOnSearchOne uiAddOnSearchOne = addChild(UIAddOnSearchOne.class, null, findedNode.getUUID());
uiAddOnSearchOne.setNodeId(findedNode.getUUID());
uiAddOnSearchOne.setCanEdit(this.getCanEdit());
}
this.data.add(findedNode);
}
}
示例8: executeJCRQuery
import javax.jcr.query.QueryResult; //导入依赖的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;
}
示例9: queryForVanityUrlNode
import javax.jcr.query.QueryResult; //导入依赖的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;
}
示例10: getWebResources
import javax.jcr.query.QueryResult; //导入依赖的package包/类
public Map<String, String> getWebResources(Session session)
throws RepositoryException {
Map<String, String> result = new HashMap<String, String>();
Query query = session
.getWorkspace()
.getQueryManager()
.createQuery(
"SELECT * FROM [webresource:WebResourceGroup] as webResourceGroupSet",
Query.JCR_SQL2);
QueryResult queryResult = query.execute();
NodeIterator queryIt = queryResult.getNodes();
while (queryIt.hasNext()) {
Node webResourceNode = queryIt.nextNode();
result.put(webResourceNode.getProperty(WebResourceGroup.NAME)
.getString(), webResourceNode.getPath());
}
return result;
}
示例11: getWebResourceGroupQueryResults
import javax.jcr.query.QueryResult; //导入依赖的package包/类
/**
*
* Runs Query for Web Resource Nodes in a given group
*
* @param session
* @param webResourceGroupName
* @return
* @throws RepositoryException
*/
protected QueryResult getWebResourceGroupQueryResults(Session session,
String webResourceGroupName) throws RepositoryException {
Query query = session
.getWorkspace()
.getQueryManager()
.createQuery(
"SELECT * FROM [nt:file] INNER JOIN [webresource:WebResourceGroup] as webResourceGroupSet ON ISDESCENDANTNODE([nt:file], webResourceGroupSet) WHERE webResourceGroupSet.[webresource:name] = $webResourceName",
Query.JCR_SQL2);
query.bindValue("webResourceName", session.getValueFactory()
.createValue(webResourceGroupName));
QueryResult queryResult = query.execute();
return queryResult;
}
示例12: getRepositoryCount
import javax.jcr.query.QueryResult; //导入依赖的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();
}
}
示例13: getRepositorySize
import javax.jcr.query.QueryResult; //导入依赖的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();
}
}
示例14: getEntities
import javax.jcr.query.QueryResult; //导入依赖的package包/类
private Entity[] getEntities(QueryResult queryResult) {
try {
NodeIterator nodes = queryResult.getNodes();
List<Entity> entities = new ArrayList<Entity>();
while (nodes.hasNext()) {
Entity entity = getEntity(nodes.nextNode());
if (entity != null) {
entities.add(entity);
}
}
return entities.toArray(new Entity[entities.size()]);
} catch (RepositoryException e) {
throw convertJcrAccessException(e);
}
}
示例15: modifyDashboardState
import javax.jcr.query.QueryResult; //导入依赖的package包/类
private void modifyDashboardState() throws RepositoryException {
LOG.info("Modify dashboard state - add columnCount property");
String path = StorageConstants.DASHBOARDS_ROOT;
String className = "ro.nextreports.server.domain.DashboardState";
String statement = "/jcr:root" + ISO9075.encodePath(path) + "//*[@className='" + className + "']";
QueryResult queryResult = getTemplate().query(statement);
NodeIterator nodes = queryResult.getNodes();
LOG.info("Found " + nodes.getSize() + " dashboard state nodes");
while (nodes.hasNext()) {
Node node = nodes.nextNode();
node.setProperty("columnCount", 2);
}
getTemplate().save();
}