protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityStatement CreateCompiledEntityStatement() { Net.Vpc.Upa.Persistence.ExpressionCompilerConfig config = new Net.Vpc.Upa.Persistence.ExpressionCompilerConfig(); string alias = null; string ent = null; if (query is Net.Vpc.Upa.Expressions.Select) { Net.Vpc.Upa.Expressions.Select d = (Net.Vpc.Upa.Expressions.Select)query; string entityAlias = d.GetEntityAlias(); Net.Vpc.Upa.Expressions.EntityName entityName = (d.GetEntity() is Net.Vpc.Upa.Expressions.EntityName) ? ((Net.Vpc.Upa.Expressions.EntityName)d.GetEntity()) : null; if (entityAlias != null) { alias = entityAlias; ent = entityName == null ? null : entityName.GetName(); } else { ent = entityName == null ? null : entityName.GetName(); alias = ent; } } if (alias != null) { config.SetThisAlias(alias); } config.SetExpandFields(false); config.SetExpandEntityFilter(false); config.SetValidate(false); return((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityStatement)context.GetPersistenceUnit().GetExpressionManager().CompileExpression(query, config)); }
public static string[] ResolveEntityAndAlias(Net.Vpc.Upa.Expressions.Select select) { string e = select.GetEntityName(); if (e != null) { return(new string[] { e, select.GetEntityAlias() }); } return(null); }
private System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery> FindDeclarations(Net.Vpc.Upa.Expressions.QueryStatement queryStatement) { System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery> names = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery>(); if (queryStatement is Net.Vpc.Upa.Expressions.Select) { Net.Vpc.Upa.Expressions.Select s = (Net.Vpc.Upa.Expressions.Select)queryStatement; if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(s.GetEntityAlias())) { names[s.GetEntityAlias()] = s.GetEntity(); } else { string t = s.GetEntityName(); if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(t)) { names[s.GetEntityAlias()] = s.GetEntity(); } } foreach (Net.Vpc.Upa.Expressions.JoinCriteria j in s.GetJoins()) { if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(j.GetEntityAlias())) { names[j.GetEntityAlias()] = j.GetEntity(); } else { string t = j.GetEntityName(); if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(t)) { names[j.GetEntityAlias()] = j.GetEntity(); } } } } else if (queryStatement is Net.Vpc.Upa.Expressions.Union) { } // do nothing return(names); }
public virtual Net.Vpc.Upa.Persistence.ResultMetaData CreateResultMetaData(Net.Vpc.Upa.Expressions.Expression baseExpression, Net.Vpc.Upa.Filters.FieldFilter fieldFilter, System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context) { baseExpression = Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.ParseUserExpressions(baseExpression, pu); Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData m = new Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData(); if (baseExpression is Net.Vpc.Upa.Expressions.NonQueryStatement) { m.SetStatement((Net.Vpc.Upa.Expressions.EntityStatement)baseExpression); m.AddField(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(null, "result", Net.Vpc.Upa.Types.TypesFactory.INT, null, null)); return(m); } else { Net.Vpc.Upa.Expressions.QueryStatement q = (Net.Vpc.Upa.Expressions.QueryStatement)baseExpression; if (q is Net.Vpc.Upa.Expressions.Select) { Net.Vpc.Upa.Expressions.Select qs = (Net.Vpc.Upa.Expressions.Select)q; if ((qs.GetFields()).Count == 0) { if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(qs.GetEntityAlias())) { qs.Field(new Net.Vpc.Upa.Expressions.Var(qs.GetEntityAlias())); } else if (qs.GetEntityName() != null) { qs.Field(new Net.Vpc.Upa.Expressions.Var(qs.GetEntityName())); } else { throw new Net.Vpc.Upa.Exceptions.UPAException("MissingAlias"); } foreach (Net.Vpc.Upa.Expressions.JoinCriteria joinCriteria in qs.GetJoins()) { if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(joinCriteria.GetEntityAlias())) { qs.Field(new Net.Vpc.Upa.Expressions.Var(joinCriteria.GetEntityAlias())); } else if (joinCriteria.GetEntityName() != null) { qs.Field(new Net.Vpc.Upa.Expressions.Var(joinCriteria.GetEntityName())); } else { throw new Net.Vpc.Upa.Exceptions.UPAException("MissingAlias"); } } } System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryField> oldFields = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryField>(q.GetFields()); System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryField> newFields = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryField>(); System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> newResults = new System.Collections.Generic.List <Net.Vpc.Upa.Persistence.ResultField>(); System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context2 = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryStatement>(); Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(context2, context); context2.Add(q); foreach (Net.Vpc.Upa.Expressions.QueryField f in oldFields) { Net.Vpc.Upa.Expressions.Expression expression = f.GetExpression(); string oldAlias = f.GetAlias(); System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> newVal = CreateResultFields(expression, oldAlias, fieldFilter, context2); Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(newResults, newVal); if ((newVal).Count == 0) { } else if ((newVal).Count == 1) { f.SetExpression(newVal[0].GetExpression()); f.SetAlias(Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(oldAlias) ? oldAlias : newVal[0].GetAlias()); newFields.Add(f); } else { foreach (Net.Vpc.Upa.Persistence.ResultField nf in newVal) { Net.Vpc.Upa.Expressions.QueryField f2 = new Net.Vpc.Upa.Expressions.QueryField(Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(oldAlias) ? oldAlias : nf.GetAlias(), nf.GetExpression()); newFields.Add(f2); } } } qs.ClearFields(); foreach (Net.Vpc.Upa.Expressions.QueryField newField in newFields) { qs.Field(newField); } m.SetStatement(qs); foreach (Net.Vpc.Upa.Persistence.ResultField newResult in newResults) { m.AddField(newResult); } } else if (q is Net.Vpc.Upa.Expressions.Union) { System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context2 = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryStatement>(); Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(context2, context); context2.Add(q); Net.Vpc.Upa.Expressions.Union u0 = (Net.Vpc.Upa.Expressions.Union)q; Net.Vpc.Upa.Expressions.Union u = new Net.Vpc.Upa.Expressions.Union(); Net.Vpc.Upa.Persistence.ResultField[] fields = null; foreach (Net.Vpc.Upa.Expressions.QueryStatement qs in u0.GetQueryStatements()) { Net.Vpc.Upa.Persistence.ResultMetaData resultMetaData = CreateResultMetaData(qs, fieldFilter, context2); u.Add((Net.Vpc.Upa.Expressions.QueryStatement)resultMetaData.GetStatement()); System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> f = resultMetaData.GetFields(); if (fields == null) { fields = f.ToArray(); } else { if (fields.Length != (f).Count) { throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidUnion"); } for (int i = 0; i < fields.Length; i++) { fields[i] = Merge(fields[i], f[i]); } } } m.SetStatement(u); if (fields != null) { foreach (Net.Vpc.Upa.Persistence.ResultField field in fields) { m.AddField(field); } } } else { throw new System.Exception(); } } return(m); }
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); }