use of org.apache.jackrabbit.spi.commons.name.PathBuilder in project jackrabbit by apache.
the class OrderQueryNode method createPath.
//--------------------------------< internal >------------------------------
/**
* Creates a path with a single element out of the given <code>name</code>.
*
* @param name the name to create the path from.
* @return a path with a single element.
*/
private static Path createPath(Name name) {
try {
PathBuilder builder = new PathBuilder();
builder.addLast(name);
return builder.getPath();
} catch (MalformedPathException e) {
// never happens, we just added an element
throw new InternalError();
}
}
use of org.apache.jackrabbit.spi.commons.name.PathBuilder in project jackrabbit by apache.
the class JCRSQLQueryBuilder method createRelationQueryNode.
//------------------------< internal >--------------------------------------
/**
* Creates a new {@link org.apache.jackrabbit.spi.commons.query.RelationQueryNode}.
*
* @param parent the parent node for the created <code>RelationQueryNode</code>.
* @param propertyName the property name for the relation.
* @param operationType the operation type.
* @param literal the literal value for the relation or
* <code>null</code> if the relation does not have a
* literal (e.g. IS NULL).
* @return a <code>RelationQueryNode</code>.
* @throws IllegalArgumentException if the literal value does not conform
* to its type. E.g. a malformed String representation of a date.
*/
private RelationQueryNode createRelationQueryNode(QueryNode parent, Name propertyName, int operationType, ASTLiteral literal) throws IllegalArgumentException {
RelationQueryNode node = null;
try {
Path relPath = null;
if (propertyName != null) {
PathBuilder builder = new PathBuilder();
builder.addLast(propertyName);
relPath = builder.getPath();
}
if (literal == null) {
node = factory.createRelationQueryNode(parent, operationType);
node.setRelativePath(relPath);
} else if (literal.getType() == QueryConstants.TYPE_DATE) {
SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
Date date = format.parse(literal.getValue());
node = factory.createRelationQueryNode(parent, operationType);
node.setRelativePath(relPath);
node.setDateValue(date);
} else if (literal.getType() == QueryConstants.TYPE_DOUBLE) {
double d = Double.parseDouble(literal.getValue());
node = factory.createRelationQueryNode(parent, operationType);
node.setRelativePath(relPath);
node.setDoubleValue(d);
} else if (literal.getType() == QueryConstants.TYPE_LONG) {
long l = Long.parseLong(literal.getValue());
node = factory.createRelationQueryNode(parent, operationType);
node.setRelativePath(relPath);
node.setLongValue(l);
} else if (literal.getType() == QueryConstants.TYPE_STRING) {
node = factory.createRelationQueryNode(parent, operationType);
node.setRelativePath(relPath);
node.setStringValue(literal.getValue());
} else if (literal.getType() == QueryConstants.TYPE_TIMESTAMP) {
Calendar c = ISO8601.parse(literal.getValue());
node = factory.createRelationQueryNode(parent, operationType);
node.setRelativePath(relPath);
node.setDateValue(c.getTime());
}
} catch (java.text.ParseException e) {
throw new IllegalArgumentException(e.toString());
} catch (NumberFormatException e) {
throw new IllegalArgumentException(e.toString());
} catch (MalformedPathException e) {
// path is always valid, but throw anyway
throw new IllegalArgumentException(e.getMessage());
}
if (node == null) {
throw new IllegalArgumentException("Unknown type for literal: " + literal.getType());
}
return node;
}
use of org.apache.jackrabbit.spi.commons.name.PathBuilder in project jackrabbit by apache.
the class TextsearchQueryNode method setPropertyName.
/**
* Sets a new name as the search scope for this fulltext query.
*
* @param property the name of the property.
* @deprecated Use {@link #setRelativePath(Path)} instead.
*/
public void setPropertyName(Name property) {
PathBuilder builder = new PathBuilder();
builder.addLast(property);
try {
this.relPath = builder.getPath();
this.propertyRef = true;
} catch (MalformedPathException e) {
// path is always valid
}
}
Aggregations