|| c.selectorName .equals(selector.getSelectorName())) { Column column = factory.column(selector .getSelectorName(), null, null); columns.add(column); Column column; if (c.selectorName != null) { column = factory.column(c.selectorName, c.propertyName, c.columnName); } else if (c.columnName != null) { column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.columnName); } else { column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.propertyName);
|| c.selectorName .equals(selector.getSelectorName())) { Column column = factory.column(selector .getSelectorName(), null, null); columns.add(column); Column column; if (c.selectorName != null) { column = factory.column(c.selectorName, c.propertyName, c.columnName); } else if (c.columnName != null) { column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.columnName); } else { column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.propertyName);
|| c.selectorName .equals(selector.getSelectorName())) { Column column = factory.column(selector .getSelectorName(), null, null); columns.add(column); Column column; if (c.selectorName != null) { column = factory.column(c.selectorName, c.propertyName, c.columnName); } else if (c.columnName != null) { column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.columnName); } else { column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.propertyName);
/** * From the spec: * <p> * If propertyName is specified, columnName is required and used to name * the column in the tabular results. */ public void testColumnNames() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, SELECTOR_1), null, null, new Column[]{qf.column(SELECTOR_1, propertyName1, propertyName1)}); forQOMandSQL2(qom, new Callable() { public Object call(Query query) throws RepositoryException { QueryResult result = query.execute(); List<String> names = new ArrayList<String>(Arrays.asList(result.getColumnNames())); assertTrue("Missing column: " + propertyName1, names.remove(propertyName1)); for (Iterator<String> it = names.iterator(); it.hasNext(); ) { fail(it.next() + " was not declared as a column"); } return null; } }); }
@Test public void column() throws RepositoryException { Column c = f.column("selectorName", "propertyName", "columnName"); assertEquals("selectorName", c.getSelectorName()); assertEquals("propertyName", c.getPropertyName()); assertEquals("columnName", c.getColumnName()); assertEquals("[selectorName].[propertyName] AS [columnName]", c.toString()); assertEquals("[p]", f.column(null, "p", null).toString()); assertEquals("[p] AS [c]", f.column(null, "p", "c").toString()); assertEquals("[s].[p]", f.column("s", "p", null).toString()); assertEquals("[s].[p] AS [c]", f.column("s", "p", "c").toString()); assertEquals("[s].* AS [c]", f.column("s", null, "c").toString()); assertEquals("* AS [c]", f.column(null, null, "c").toString()); assertEquals("*", f.column(null, null, null).toString()); assertEquals("[s].*", f.column("s", null, null).toString()); }
null, null, new Column[]{qf.column(SELECTOR_1, null, null)}); forQOMandSQL2(qom, new Callable() { public Object call(Query query) throws RepositoryException {
/** * Test case for {@link QueryObjectModelFactory#column(String, String, String)} */ public void testColumnWithColumnName() throws RepositoryException { Column col = qf.column(SELECTOR_NAME1, propertyName1, COLUMN_NAME); assertEquals("Wrong selector name", SELECTOR_NAME1, col.getSelectorName()); assertEquals("Wrong property name", propertyName1, col.getPropertyName()); assertEquals("Wrong column name", COLUMN_NAME, col.getColumnName()); }
/** * Test case for {@link QueryObjectModelFactory#column(String, String, String)} */ public void testColumn() throws RepositoryException { Column col = qf.column(SELECTOR_NAME1, propertyName1, propertyName1); assertEquals("Wrong selector name", SELECTOR_NAME1, col.getSelectorName()); assertEquals("Wrong property name", propertyName1, col.getPropertyName()); assertEquals("Wrong column name", propertyName1, col.getColumnName()); }
/** * Test case for {@link QueryObjectModelFactory#column(String, String, String)} */ public void testColumnAllProperties() throws RepositoryException { Column col = qf.column(SELECTOR_NAME1, null, null); assertEquals("Wrong selector name", SELECTOR_NAME1, col.getSelectorName()); assertNull("Property name must be null", col.getPropertyName()); assertNull("Column name must be null", col.getColumnName()); }
/** * Test case for {@link QueryObjectModelFactory#column(String, String, String)} */ public void testColumnWithSelector() throws RepositoryException { Column col = qf.column(SELECTOR_NAME1, propertyName1, COLUMN_NAME); assertEquals("Wrong selector name", SELECTOR_NAME1, col.getSelectorName()); assertEquals("Wrong property name", propertyName1, col.getPropertyName()); assertEquals("Wrong column name", COLUMN_NAME, col.getColumnName()); }
/** * 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); } }
/** * 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); } }
/** * 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); }
private Row getRow() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, SELECTOR_NAME), qf.descendantNode(SELECTOR_NAME, testRoot), null, new Column[]{qf.column(SELECTOR_NAME, propertyName1, propertyName1)}); RowIterator rows = qom.execute().getRows(); assertTrue("empty result", rows.hasNext()); Row r = rows.nextRow(); assertFalse("result must not contain more than one row", rows.hasNext()); return r; } }
@Test public void jcrNameConversion() throws RepositoryException { assertEquals("[nt:base]", f.column(null, NodeType.NT_BASE, null).toString()); assertEquals("[s1].[nt:base] = [s2].[nt:base]", f.equiJoinCondition("s1", NodeType.NT_BASE, "s2", NodeType.NT_BASE).toString()); assertEquals("CONTAINS([nt:base], null)", f.fullTextSearch(null, NodeType.NT_BASE, null).toString()); assertEquals("CAST('nt:base' AS NAME)", f.literal(vf.createValue(NodeType.NT_BASE, PropertyType.NAME)).toString()); assertEquals("[nt:base] IS NOT NULL", f.propertyExistence(null, NodeType.NT_BASE).toString()); assertEquals("[nt:base]", f.propertyValue(null, NodeType.NT_BASE).toString()); assertEquals("[nt:base]", f.selector(NodeType.NT_BASE, null).toString()); Source source1 = f.selector(NodeType.NT_BASE, "selector"); Column[] columns = new Column[] { f.column("selector", null, null) }; Constraint constraint2 = f.childNode("selector", "/"); QueryObjectModel qom = f.createQuery(source1, constraint2, null, columns); assertEquals("select [selector].* from " + "[nt:base] AS [selector] " + "where ISCHILDNODE([selector], [/])", qom.toString()); }
/** * 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); }
public void testCreateQueryWithConstraintOrderingAndColumn() throws RepositoryException { Selector selector = qf.selector(testNodeType, SELECTOR_NAME1); PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1); PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1); Ordering ordering = qf.ascending(propValue); Column column = qf.column(SELECTOR_NAME1, propertyName1, propertyName1); QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[]{ordering}, new Column[]{column}); assertTrue("Not a selector source", qom.getSource() instanceof Selector); assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence); assertEquals("Wrong size of orderings", 1, qom.getOrderings().length); assertEquals("Wrong size of columns", 1, qom.getColumns().length); }
public void testCreateQueryFromSourceWithConstraintOrderingAndColumn() throws RepositoryException { Source selector = qf.selector(testNodeType, SELECTOR_NAME1); PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1); PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1); Ordering ordering = qf.ascending(propValue); Column column = qf.column(SELECTOR_NAME1, propertyName1, propertyName1); QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[]{ordering}, new Column[]{column}); assertTrue("Not a selector source", qom.getSource() instanceof Selector); assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence); assertEquals("Wrong size of orderings", 1, qom.getOrderings().length); assertEquals("Wrong size of columns", 1, qom.getColumns().length); }
@Test public void createQuery() throws RepositoryException { Selector s = f.selector("nt:file", "x"); BindVariableValue b = f.bindVariable("var"); Constraint c = f.propertyExistence("x", "c"); PropertyValue p = f.propertyValue("x", "propertyName"); c = f.and(f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, b), c); Ordering o = f.ascending(p); Column col = f.column("x", "propertyName", "columnName"); Ordering[] ords = new Ordering[]{o}; Column[] cols = new Column[]{col}; QueryObjectModel q = f.createQuery(s, c, ords, cols); assertEquals(Query.JCR_JQOM, q.getLanguage()); String[] bv = q.getBindVariableNames(); assertEquals(1, bv.length); assertEquals("var", bv[0]); assertEquals(s, q.getSource()); assertEquals(c, q.getConstraint()); assertEquals(o, q.getOrderings()[0]); assertEquals(col, q.getColumns()[0]); }