use of org.apache.jena.arq.querybuilder.clauses.SelectClause in project jena by apache.
the class WhereHandler method addUnion.
/**
* Add a union to the where clause.
*
* @param subQuery The subquery to add as the union.
*/
public void addUnion(AbstractQueryBuilder<?> subQuery) {
ElementUnion union = null;
ElementGroup clause = getClause();
// if the last element is a union make sure we add to it.
if (!clause.isEmpty()) {
Element lastElement = clause.getElements().get(clause.getElements().size() - 1);
if (lastElement instanceof ElementUnion) {
union = (ElementUnion) lastElement;
} else {
// clauses is not empty and is not a union so it is the left
// side of the union.
union = new ElementUnion();
union.addElement(clause);
query.setQueryPattern(union);
}
} else {
// add the union as the first element in the clause.
union = new ElementUnion();
clause.addElement(union);
}
// otherwise just add the clause.
if (subQuery instanceof SelectClause && ((SelectClause<?>) subQuery).getVars().size() > 0) {
union.addElement(makeSubQuery(subQuery));
} else {
PrologHandler ph = new PrologHandler(query);
ph.addPrefixes(subQuery.getPrologHandler().getPrefixes());
union.addElement(subQuery.getWhereHandler().getClause());
}
}
use of org.apache.jena.arq.querybuilder.clauses.SelectClause in project jena by apache.
the class WhereQuadHolder method addUnion.
/**
* Add a union to the where clause.
*
* @param subQuery The subquery to add as the union.
*/
public void addUnion(AbstractQueryBuilder<?> subQuery) {
ElementUnion union = null;
ElementGroup clause = getClause();
// if the last element is a union make sure we add to it.
if (!clause.isEmpty()) {
Element lastElement = clause.getElements().get(clause.getElements().size() - 1);
if (lastElement instanceof ElementUnion) {
union = (ElementUnion) lastElement;
} else {
// clauses is not empty and is not a union so it is the left
// side of the union.
union = new ElementUnion();
union.addElement(clause);
whereClause = union;
}
} else {
// add the union as the first element in the clause.
union = new ElementUnion();
clause.addElement(union);
}
// otherwise just add the clause.
if (subQuery instanceof SelectClause && ((SelectClause<?>) subQuery).getVars().size() > 0) {
union.addElement(subQuery.asSubQuery());
} else {
prefixHandler.addPrefixes(subQuery.getPrologHandler().getPrefixes());
union.addElement(subQuery.getWhereHandler().getClause());
}
}
Aggregations