public Object visit(RelationQueryNode node, Object data) throws RepositoryException { StringBuffer buffer = (StringBuffer) data; buffer.append(PADDING, 0, indent); buffer.append("+ RelationQueryNode: Op: "); buffer.append(QueryConstants.OPERATION_NAMES.getName(node.getOperation())); buffer.append(" Prop=["); PathQueryNode relPath = node.getRelativePath(); if (relPath == null) { buffer.append(relPath); } else { visit(relPath, buffer); } buffer.append("] Type=").append(QueryConstants.TYPE_NAMES.getName(node.getValueType())); if (node.getValueType() == QueryConstants.TYPE_DATE) { buffer.append(" Value=").append(node.getDateValue()); } else if (node.getValueType() == QueryConstants.TYPE_DOUBLE) { buffer.append(" Value=").append(node.getDoubleValue()); } else if (node.getValueType() == QueryConstants.TYPE_LONG) { buffer.append(" Value=").append(node.getLongValue()); } else if (node.getValueType() == QueryConstants.TYPE_POSITION) { buffer.append(" Value=").append(node.getPositionValue()); } else if (node.getValueType() == QueryConstants.TYPE_STRING) { buffer.append(" Value=").append(node.getStringValue()); } else if (node.getValueType() == QueryConstants.TYPE_TIMESTAMP) { buffer.append(" Value=").append(node.getDateValue()); } buffer.append("\n"); traverse(node.getOperands(), buffer); return buffer; }
/** * {@inheritDoc} */ public RelationQueryNode createRelationQueryNode(QueryNode parent, int operation) { return new RelationQueryNode(parent, operation, this); }
private void appendValue(RelationQueryNode node, StringBuffer b) { if (node.getValueType() == TYPE_LONG) { b.append(node.getLongValue()); } else if (node.getValueType() == TYPE_DOUBLE) { b.append(node.getDoubleValue()); } else if (node.getValueType() == TYPE_STRING) { b.append("'").append(node.getStringValue().replaceAll("'", "''")).append("'"); } else if (node.getValueType() == TYPE_DATE || node.getValueType() == TYPE_TIMESTAMP) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTime(node.getDateValue()); b.append("TIMESTAMP '").append(ISO8601.format(cal)).append("'"); } else { exceptions.add(new InvalidQueryException("Invalid type: " + node.getValueType())); } }
public Object visit(ASTUpperFunction node, Object data) { RelationQueryNode parent = (RelationQueryNode) data; if (parent.getValueType() != QueryConstants.TYPE_STRING) { String msg = "UPPER() function is only supported for String literal"; throw new IllegalArgumentException(msg); } parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.UPPER_CASE)); return parent; }
public Object visit(RelationQueryNode node, Object data) throws RepositoryException { PathQueryNode relPath = node.getRelativePath(); if (relPath == null && node.getOperation() != QueryConstants.OPERATION_SIMILAR && node.getOperation() != QueryConstants.OPERATION_SPELLCHECK) { exceptions.add(new InvalidQueryException("@* not supported in predicate")); return data; if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) { switch (node.getValueType()) { case 0: stringValues[0] = DateField.dateToString(node.getDateValue()); break; case QueryConstants.TYPE_DOUBLE: stringValues[0] = DoubleField.doubleToString(node.getDoubleValue()); break; case QueryConstants.TYPE_LONG: stringValues[0] = LongField.longToString(node.getLongValue()); break; case QueryConstants.TYPE_STRING: if (node.getOperation() == QueryConstants.OPERATION_EQ_GENERAL || node.getOperation() == QueryConstants.OPERATION_EQ_VALUE || node.getOperation() == QueryConstants.OPERATION_NE_GENERAL || node.getOperation() == QueryConstants.OPERATION_NE_VALUE) { stringValues = getStringValues(propertyName, node.getStringValue()); } else { stringValues[0] = node.getStringValue();
exceptions.add(new InvalidQueryException("Unable to parse string literal for xs:dateTime: " + value)); } else { rel.setDateValue(c.getTime()); if (like.getRelativePath() == null) { exceptions.add(new InvalidQueryException("Wrong first argument type for jcr:like")); like.setStringValue(unescapeQuotes(literal.getValue())); } else { exceptions.add(new InvalidQueryException("Wrong second argument type for jcr:like")); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode rel = (RelationQueryNode) queryNode; rel.setStringValue("true"); } else { exceptions.add(new InvalidQueryException("Unsupported location for true()")); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode rel = (RelationQueryNode) queryNode; rel.setStringValue("false"); } else { exceptions.add(new InvalidQueryException("Unsupported location for false()")); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode rel = (RelationQueryNode) queryNode; if (rel.getOperation() == RelationQueryNode.OPERATION_EQ_GENERAL) { rel.setPositionValue(1); rel.addPathElement(PATH_FACTORY.createElement(FN_POSITION_FULL));
try { StringBuffer propName = new StringBuffer(); PathQueryNode relPath = node.getRelativePath(); if (relPath == null) { propName.append("."); node.acceptOperands(this, propName); if (node.getOperation() == OPERATION_EQ_VALUE || node.getOperation() == OPERATION_EQ_GENERAL) { sb.append(propName); sb.append(" = "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GE_VALUE || node.getOperation() == OPERATION_GE_GENERAL) { sb.append(propName); sb.append(" >= "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GT_VALUE || node.getOperation() == OPERATION_GT_GENERAL) { sb.append(propName); sb.append(" > "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LE_VALUE || node.getOperation() == OPERATION_LE_GENERAL) { sb.append(propName); sb.append(" <= "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LIKE) { sb.append(propName); sb.append(" LIKE "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LT_VALUE || node.getOperation() == OPERATION_LT_GENERAL) {
/** * Assigns a value to the <code>queryNode</code>. * * @param node must be of type string, decimal, double or integer; otherwise * an InvalidQueryException is added to {@link #exceptions}. * @param queryNode current node in the query tree. */ private void assignValue(SimpleNode node, RelationQueryNode queryNode) { if (node.getId() == JJTSTRINGLITERAL) { queryNode.setStringValue(unescapeQuotes(node.getValue())); } else if (node.getId() == JJTDECIMALLITERAL) { queryNode.setDoubleValue(Double.parseDouble(node.getValue())); } else if (node.getId() == JJTDOUBLELITERAL) { queryNode.setDoubleValue(Double.parseDouble(node.getValue())); } else if (node.getId() == JJTINTEGERLITERAL) { // if this is an expression that contains position() do not change // the type. if (queryNode.getValueType() == QueryConstants.TYPE_POSITION) { queryNode.setPositionValue(Integer.parseInt(node.getValue())); } else { queryNode.setLongValue(Long.parseLong(node.getValue())); } } else { exceptions.add(new InvalidQueryException("Unsupported literal type:" + node.toString())); } }
PathQueryNode relPath = node.getRelativePath(); if (relPath == null) { propPath.append("."); propPath.append(slash); slash = "/"; if (i == steps.length - 1 && node.getOperation() != OPERATION_SIMILAR) { node.acceptOperands(this, propPath); if (node.getOperation() == OPERATION_EQ_VALUE) { sb.append(propPath).append(" eq "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_EQ_GENERAL) { sb.append(propPath).append(" = "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GE_GENERAL) { sb.append(propPath).append(" >= "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GE_VALUE) { sb.append(propPath).append(" ge "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GT_GENERAL) { sb.append(propPath).append(" > "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GT_VALUE) { sb.append(propPath).append(" gt "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LE_GENERAL) {
if (aPred.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode pos = (RelationQueryNode) aPred; if (pos.getValueType() == QueryConstants.TYPE_POSITION) { node.setIndex(pos.getPositionValue());
tmpRelPath = new PathBuilder(); PathQueryNode relPath = tmp.getRelativePath(); LocationStepQueryNode[] steps = relPath.getPathSteps(); case JJTUNARYMINUS: if (queryNode.getType() == QueryNode.TYPE_RELATION) { ((RelationQueryNode) queryNode).setUnaryMinus(true); } else { exceptions.add(new InvalidQueryException("Parse error: data is not a RelationQueryNode")); ((LocationStepQueryNode) queryNode).setNameTest(PATH_FACTORY.getParentElement().getName()); } else { ((RelationQueryNode) queryNode).addPathElement(PATH_FACTORY.getParentElement());
public Object visit(PropertyFunctionQueryNode node, Object data) { String functionName = node.getFunctionName(); if ((functionName.equals(PropertyFunctionQueryNode.LOWER_CASE) || functionName.equals(PropertyFunctionQueryNode.UPPER_CASE)) && rqn.getValueType() != QueryConstants.TYPE_STRING) { String msg = "Upper and lower case function are only supported with String literals"; exceptions.add(new InvalidQueryException(msg)); } return data; } }, null);
rqn.acceptOperands(new DefaultQueryNodeVisitor() { public Object visit(PropertyFunctionQueryNode node, Object data) { String functionName = node.getFunctionName();
private void appendValue(RelationQueryNode node, StringBuffer b) { if (node.getValueType() == TYPE_LONG) { b.append(node.getLongValue()); } else if (node.getValueType() == TYPE_DOUBLE) { b.append(node.getDoubleValue()); } else if (node.getValueType() == TYPE_STRING) { b.append("'").append(node.getStringValue().replaceAll("'", "''")).append("'"); } else if (node.getValueType() == TYPE_DATE || node.getValueType() == TYPE_TIMESTAMP) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTime(node.getDateValue()); b.append("TIMESTAMP '").append(ISO8601.format(cal)).append("'"); } else { exceptions.add(new InvalidQueryException("Invalid type: " + node.getValueType())); } }
public Object visit(RelationQueryNode node, Object data) throws RepositoryException { PathQueryNode relPath = node.getRelativePath(); if (relPath == null && node.getOperation() != QueryConstants.OPERATION_SIMILAR && node.getOperation() != QueryConstants.OPERATION_SPELLCHECK) { exceptions.add(new InvalidQueryException("@* not supported in predicate")); return data; if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) { switch (node.getValueType()) { case 0: stringValues[0] = DateField.dateToString(node.getDateValue()); break; case QueryConstants.TYPE_DOUBLE: stringValues[0] = DoubleField.doubleToString(node.getDoubleValue()); break; case QueryConstants.TYPE_LONG: stringValues[0] = LongField.longToString(node.getLongValue()); break; case QueryConstants.TYPE_STRING: if (node.getOperation() == QueryConstants.OPERATION_EQ_GENERAL || node.getOperation() == QueryConstants.OPERATION_EQ_VALUE || node.getOperation() == QueryConstants.OPERATION_NE_GENERAL || node.getOperation() == QueryConstants.OPERATION_NE_VALUE) { stringValues = getStringValues(propertyName, node.getStringValue()); } else { stringValues[0] = node.getStringValue();
exceptions.add(new InvalidQueryException("Unable to parse string literal for xs:dateTime: " + value)); } else { rel.setDateValue(c.getTime()); if (like.getRelativePath() == null) { exceptions.add(new InvalidQueryException("Wrong first argument type for jcr:like")); like.setStringValue(unescapeQuotes(literal.getValue())); } else { exceptions.add(new InvalidQueryException("Wrong second argument type for jcr:like")); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode rel = (RelationQueryNode) queryNode; rel.setStringValue("true"); } else { exceptions.add(new InvalidQueryException("Unsupported location for true()")); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode rel = (RelationQueryNode) queryNode; rel.setStringValue("false"); } else { exceptions.add(new InvalidQueryException("Unsupported location for false()")); if (queryNode.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode rel = (RelationQueryNode) queryNode; if (rel.getOperation() == RelationQueryNode.OPERATION_EQ_GENERAL) { rel.setPositionValue(1); rel.addPathElement(PATH_FACTORY.createElement(FN_POSITION_FULL));
try { StringBuffer propName = new StringBuffer(); PathQueryNode relPath = node.getRelativePath(); if (relPath == null) { propName.append("."); node.acceptOperands(this, propName); if (node.getOperation() == OPERATION_EQ_VALUE || node.getOperation() == OPERATION_EQ_GENERAL) { sb.append(propName); sb.append(" = "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GE_VALUE || node.getOperation() == OPERATION_GE_GENERAL) { sb.append(propName); sb.append(" >= "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GT_VALUE || node.getOperation() == OPERATION_GT_GENERAL) { sb.append(propName); sb.append(" > "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LE_VALUE || node.getOperation() == OPERATION_LE_GENERAL) { sb.append(propName); sb.append(" <= "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LIKE) { sb.append(propName); sb.append(" LIKE "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LT_VALUE || node.getOperation() == OPERATION_LT_GENERAL) {
/** * Assigns a value to the <code>queryNode</code>. * * @param node must be of type string, decimal, double or integer; otherwise * an InvalidQueryException is added to {@link #exceptions}. * @param queryNode current node in the query tree. */ private void assignValue(SimpleNode node, RelationQueryNode queryNode) { if (node.getId() == JJTSTRINGLITERAL) { queryNode.setStringValue(unescapeQuotes(node.getValue())); } else if (node.getId() == JJTDECIMALLITERAL) { queryNode.setDoubleValue(Double.parseDouble(node.getValue())); } else if (node.getId() == JJTDOUBLELITERAL) { queryNode.setDoubleValue(Double.parseDouble(node.getValue())); } else if (node.getId() == JJTINTEGERLITERAL) { // if this is an expression that contains position() do not change // the type. if (queryNode.getValueType() == QueryConstants.TYPE_POSITION) { queryNode.setPositionValue(Integer.parseInt(node.getValue())); } else { queryNode.setLongValue(Long.parseLong(node.getValue())); } } else { exceptions.add(new InvalidQueryException("Unsupported literal type:" + node.toString())); } }
PathQueryNode relPath = node.getRelativePath(); if (relPath == null) { propPath.append("."); propPath.append(slash); slash = "/"; if (i == steps.length - 1 && node.getOperation() != OPERATION_SIMILAR) { node.acceptOperands(this, propPath); if (node.getOperation() == OPERATION_EQ_VALUE) { sb.append(propPath).append(" eq "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_EQ_GENERAL) { sb.append(propPath).append(" = "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GE_GENERAL) { sb.append(propPath).append(" >= "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GE_VALUE) { sb.append(propPath).append(" ge "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GT_GENERAL) { sb.append(propPath).append(" > "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_GT_VALUE) { sb.append(propPath).append(" gt "); appendValue(node, sb); } else if (node.getOperation() == OPERATION_LE_GENERAL) {
public Object visit(ASTUpperFunction node, Object data) { RelationQueryNode parent = (RelationQueryNode) data; if (parent.getValueType() != QueryConstants.TYPE_STRING) { String msg = "UPPER() function is only supported for String literal"; throw new IllegalArgumentException(msg); } parent.addOperand(factory.createPropertyFunctionQueryNode(parent, PropertyFunctionQueryNode.UPPER_CASE)); return parent; }