private Query.Join GetJoinExpr(string table, IList <Query.Join> joinExprs) { for (Iterator <Query.Join> iter = joinExprs.Iterator(); iter.HasNext();) { Query.Join joinExpr = iter.Next(); if (joinExpr.tables.Contains(table)) { iter.Remove(); return(joinExpr); } } throw new InvalidOperationException("Cannot find join table " + table); }
public void Add(Query.Join other, string newExpr) { Sharpen.Collections.AddAll(tables, other.tables); isJoin = true; expression = newExpr; }
public virtual IList <string> GetFromTables() { IList <Query.Join> joinExprs = new AList <Query.Join>(); foreach (Query.Row table in GetTableRows()) { StringBuilder builder = new StringBuilder(); if (table.expression != null) { ToQuotedExpr(builder, table.expression).Append(QueryFormat.IDENTIFIER_SEP_CHAR); } if (table.name1 != null) { ToOptionalQuotedExpr(builder, table.name1, true); } ToAlias(builder, table.name2); string key = ((table.name2 != null) ? table.name2 : table.name1); joinExprs.AddItem(new Query.Join(key, builder.ToString())); } IList <Query.Row> joins = GetJoinRows(); if (!joins.IsEmpty()) { // combine any multi-column joins ICollection <IList <Query.Row> > comboJoins = CombineJoins(joins); foreach (IList <Query.Row> comboJoin in comboJoins) { Query.Row join = comboJoin[0]; string joinExpr = join.expression; if (comboJoin.Count > 1) { // combine all the join expressions with "AND" Query.AppendableList <string> comboExprs = new _AppendableList_279(); foreach (Query.Row tmpJoin in comboJoin) { comboExprs.AddItem(tmpJoin.expression); } joinExpr = new StringBuilder().Append("(").Append(comboExprs).Append(")").ToString (); } string fromTable = join.name1; string toTable = join.name2; Query.Join fromExpr = GetJoinExpr(fromTable, joinExprs); Query.Join toExpr = GetJoinExpr(toTable, joinExprs); string joinType = QueryFormat.JOIN_TYPE_MAP.Get(join.flag); if (joinType == null) { throw new InvalidOperationException("Unknown join type " + join.flag); } string expr = new StringBuilder().Append(fromExpr).Append(joinType).Append(toExpr ).Append(" ON ").Append(joinExpr).ToString(); fromExpr.Add(toExpr, expr); joinExprs.AddItem(fromExpr); } } IList <string> result = new Query.AppendableList <string>(); foreach (Query.Join joinExpr_1 in joinExprs) { result.AddItem(joinExpr_1.expression); } return(result); }