use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.
the class NodeLocalNameTest method testStringLiteralInvalidName.
public void testStringLiteralInvalidName() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue("[" + nodeLocalName);
try {
createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
fail("NodeName comparison with STRING that cannot be converted to NAME must fail with InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.
the class Parser method getSyntaxError.
private InvalidQueryException getSyntaxError(String expected) {
int index = Math.min(parseIndex, statement.length() - 1);
String query = statement.substring(0, index) + "(*)" + statement.substring(index).trim();
if (expected != null) {
query += "; expected: " + expected;
}
return new InvalidQueryException("Query:\n" + query);
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.
the class Parser method readDecimal.
private void readDecimal(int start, int i) throws RepositoryException {
char[] chars = statementChars;
int[] types = characterTypes;
while (true) {
int t = types[i];
if (t != CHAR_DECIMAL && t != CHAR_VALUE) {
break;
}
i++;
}
if (chars[i] == 'E' || chars[i] == 'e') {
i++;
if (chars[i] == '+' || chars[i] == '-') {
i++;
}
if (types[i] != CHAR_VALUE) {
throw getSyntaxError();
}
do {
// go until the first non-number
i++;
} while (types[i] == CHAR_VALUE);
}
parseIndex = i;
String sub = statement.substring(start, i);
BigDecimal bd;
try {
bd = new BigDecimal(sub);
} catch (NumberFormatException e) {
throw new InvalidQueryException("Data conversion error converting " + sub + " to BigDecimal: " + e);
}
checkLiterals(false);
currentValue = valueFactory.createValue(bd);
currentTokenType = VALUE;
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.
the class ParserTest method fuzz.
public void fuzz(String query) throws Exception {
for (int i = 0; i < 100; i++) {
StringBuffer buff = new StringBuffer(query);
int changes = 1 + (int) Math.abs(random.nextGaussian() * 2);
for (int j = 0; j < changes; j++) {
char newChar;
if (random.nextBoolean()) {
String s = "<>_.+\"*%&/()=?[]{}_:;,.-1234567890.qersdf";
newChar = s.charAt(random.nextInt(s.length()));
} else {
newChar = (char) random.nextInt(255);
}
int pos = random.nextInt(buff.length());
if (random.nextBoolean()) {
// 50%: change one character
buff.setCharAt(pos, newChar);
} else {
if (random.nextBoolean()) {
// 25%: delete one character
buff.deleteCharAt(pos);
} else {
// 25%: insert one character
buff.insert(pos, newChar);
}
}
}
String q = buff.toString();
try {
parser.createQueryObjectModel(q);
} catch (ValueFormatException e) {
// OK
} catch (InvalidQueryException e) {
// OK
} catch (NamespaceException e) {
// OK?
} catch (Throwable t) {
t.printStackTrace();
assertTrue("Unexpected exception for query " + q + ": " + t, false);
}
}
}
use of javax.jcr.query.InvalidQueryException in project jackrabbit by apache.
the class LuceneQueryFactory method mapConstraintToQueryAndFilter.
protected Predicate mapConstraintToQueryAndFilter(QueryPair query, Constraint constraint, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher, IndexReader reader) throws RepositoryException, IOException {
Predicate filter = Predicate.TRUE;
if (constraint instanceof And) {
And and = (And) constraint;
filter = mapConstraintToQueryAndFilter(query, and.getConstraint1(), selectorMap, searcher, reader);
Predicate other = mapConstraintToQueryAndFilter(query, and.getConstraint2(), selectorMap, searcher, reader);
if (filter == Predicate.TRUE) {
filter = other;
} else if (other != Predicate.TRUE) {
filter = Predicates.and(filter, other);
}
} else if (constraint instanceof Comparison) {
Comparison c = (Comparison) constraint;
Transform transform = new Transform(c.getOperand1());
DynamicOperand left = transform.operand;
final String operator = c.getOperator();
StaticOperand right = c.getOperand2();
if (left instanceof Length || left instanceof FullTextSearchScore || (((!JCR_OPERATOR_EQUAL_TO.equals(operator) && !JCR_OPERATOR_LIKE.equals(operator)) || transform.transform != TRANSFORM_NONE) && (left instanceof NodeName || left instanceof NodeLocalName))) {
try {
int type = PropertyType.UNDEFINED;
if (left instanceof Length) {
type = PropertyType.LONG;
} else if (left instanceof FullTextSearchScore) {
type = PropertyType.DOUBLE;
}
final DynamicOperand operand = c.getOperand1();
final Value value = evaluator.getValue(right, type);
filter = new RowPredicate() {
@Override
protected boolean evaluate(Row row) throws RepositoryException {
return new ValueComparator().evaluate(operator, evaluator.getValue(operand, row), value);
}
};
} catch (ValueFormatException e) {
throw new InvalidQueryException(e);
}
} else {
Query cq = getComparisonQuery(left, transform.transform, operator, right, selectorMap);
query.subQuery.add(cq, MUST);
}
} else if (constraint instanceof DescendantNode) {
final DescendantNode descendantNode = (DescendantNode) constraint;
Query context = getNodeIdQuery(UUID, descendantNode.getAncestorPath());
query.mainQuery = new DescendantSelfAxisQuery(context, query.subQuery, false);
} else {
query.subQuery.add(create(constraint, selectorMap, searcher), MUST);
}
return filter;
}
Aggregations