/** * Create a literal from a parsed value. * * @param value the original value * @return the literal */ private Literal getUncastLiteral(Value value) throws RepositoryException { return factory.literal(value); }
/** * Create a literal from a parsed value. * * @param value the original value * @return the literal */ private Literal getUncastLiteral(Value value) throws RepositoryException { return factory.literal(value); }
/** * Create a literal from a parsed value. * * @param value the original value * @return the literal */ private Literal getUncastLiteral(Value value) throws RepositoryException { return factory.literal(value); }
@Override public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException { Map<String, Literal> literals = new HashMap<String, Literal>(); for (Row leftRow : leftRows) { for (Value value : evaluator.getValues(leftProperty, leftRow)) { literals.put(value.getString(), factory.literal(value)); } } List<Constraint> constraints = new ArrayList<Constraint>(literals.size()); for (Literal literal : literals.values()) { constraints.add(factory.comparison( rightProperty, JCR_OPERATOR_EQUAL_TO, literal)); } return constraints; }
@Override public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException { Map<String, Literal> literals = new HashMap<String, Literal>(); for (Row leftRow : leftRows) { for (Value value : evaluator.getValues(leftProperty, leftRow)) { literals.put(value.getString(), factory.literal(value)); } } List<Constraint> constraints = new ArrayList<Constraint>(literals.size()); for (Literal literal : literals.values()) { constraints.add(factory.comparison( rightProperty, JCR_OPERATOR_EQUAL_TO, literal)); } return constraints; }
/** * Test case for {@link QueryObjectModelFactory#literal(Value)} */ public void testLiteral() throws RepositoryException { Value v = superuser.getValueFactory().createValue("test"); Literal literal = qf.literal(v); assertEquals("Wrong literal value", v.getString(), literal.getLiteralValue().getString()); }
@Test public void literal() throws RepositoryException { Value v = vf.createValue(1); Literal l = f.literal(v); assertEquals(v, l.getLiteralValue()); assertEquals("1", l.toString()); assertEquals("'Joe''s'", f.literal(vf.createValue("Joe's")).toString()); assertEquals("' - \" - '", f.literal(vf.createValue(" - \" - ")).toString()); }
/** * Test case for {@link QueryObjectModelFactory#fullTextSearch(String, String, StaticOperand)} */ public void testFullTextSearchAllProperties() throws RepositoryException { FullTextSearch ftSearch = qf.fullTextSearch( SELECTOR_NAME1, null, qf.literal(vf.createValue(FULLTEXT_SEARCH_EXPR))); assertEquals("Wrong selector name", SELECTOR_NAME1, ftSearch.getSelectorName()); assertNull("Property name must be null", ftSearch.getPropertyName()); }
private QueryObjectModel createQuery(String operator, Value literal) throws RepositoryException { return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.nodeName("s"), operator, qf.literal(literal) ) ), null, null); } }
private QueryObjectModel createQuery(String operator, Value literal) throws RepositoryException { return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.nodeLocalName("s"), operator, qf.literal(literal) ) ), null, null); } }
QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, fac.literal( session.getValueFactory().createValue( origParentFolderPath ) ) ); origNameConstraint = fac.comparison( fac.propertyValue( selectorName, pentahoJcrConstants.getPHO_ORIGNAME() ), QueryObjectModelConstants.JCR_OPERATOR_LIKE, fac.literal( session.getValueFactory().createValue( convertedFilter ) ) );
public void testOrdering() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.fullTextSearch("s", null, qf.literal(vf.createValue("fox"))), qf.descendantNode("s", testRootNode.getPath()) ), new Ordering[]{qf.ascending(qf.fullTextSearchScore("s"))}, null ); forQOMandSQL2(qom, new Callable() { public Object call(Query query) throws RepositoryException { RowIterator rows = query.execute().getRows(); double previousScore = Double.NaN; while (rows.hasNext()) { double score = rows.nextRow().getScore("s"); if (!Double.isNaN(previousScore)) { assertTrue("wrong order", previousScore <= score); } previousScore = score; } return null; } }); }
/** * Test case for {@link QueryObjectModelFactory#fullTextSearch(String, String, StaticOperand)} */ public void testFullTextSearch() throws RepositoryException { FullTextSearch ftSearch = qf.fullTextSearch( SELECTOR_NAME1, propertyName1, qf.literal(vf.createValue(FULLTEXT_SEARCH_EXPR))); assertEquals("Wrong selector name", SELECTOR_NAME1, ftSearch.getSelectorName()); assertEquals("Wrong propertyName", propertyName1, ftSearch.getPropertyName()); StaticOperand op = ftSearch.getFullTextSearchExpression(); assertNotNull(op); assertTrue("not a Literal", op instanceof Literal); Literal literal = (Literal) op; assertEquals(FULLTEXT_SEARCH_EXPR, literal.getLiteralValue().getString()); }
private QueryObjectModel createQuery(DynamicOperand operand, boolean toUpper, String operator, Value literal) throws RepositoryException { if (toUpper) { operand = qf.upperCase(operand); } else { operand = qf.lowerCase(operand); } return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( operand, operator, qf.literal(literal) ) ), null, null); } }
@Test public void fullTextSearch() throws RepositoryException { Literal l = f.literal(vf.createValue(1)); FullTextSearch x = f.fullTextSearch("selectorName", "propertyName", l); assertEquals("selectorName", x.getSelectorName()); assertEquals("propertyName", x.getPropertyName()); assertEquals(l, x.getFullTextSearchExpression()); assertEquals("CONTAINS([selectorName].[propertyName], 1)", x.toString()); assertEquals("CONTAINS([p], null)", f.fullTextSearch(null, "p", null).toString()); assertEquals("CONTAINS([s].[p], null)", f.fullTextSearch("s", "p", null).toString()); assertEquals("CONTAINS([s].*, null)", f.fullTextSearch("s", null, null).toString()); assertEquals("CONTAINS(*, null)", f.fullTextSearch(null, null, null).toString()); }
private QueryResult[] executeQueries(String propertyName, String operator, Value length) throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.length( qf.propertyValue( "s", propertyName)), operator, qf.literal(length)) ), null, null); QueryResult[] results = new QueryResult[2]; results[0] = qom.execute(); results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(); return results; } }
@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()); }
@Test public void comparison() throws RepositoryException { PropertyValue p = f.propertyValue("selectorName", "propertyName"); Literal l = f.literal(vf.createValue(1)); Comparison c = f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, l); assertEquals(p, c.getOperand1()); assertEquals(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, c.getOperator()); assertEquals(l, c.getOperand2()); assertEquals("[selectorName].[propertyName] = 1", c.toString()); }