public CompiledJoinCriteria(Net.Vpc.Upa.Expressions.JoinType joinType, Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect entity, string alias, Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression condition) { this.joinType = joinType; this.entity = entity; this.alias = alias; SetCondition(joinType.Equals(Net.Vpc.Upa.Expressions.JoinType.CROSS_JOIN) ? null : condition); }
public virtual System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect> FindEntityDefinitions(System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect> inherited) { System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect> m = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect>(); if (inherited != null) { Net.Vpc.Upa.Impl.FwkConvertUtils.PutAllMap <string, Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect>(m, inherited); } System.Collections.Generic.IList <Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNamedExpression> list = FindEntityDefinitions(); if (list != null) { foreach (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNamedExpression objects in list) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect entity = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)objects.GetExpression(); string entityAlias = objects.GetName(); if (entity != null) { if (entityAlias == null) { if (entity is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName) { entityAlias = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)entity).GetName(); } } if (entityAlias != null) { m[entityAlias] = entity; } } } } return(m); }
public virtual void SetEntity(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect expression) { if (this.entity != null) { this.entity.UnsetParent(); } this.entity = expression; PrepareChildren(expression); }
public virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect From(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect queryEntity, string entityAlias) { Invalidate(); //getContext().declare(alias, queryEntity); this.queryEntity = queryEntity; queryEntityAlias = entityAlias; PrepareChildren(queryEntity); ExportDeclaration(queryEntity, entityAlias); return(this); }
protected internal virtual void ExportDeclaration(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect e, string entityAlias) { if (e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName) { ExportDeclaration(entityAlias, Net.Vpc.Upa.Impl.Uql.DecObjectType.ENTITY, ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)e).GetName(), null); } else { ExportDeclaration(entityAlias, Net.Vpc.Upa.Impl.Uql.DecObjectType.SELECT, e, null); } }
protected internal virtual void AppendFrom(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) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect entity = o.GetEntity(); if (entity == null) { string fns = GetFromNullString(); if (fns != null) { sb.Append(" "); sb.Append(fns); } } else { sb.Append(" From "); if (entity is Net.Vpc.Upa.Expressions.Select) { sb.Append(sqlManager.GetSQL(entity, context, declarations)); } else { Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore = context.GetPersistenceStore(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName entityName = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)entity; Net.Vpc.Upa.Entity e = context.GetPersistenceUnit().GetEntity(entityName.GetName()); if (entityName.IsUseView() && e.NeedsView() && persistenceStore.IsViewSupported()) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(e.GetName(), true); sb.Append(sqlManager.GetSQL(v, context, declarations)); } else { sb.Append(sqlManager.GetSQL(entityName, context, declarations)); } } } if (o.GetEntityAlias() != null) { Net.Vpc.Upa.Persistence.PersistenceStore store = context.GetPersistenceStore(); sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(o.GetEntityAlias()), 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 void SetSubExpression(int index, Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression expression) { int i = 0; if (fields != null) { foreach (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryField field in fields) { if (i == index) { field.SetExpression(expression); if (expression != null) { expression.SetParentExpression(this); } return; } i++; } } if (queryEntity != null) { if (i == index) { queryEntity = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)expression; if (expression != null) { expression.SetParentExpression(this); } return; } i++; } if (joinsTables != null) { for (int ii = 0; ii < (joinsTables).Count; ii++) { if (i == index) { joinsTables[ii] = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria)expression; if (expression != null) { expression.SetParentExpression(this); } return; } i++; } } if (groupByExpressions != null) { int size = (groupByExpressions).Count; for (int j = 0; j < size; j++) { if (i == index) { groupByExpressions[j] = expression; if (expression != null) { expression.SetParentExpression(this); } return; } i++; } } if (order != null) { int size = order.Size(); for (int j = 0; j < size; j++) { if (i == index) { order.SetOrderAt(j, expression); if (expression != null) { expression.SetParentExpression(this); } return; } i++; } } if (where != null) { if (i == index) { where = expression; if (expression != null) { expression.SetParentExpression(this); } } i++; } if (having != null) { if (i == index) { having = expression; if (expression != null) { expression.SetParentExpression(this); } } i++; } }
public virtual string GetMainTableName() { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect t = GetEntity(); return((GetEntity() is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName) ? ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)(GetEntity())).GetName() : null); }
private Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect Join(Net.Vpc.Upa.Expressions.JoinType joinType, Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect entityName, string alias, Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression condition) { Invalidate(); Join(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria(joinType, entityName, alias, condition)); //getContext().declare(alias, entityName); return(this); }
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); }