public virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect Join(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria someJoin) { joinsTables.Add(someJoin); PrepareChildren(someJoin); ExportDeclaration(someJoin.GetEntity(), someJoin.GetEntityAlias()); return(this); }
protected internal virtual void AppendJoins(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect o, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { for (int i = 0; i < o.CountJoins(); i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria e = o.GetJoin(i); // String _valueString = sqlManager.getSQL(e.getEntity(), context, declarations); string _aliasString = e.GetEntityAlias(); string _joinKey = "Inner Join"; switch (e.GetJoinType()) { case Net.Vpc.Upa.Expressions.JoinType.INNER_JOIN: _joinKey = "Inner Join"; break; case Net.Vpc.Upa.Expressions.JoinType.FULL_JOIN: _joinKey = "Full Join"; break; case Net.Vpc.Upa.Expressions.JoinType.LEFT_JOIN: _joinKey = "Left Join"; break; case Net.Vpc.Upa.Expressions.JoinType.RIGHT_JOIN: _joinKey = "Right Join"; break; case Net.Vpc.Upa.Expressions.JoinType.CROSS_JOIN: _joinKey = "Cross Join"; break; } sb.Append(" ").Append(_joinKey).Append(" ").Append(sqlManager.GetSQL(e.GetEntity(), context, declarations)); if (_aliasString != null) { Net.Vpc.Upa.Persistence.PersistenceStore store = context.GetPersistenceStore(); // String goodAlias = store.getPersistenceName(, PersistenceNameType.ALIAS); sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(_aliasString), context, declarations)); } if (e.GetCondition() != null && e.GetCondition().IsValid()) { sb.Append(" On ").Append(sqlManager.GetSQL(e.GetCondition(), context, declarations)); } } }
public virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect AddQuery(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect other) { if (other == null) { return(this); } if (other.queryEntity != null) { From((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)(other.queryEntity.Copy()), other.queryEntityAlias); } for (int i = 0; i < (other.joinsTables).Count; i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria j = other.GetJoin(i); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect ee = j.GetEntity(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression cc = j.GetCondition(); Join(j.GetJoinType(), ee == null ? null : (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)ee.Copy(), j.GetEntityAlias(), cc == null ? null : cc.Copy()); } foreach (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryField field in other.fields) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression ee = field.GetExpression(); AddField(ee == null ? null : ee.Copy(), field.GetAlias()); } foreach (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledOrderItem compiledOrderItem in other.order.GetItems()) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression ee = compiledOrderItem.GetExpression(); OrderBy(ee == null ? null : ee.Copy(), compiledOrderItem.IsAsc()); } foreach (Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression e in other.groupByExpressions) { GroupBy(e == null ? null : e.Copy()); } AddWhere(other.where == null ? null : other.where.Copy()); AddHaving(other.having == null ? null : other.having.Copy()); Invalidate(); return(this); }
public override string ToString() { System.Text.StringBuilder sb = new System.Text.StringBuilder("Select "); if (top > 0) { sb.Append(" TOP ").Append(top); } if (distinct) { sb.Append(" DISTINCT"); } sb.Append(" "); string aliasString = null; string valueString = null; bool started = false; if (CountFields() == 0) { sb.Append("..."); } else { for (int i = 0; i < CountFields(); i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryField fi = GetField(i); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression e = fi.GetExpression(); valueString = System.Convert.ToString(e); if (!(e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar) && !(e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam) && !(e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledFunction) && !(e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral)) { valueString = "(" + valueString + ")"; } aliasString = fi.GetAlias(); if (started) { sb.Append(","); } else { started = true; } if (aliasString == null) { sb.Append(valueString); } else { sb.Append(valueString); sb.Append(" "); sb.Append(aliasString); } } } if (GetEntity() == null) { } else { sb.Append(" From "); if (GetEntity() is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect) { sb.Append(GetEntity().ToString()); } else { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName entityName = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)GetEntity(); sb.Append(entityName); } } if (GetEntityAlias() != null) { sb.Append(" ").Append(GetEntityAlias()); } for (int i = 0; i < CountJoins(); i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria e = GetJoin(i); sb.Append(" ").Append(e); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression c = GetWhere(); if (c != null && c.IsValid()) { sb.Append(" Where ").Append(c); } if (CountGroupByItems() > 0) { sb.Append(" "); int maxGroups = CountGroupByItems(); sb.Append("Group By "); for (int i = 0; i < maxGroups; i++) { if (i > 0) { sb.Append(", "); } sb.Append(GetGroupBy(i)); } } int maxOrders = CountOrderByItems(); if (maxOrders > 0) { sb.Append(" "); sb.Append("Order By "); for (int i = 0; i < maxOrders; i++) { if (i > 0) { sb.Append(", "); } sb.Append(GetOrderBy(i)); if (IsOrderAscending(i)) { sb.Append(" Asc "); } else { sb.Append(" Desc "); } } } return(sb.ToString()); }
protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect CompileSelect(Net.Vpc.Upa.Expressions.Select v, Net.Vpc.Upa.Impl.Uql.ExpressionTranslationManager manager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { if (v == null) { return(null); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect s = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect(); s.SetDistinct(v.IsDistinct()); s.SetTop(v.GetTop()); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect nameOrSelect = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)manager.TranslateAny(v.GetEntity(), declarations); string entityAlias = v.GetEntityAlias(); System.Collections.Generic.HashSet <string> aliases = new System.Collections.Generic.HashSet <string>(); if (entityAlias == null) { if (nameOrSelect is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName) { entityAlias = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)nameOrSelect).GetName(); } else { entityAlias = "ALIAS"; } int i = 0; while (true) { string a2 = i == 0 ? entityAlias : (entityAlias + i); if (!aliases.Contains(a2)) { aliases.Add(a2); entityAlias = a2; break; } i++; } } s.From(nameOrSelect, entityAlias); for (int i = 0; i < v.CountJoins(); i++) { Net.Vpc.Upa.Expressions.JoinCriteria c = v.GetJoin(i); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect jnameOrSelect = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)manager.TranslateAny(c.GetEntity(), declarations); entityAlias = c.GetEntityAlias(); if (entityAlias == null) { if (nameOrSelect is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName) { entityAlias = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)nameOrSelect).GetName(); } else { entityAlias = "ALIAS"; } i = 0; while (true) { string a2 = i == 0 ? entityAlias : (entityAlias + i); if (!aliases.Contains(a2)) { aliases.Add(a2); entityAlias = a2; break; } i++; } } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria cc = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria(c.GetJoinType(), jnameOrSelect, entityAlias, manager.TranslateAny(c.GetCondition(), declarations)); s.Join(cc); } for (int i = 0; i < v.CountFields(); i++) { Net.Vpc.Upa.Expressions.QueryField field = v.GetField(i); s.Field(manager.TranslateAny(field.GetExpression(), declarations), field.GetAlias()); } s.Where(manager.TranslateAny(v.GetWhere(), declarations)); s.Having(manager.TranslateAny(v.GetHaving(), declarations)); for (int i = 0; i < v.CountGroupByItems(); i++) { Net.Vpc.Upa.Expressions.Expression c = v.GetGroupBy(i); s.GroupBy(manager.TranslateAny(c, declarations)); } for (int i = 0; i < v.CountOrderByItems(); i++) { Net.Vpc.Upa.Expressions.Expression c = v.GetOrderBy(i); s.OrderBy(manager.TranslateAny(c, declarations), v.IsOrderAscending(i)); } return(s); }