Search in sources :

Example 1 with SelectClause

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());
    }
}
Also used : SelectClause(org.apache.jena.arq.querybuilder.clauses.SelectClause) ElementUnion(org.apache.jena.sparql.syntax.ElementUnion) Element(org.apache.jena.sparql.syntax.Element) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 2 with SelectClause

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());
    }
}
Also used : SelectClause(org.apache.jena.arq.querybuilder.clauses.SelectClause) ElementUnion(org.apache.jena.sparql.syntax.ElementUnion) Element(org.apache.jena.sparql.syntax.Element) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Aggregations

SelectClause (org.apache.jena.arq.querybuilder.clauses.SelectClause)2 Element (org.apache.jena.sparql.syntax.Element)2 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)2 ElementUnion (org.apache.jena.sparql.syntax.ElementUnion)2