protected QueryBuilder createJoin(JoinCondition condition) { // Otherwise, just create using usual precedence ... source = new Join(source, type, rightSource, condition); return QueryBuilder.this; } }
@Override public void visit(Selector selector) { if (notFound.get() && selector.getAliasOrName().equals(name)) { notFound.set(false); } } });
/** * {@inheritDoc} * @throws VisitException if exception occurs * * @see QueryObjectModelVisitor#visit(Join) */ public void visit(Join join) throws VisitException { join.getLeft().accept(this); // if (join.getType() != JoinType.INNER) { sb.append(' ').append(join.getType().getSymbol()); // } else { // sb.append(','); // } append(' '); join.getRight().accept(this); append(" ON "); join.getJoinCondition().accept(this); }
/** * @see org.xcmis.search.Visitors.AbstractModelVisitor#visit(org.xcmis.search.model.source.Join) */ @Override public void visit(Join node) throws VisitException { JoinExecutionPlan joinPlan = new JoinExecutionPlan(); joinPlan.setJoinType(node.getType()); joinPlan.setJoinAlgorithm(JoinAlgorithm.NESTED_LOOP); joinPlan.setJoinCondition(node.getJoinCondition()); //left plan node.getLeft().accept(this); joinPlan.setLeftPlan((SourceExecutionPlan)stepsStack.pop()); //right plan node.getRight().accept(this); joinPlan.setRightPlan((SourceExecutionPlan)stepsStack.pop()); }
/** * @see org.xcmis.search.Visitors.AbstractModelVisitor#visit(org.xcmis.search.model.source.join.EquiJoinCondition) */ @Override public void visit(EquiJoinCondition node) throws VisitException { checkTableAndColumnExistance(node.getSelector1Name(), node.getProperty1Name(), true); checkTableAndColumnExistance(node.getSelector2Name(), node.getProperty2Name(), true); if (node.getSelector1Name().equals(node.getSelector2Name())) { problems.addException(new InvalidQueryException(node.getSelector1Name() + " is the same as " + node.getSelector2Name())); } }
/** * @see org.xcmis.search.Visitors.AbstractModelVisitor#visit(org.xcmis.search.model.source.join.ChildNodeJoinCondition) */ @Override public void visit(ChildNodeJoinCondition node) throws VisitException { checkSelectorExistance(node.getChildSelectorName()); checkSelectorExistance(node.getParentSelectorName()); if (node.getChildSelectorName().equals(node.getParentSelectorName())) { problems.addException(new InvalidQueryException(node.getChildSelectorName() + " is the same as " + node.getParentSelectorName())); } }
/** * @see org.xcmis.search.Visitors.AbstractModelVisitor#visit(org.xcmis.search.model.source.join.SameNodeJoinCondition) */ @Override public void visit(SameNodeJoinCondition node) throws VisitException { checkSelectorExistance(node.getSelector1Name()); checkSelectorExistance(node.getSelector2Name()); if (node.getSelector1Name().equals(node.getSelector2Name())) { problems.addException(new InvalidQueryException(node.getSelector1Name() + " is the same as " + node.getSelector2Name())); } }
/** * {@inheritDoc} * @throws VisitException if exception occurs * * @see QueryObjectModelVisitor#visit(Join) */ public void visit(Join join) throws VisitException { strategy.visit(join); enqueue(join.getLeft()); enqueue(join.getJoinCondition()); enqueue(join.getRight()); visitNext(); }
/** * Specify the name of the table from which tuples should be selected. The * supplied string is of the form " <code>tableName [AS alias]</code>". * * @param tableNameWithOptionalAlias * the name of the table, optionally including the alias * @return this builder object, for convenience in method chaining */ public QueryBuilder from(String tableNameWithOptionalAlias) { Selector selector = namedSelector(tableNameWithOptionalAlias); SelectorName oldName = this.source instanceof Selector ? ((Selector)source).getName() : null; // Go through the columns and change the selector name to use the new // alias ... for (int i = 0; i != columns.size(); ++i) { Column old = columns.get(i); if (old.getSelectorName().equals(oldName)) { columns.set(i, new Column(selector.getAliasOrName(), old.getPropertyName(), old.getColumnName())); } } this.source = selector; return this; }
/** * Utility method that does all the work of the clear, but with a flag that * defines whether to clear the first query. This method is used by * {@link #clear()} as well as the {@link #union() many} {@link #intersect() * set} {@link #except() operations}. * * @param clearFirstQuery * true if the first query should be cleared, or false if the first * query should be retained * @return this builder object, for convenience in method chaining */ protected QueryBuilder clear(boolean clearFirstQuery) { source = new Selector(new SelectorName("__not:defined__")); constraint = null; columns = new LinkedList<Column>(); orderings = new LinkedList<Ordering>(); limit = Limit.NONE; distinct = false; if (clearFirstQuery) { this.firstQuery = null; } return this; }
/** * Convenience method that creates a selector name object using the supplied * string. * * @param name * the name of the selector; may not be null * @return the selector name; never null */ protected SelectorName selector(String name) { return new SelectorName(name.trim()); }
protected final ReadableVisitor append(SelectorName name) { sb.append(name.getName()); return this; }
/** * Convenience method that creates a {@link Selector} object given a string * that contains the selector name and optionally an alias. The format of the * string parameter is <code>name [AS alias]</code>. Leading and trailing * whitespace are trimmed. * * @param nameWithOptionalAlias * the name and optional alias; may not be null * @return the named selector object; never null */ protected Selector namedSelector(String nameWithOptionalAlias) { String[] parts = nameWithOptionalAlias.split("\\sAS\\s"); if (parts.length == 2) { return new Selector(selector(parts[0]), selector(parts[1])); } return new Selector(selector(parts[0])); }
public final SelectorName qualifier() throws RecognitionException { SelectorName res = null; String i = null; try { // org/xcmis/search/parser/CMISSQLTreeWalker.g:1075:3: ( ^( QUALIFIER i= id ) ) // org/xcmis/search/parser/CMISSQLTreeWalker.g:1076:3: ^( QUALIFIER i= id ) { match(input,QUALIFIER,FOLLOW_QUALIFIER_in_qualifier2524); match(input, Token.DOWN, null); pushFollow(FOLLOW_id_in_qualifier2528); i=id(); state._fsp--; match(input, Token.UP, null); res=new SelectorName(i); } } catch (RecognitionException e) { throw e; } finally { } return res; } // $ANTLR end "qualifier"
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof SelectorName) { SelectorName that = (SelectorName)obj; return this.name.equals(that.getName()); } return false; }
public final SelectorName correlationName() throws RecognitionException { SelectorName res = null; String i = null; try { // org/xcmis/search/parser/CMISSQLTreeWalker.g:1093:3: ( ^( CORRELATION_NAME i= id ) ) // org/xcmis/search/parser/CMISSQLTreeWalker.g:1094:3: ^( CORRELATION_NAME i= id ) { match(input,CORRELATION_NAME,FOLLOW_CORRELATION_NAME_in_correlationName2594); match(input, Token.DOWN, null); pushFollow(FOLLOW_id_in_correlationName2598); i=id(); state._fsp--; match(input, Token.UP, null); res=new SelectorName(i); } } catch (RecognitionException e) { throw e; } finally { } return res; } // $ANTLR end "correlationName"
/** * Check if selector exists in list of selectors. * @param selectorName * @return */ public Table checkSelectorExistance(SelectorName selectorName) { Table table = selectorsByNameOrAlias.get(selectorName); if (table == null) { // Try looking up the table by it's real name (if an alias were used) ... table = selectorsByName.get(selectorName); } if (table == null) { problems.addException(new TableDoesntExistException("Table " + selectorName.getName() + " doesnt exist")); } return table; }
public final SelectorName tableName() throws RecognitionException { SelectorName res = null; String i = null; try { // org/xcmis/search/parser/CMISSQLTreeWalker.g:1084:3: ( ^( TABLE_NAME i= id ) ) // org/xcmis/search/parser/CMISSQLTreeWalker.g:1085:3: ^( TABLE_NAME i= id ) { match(input,TABLE_NAME,FOLLOW_TABLE_NAME_in_tableName2559); match(input, Token.DOWN, null); pushFollow(FOLLOW_id_in_tableName2563); i=id(); state._fsp--; match(input, Token.UP, null); res=new SelectorName(i); } } catch (RecognitionException e) { throw e; } finally { } return res; } // $ANTLR end "tableName"