use of org.eclipse.rdf4j.query.algebra.UnaryTupleOperator in project rdf4j by eclipse.
the class AbstractQueryBuilder method query.
/**
* @inheritDoc
*/
public T query() {
UnaryTupleOperator aRoot = null;
UnaryTupleOperator aCurr = null;
if (mLimit != -1 || mOffset != -1) {
Slice aSlice = new Slice();
if (mLimit != -1) {
aSlice.setLimit(mLimit);
}
if (mOffset != -1) {
aSlice.setOffset(mOffset);
}
aRoot = aCurr = aSlice;
}
if (mOrderByElems != null && !mOrderByElems.isEmpty()) {
Order aOrder = new Order();
aOrder.addElements(mOrderByElems);
if (aRoot == null) {
aRoot = aCurr = aOrder;
} else {
aCurr.setArg(aOrder);
aCurr = aOrder;
}
}
if (mDistinct) {
Distinct aDistinct = new Distinct();
if (aRoot == null) {
aRoot = aCurr = aDistinct;
} else {
aCurr.setArg(aDistinct);
aCurr = aDistinct;
}
}
if (mReduced) {
Reduced aReduced = new Reduced();
if (aRoot == null) {
aRoot = aCurr = aReduced;
} else {
aCurr.setArg(aReduced);
aCurr = aReduced;
}
}
TupleExpr aJoin = join();
if (mQuery instanceof ParsedTupleQuery && mProjectionVars.isEmpty()) {
VarNameCollector aCollector = new VarNameCollector();
aJoin.visit(aCollector);
mProjectionVars.addAll(aCollector.getVarNames());
} else if (mQuery instanceof ParsedGraphQuery && mProjectionPatterns.isEmpty()) {
StatementPatternCollector aCollector = new StatementPatternCollector();
aJoin.visit(aCollector);
mProjectionPatterns.addAll(aCollector.getStatementPatterns());
}
UnaryTupleOperator aProjection = projection();
if (aRoot == null) {
aRoot = aCurr = aProjection;
} else {
aCurr.setArg(aProjection);
}
if (aProjection.getArg() == null) {
aCurr = aProjection;
} else {
// I think this is always a safe cast
aCurr = (UnaryTupleOperator) aProjection.getArg();
}
if (aJoin != null) {
aCurr.setArg(aJoin);
}
mQuery.setTupleExpr(aRoot);
if (!mFrom.isEmpty() || !mFromNamed.isEmpty()) {
SimpleDataset aDataset = new SimpleDataset();
for (IRI aFrom : mFrom) {
aDataset.addDefaultGraph(aFrom);
}
for (IRI aFrom : mFromNamed) {
aDataset.addNamedGraph(aFrom);
}
mQuery.setDataset(aDataset);
}
return mQuery;
}
Aggregations