use of javax.jcr.query.qom.QueryObjectModelFactory in project jackrabbit by apache.
the class SQL2PathEscapingTest method testGetChildrenApiDirect.
/**
* will build a query directly via the api using a spaced path
*
* @throws Exception
*/
public void testGetChildrenApiDirect() throws Exception {
QueryObjectModelFactory qomf = qm.getQOMFactory();
Source source1 = qomf.selector(NodeType.NT_BASE, "selector");
Column[] columns = new Column[] { qomf.column("selector", null, null) };
Constraint constraint2 = qomf.childNode("selector", n1.getPath());
QueryObjectModel qom = qomf.createQuery(source1, constraint2, null, columns);
checkResult(qom.execute(), 2);
}
use of javax.jcr.query.qom.QueryObjectModelFactory in project jackrabbit by apache.
the class QueryManagerImpl method getQuery.
/**
* @see QueryManager#getQuery(Node)
*/
public Query getQuery(Node node) throws InvalidQueryException, RepositoryException {
checkIsAlive();
NamePathResolver resolver = mgrProvider.getNamePathResolver();
if (!node.isNodeType(resolver.getJCRName(NameConstants.NT_QUERY))) {
throw new InvalidQueryException("Node is not of type nt:query");
}
if (node.getSession() != session) {
throw new InvalidQueryException("Node belongs to a different session.");
}
String statement = node.getProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT)).getString();
String language = node.getProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE)).getString();
if (Query.JCR_JQOM.equals(language)) {
QueryObjectModelFactory qomFactory = new QOMFactory(node, resolver);
QueryObjectModelBuilder builder = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language);
return builder.createQueryObjectModel(statement, qomFactory, valueFactory);
} else {
return new QueryImpl(session, mgrProvider, itemMgr, wspManager, statement, language, node);
}
}
use of javax.jcr.query.qom.QueryObjectModelFactory in project jackrabbit by apache.
the class QueryImpl method columnForName.
/**
* Returns a column for the given property name and the default selector
* name.
*
* @param propertyName the name of the property as well as the column.
* @return a column.
* @throws RepositoryException if an error occurs while creating the column.
*/
protected ColumnImpl columnForName(Name propertyName) throws RepositoryException {
Workspace workspace = sessionContext.getSessionImpl().getWorkspace();
QueryObjectModelFactory qomFactory = workspace.getQueryManager().getQOMFactory();
String name = sessionContext.getJCRName(propertyName);
return (ColumnImpl) qomFactory.column(sessionContext.getJCRName(DEFAULT_SELECTOR_NAME), name, name);
}
use of javax.jcr.query.qom.QueryObjectModelFactory in project jackrabbit by apache.
the class QueryImpl method getColumns.
/**
* Returns the columns for this query.
*
* @return array of columns.
* @throws RepositoryException if an error occurs.
*/
protected ColumnImpl[] getColumns() throws RepositoryException {
SessionImpl session = sessionContext.getSessionImpl();
QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
// get columns
Map<Name, ColumnImpl> columns = new LinkedHashMap<Name, ColumnImpl>();
for (Name name : root.getSelectProperties()) {
String pn = sessionContext.getJCRName(name);
ColumnImpl col = (ColumnImpl) qomFactory.column(sessionContext.getJCRName(DEFAULT_SELECTOR_NAME), pn, pn);
columns.put(name, col);
}
if (columns.size() == 0) {
// use node type constraint
LocationStepQueryNode[] steps = root.getLocationNode().getPathSteps();
final Name[] ntName = new Name[1];
steps[steps.length - 1].acceptOperands(new DefaultQueryNodeVisitor() {
public Object visit(AndQueryNode node, Object data) throws RepositoryException {
return node.acceptOperands(this, data);
}
public Object visit(NodeTypeQueryNode node, Object data) {
ntName[0] = node.getValue();
return data;
}
}, null);
if (ntName[0] == null) {
ntName[0] = NameConstants.NT_BASE;
}
NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
for (PropertyDefinition pd : propDefs) {
QPropertyDefinition propDef = ((PropertyDefinitionImpl) pd).unwrap();
if (!propDef.definesResidual() && !propDef.isMultiple()) {
columns.put(propDef.getName(), columnForName(propDef.getName()));
}
}
}
// add jcr:path and jcr:score if not selected already
if (!columns.containsKey(NameConstants.JCR_PATH)) {
columns.put(NameConstants.JCR_PATH, columnForName(NameConstants.JCR_PATH));
}
if (!columns.containsKey(NameConstants.JCR_SCORE)) {
columns.put(NameConstants.JCR_SCORE, columnForName(NameConstants.JCR_SCORE));
}
return columns.values().toArray(new ColumnImpl[columns.size()]);
}
use of javax.jcr.query.qom.QueryObjectModelFactory in project jackrabbit by apache.
the class SQL2PathEscapingTest method testGetChildrenApiStatement.
/**
* the statement behind the api should be consistent, and return a similar
* query. in our case it should escape the paths that have spaces in them by
* enclosing them in single quotes
*
* @throws Exception
*/
public void testGetChildrenApiStatement() throws Exception {
QueryObjectModelFactory qomf = qm.getQOMFactory();
Source source1 = qomf.selector(NodeType.NT_BASE, "selector");
Column[] columns = new Column[] { qomf.column("selector", null, null) };
Constraint constraint2 = qomf.childNode("selector", n1.getPath());
QueryObjectModel qom = qomf.createQuery(source1, constraint2, null, columns);
checkResult(executeSQL2Query(qom.getStatement()), 2);
}
Aggregations