/** * 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()); }
final SelectorName name = new SelectorName(tableName); if (rightSource.getAliasOrName().equals(name))
protected final ReadableVisitor append(SelectorName name) { sb.append(name.getName()); return this; }
@Override public void visit(Selector selector) { if (notFound.get() && selector.getAliasOrName().equals(name)) { notFound.set(false); } } });
/** * Get selector name for qualifer. Qualifier may be selector name or table * name. Method returns actual selector name. * * @param qualifierName - selector or table name * @return selector name * @throws TreeWalkerException if there is no such selector or selector name. */ private SelectorName getSelectorName(SelectorName qualifierName) throws TreeWalkerException { if (selectors.containsKey(qualifierName)) { return qualifierName; } else if (selectors.containsValue(qualifierName)) { Iterator<SelectorName> it = selectors.keySet().iterator(); // find selectorName associated with queryName name while (it.hasNext()) { SelectorName selName = it.next(); SelectorName ntName = selectors.get(selName); if ((!selName.equals(qualifierName)) && (ntName.equals(qualifierName))) { return selName; } } throw new TreeWalkerException("queryName name [" + qualifierName + "] has no associated selector name."); } else { throw new TreeWalkerException("There is no selector name or table name [" + qualifierName + "]"); } }
/** * 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; }
/** * 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; }
/** * {@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; }
/** * Add a table with the supplied name and column names. Each column will * be given a default type. The table will also overwrite any existing * table definition with the same name. * * @param name * the name of the new table * @param columnNames * the names of the columns. * @return this builder, for convenience in method chaining; never null */ public Builder addTable(String name, String... columnNames) { Validate.notEmpty(name, " name may not be empty"); Validate.notEmpty(columnNames, "columnNames may not be empty"); List<Column> columns = new ArrayList<Column>(); int i = 0; for (String columnName : columnNames) { Validate.notEmpty(columnName, "columnName[" + (i++) + "] may not be empty");; // TODO default type columns.add(new InMemoryColumn(columnName, PropertyType.STRING)); } InMemoryTable table = new InMemoryTable(new SelectorName(name), columns); tables.put(table.getName(), table); return this; }
/** * @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())); } }
/** * 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; }
Validate.notEmpty(columnName, " columnName may not be empty"); Validate.notNull(type, " type may not be null"); SelectorName selector = new SelectorName(tableName); InMemoryTable existing = tables.get(selector); InMemoryTable table = null;
/** * @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())); } }
/** * Check if selector exists in list of selectors. * @param selectorName * @param propertyName * @param columnIsRequired */ public Schema.Column checkTableAndColumnExistance(SelectorName selectorName, String propertyName, boolean columnIsRequired) { Table table = checkSelectorExistance(selectorName); //no need to check select ALL properties. if (table != null && !propertyName.equals("*")) { Schema.Column column = table.getColumn(propertyName); if (column == null) { // Maybe the supplied property name is really an alias ... column = this.columnsByAlias.get(propertyName); if (column == null && columnIsRequired) { problems.addException(new InvalidQueryException("Column " + propertyName + " doesnt exist on table " + selectorName.getName() + " or not allowed for search")); } } return column; } return null; }
columns.add(new InMemoryColumn(columnName, types[i])); InMemoryTable table = new InMemoryTable(new SelectorName(name), columns); tables.put(table.getName(), table); return this;
/** * @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())); } }
SelectorName selector = new SelectorName(tableName); InMemoryTable existing = tables.get(selector); InMemoryTable table = null;
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"
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"