@Override public QueryCommand getLeft() { return query().getLeft(); }
@Override public QueryCommand getLeft() { return query().getLeft(); }
@Override public void visit( SetQuery setQuery ) { strategy.visit(setQuery); enqueue(setQuery.getLeft()); enqueue(setQuery.getRight()); visitNext(); }
@Override public void visit( SetQuery setQuery ) { strategy.visit(setQuery); enqueue(setQuery.getLeft()); enqueue(setQuery.getRight()); visitNext(); }
/** * Return a {@link QueryCommand} representing the currently-built query. * * @return the resulting query command; never null * @see #clear() */ public QueryCommand query() { QueryCommand result = new Query(source, constraint, orderings, columns, limit, distinct); if (this.firstQuery != null) { // EXCEPT has a higher precedence than INTERSECT or UNION, so if the first query is // an INTERSECT or UNION SetQuery, the result should be applied to the RHS of the previous set ... if (firstQuery instanceof SetQuery && firstQuerySetOperation == Operation.EXCEPT) { SetQuery setQuery = (SetQuery)firstQuery; QueryCommand left = setQuery.getLeft(); QueryCommand right = setQuery.getRight(); SetQuery exceptQuery = new SetQuery(right, Operation.EXCEPT, result, firstQueryAll); result = new SetQuery(left, setQuery.operation(), exceptQuery, setQuery.isAll()); } else { result = new SetQuery(this.firstQuery, this.firstQuerySetOperation, result, this.firstQueryAll); } } return result; }
/** * Return a {@link QueryCommand} representing the currently-built query. * * @return the resulting query command; never null * @see #clear() */ public QueryCommand query() { QueryCommand result = new Query(source, constraint, orderings, columns, limit, distinct); if (this.firstQuery != null) { // EXCEPT has a higher precedence than INTERSECT or UNION, so if the first query is // an INTERSECT or UNION SetQuery, the result should be applied to the RHS of the previous set ... if (firstQuery instanceof SetQuery && firstQuerySetOperation == Operation.EXCEPT) { SetQuery setQuery = (SetQuery)firstQuery; QueryCommand left = setQuery.getLeft(); QueryCommand right = setQuery.getRight(); SetQuery exceptQuery = new SetQuery(right, Operation.EXCEPT, result, firstQueryAll); result = new SetQuery(left, setQuery.operation(), exceptQuery, setQuery.isAll()); } else { result = new SetQuery(this.firstQuery, this.firstQuerySetOperation, result, this.firstQueryAll); } } return result; }
@Override public void visit( SetQuery query ) { query.getLeft().accept(this); append(' ').append(query.operation().getSymbol()).append(' '); if (query.isAll()) append("ALL "); query.getRight().accept(this); }
@Override public void visit( SetQuery query ) { query.getLeft().accept(this); append(' ').append(query.operation().getSymbol()).append(' '); if (query.isAll()) append("ALL "); query.getRight().accept(this); }
/** * Create a canonical query plan for the given set query. * * @param context the context in which the query is being planned * @param query the set query to be planned * @return the root node of the plan tree representing the canonical plan */ protected PlanNode createCanonicalPlan( QueryContext context, SetQuery query ) { // Process the left and right parts of the query ... PlanNode left = createPlan(context, query.getLeft()); PlanNode right = createPlan(context, query.getRight()); // Wrap in a set operation node ... PlanNode plan = new PlanNode(Type.SET_OPERATION); plan.addChildren(left, right); plan.setProperty(Property.SET_OPERATION, query.operation()); plan.setProperty(Property.SET_USE_ALL, query.isAll()); // Process the orderings and limits ... plan = attachSorting(context, plan, query.orderings()); plan = attachLimits(context, plan, query.getLimits()); // Capture if we're limiting the results to 1 row and no offset and no sorting ... if (query.getLimits().isLimitedToSingleRowWithNoOffset() && query.orderings().isEmpty()) { context.getHints().isExistsQuery = true; } return plan; }
/** * Create a canonical query plan for the given set query. * * @param context the context in which the query is being planned * @param query the set query to be planned * @return the root node of the plan tree representing the canonical plan */ protected PlanNode createCanonicalPlan( QueryContext context, SetQuery query ) { // Process the left and right parts of the query ... PlanNode left = createPlan(context, query.getLeft()); PlanNode right = createPlan(context, query.getRight()); // Wrap in a set operation node ... PlanNode plan = new PlanNode(Type.SET_OPERATION); plan.addChildren(left, right); plan.setProperty(Property.SET_OPERATION, query.operation()); plan.setProperty(Property.SET_USE_ALL, query.isAll()); // Process the orderings and limits ... plan = attachSorting(context, plan, query.orderings()); plan = attachLimits(context, plan, query.getLimits()); // Capture if we're limiting the results to 1 row and no offset and no sorting ... if (query.getLimits().isLimitedToSingleRowWithNoOffset() && query.orderings().isEmpty()) { context.getHints().isExistsQuery = true; } return plan; }