public DefaultQueryExecutor(Net.Vpc.Upa.Impl.Persistence.NativeStatementType type, System.Collections.Generic.IDictionary <string, object> hints, string query, System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.Parameter> queryParameters, System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.Parameter> generatedKeys, Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore, Net.Vpc.Upa.Persistence.UConnection connection, Net.Vpc.Upa.Impl.Persistence.NativeField[] nativeFields, bool updatable, Net.Vpc.Upa.Persistence.ResultMetaData metaData) { this.type = type; this.updatable = updatable; this.metaData = metaData; this.query = query; this.fields = nativeFields; this.queryParameters = queryParameters; this.generatedKeys = generatedKeys; this.persistenceStore = persistenceStore; this.connection = connection; parameters = new System.Collections.Generic.Dictionary <string, string>(); this.hints = hints; }
public CustomUpdateQueryExecutor(Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore defaultPersistenceStore, System.Collections.Generic.IDictionary <string, object> finalHints, Net.Vpc.Upa.Expressions.Update baseExpression, System.Collections.Generic.IDictionary <string, object> parametersByName, System.Collections.Generic.IDictionary <int?, object> parametersByIndex, bool updatable, Net.Vpc.Upa.Filters.FieldFilter defaultFieldFilter, Net.Vpc.Upa.Persistence.EntityExecutionContext context, System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.VarVal> complexVals, Net.Vpc.Upa.Entity entity, string entityName, Net.Vpc.Upa.Persistence.ResultMetaData metadata) { this.defaultPersistenceStore = defaultPersistenceStore; this.finalHints = finalHints; this.baseExpression = baseExpression; this.parametersByName = parametersByName; this.parametersByIndex = parametersByIndex; this.updatable = updatable; this.defaultFieldFilter = defaultFieldFilter; this.context = context; this.complexVals = complexVals; this.entity = entity; this.entityName = entityName; this.metadata = metadata; this.connection = context.GetConnection(); }
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); }
public virtual object CreateResult(Net.Vpc.Upa.Impl.Persistence.Result.ResultColumn[] row, Net.Vpc.Upa.Persistence.ResultMetaData metadata) { System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> fields = metadata.GetFields(); Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData d = (Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData)metadata; string[] bindings = (string[])Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(d.GetProperties(), CACHE_KEY); if (bindings == null) { bindings = new string[(fields).Count]; for (int i = 0; i < (fields).Count; i++) { Net.Vpc.Upa.Persistence.ResultField field = fields[i]; Net.Vpc.Upa.Expressions.Expression ss = field.GetExpression(); string binding = ss == null ? "null" : ss.ToString(); bindings[i] = binding; } d.GetProperties()[CACHE_KEY] = bindings; } object[] allRet = new object[(fields).Count]; for (int i = 0; i < allRet.Length; i++) { allRet[i] = row[i].GetValue(); } return(allRet); }
public DefaultObjectQueryResultLazyList(Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor, bool loadManyToOneRelations, bool defaultsToRecord, bool relationAsRecord, bool supportCache, bool updatable, Net.Vpc.Upa.Impl.Persistence.Result.QueryResultRelationLoader loader, Net.Vpc.Upa.Impl.Persistence.Result.QueryResultItemBuilder resultBuilder) : base(queryExecutor) { this.resultBuilder = resultBuilder; this.loader = loader; this.defaultsToRecord = defaultsToRecord; this.relationAsRecord = relationAsRecord; this.loadManyToOneRelations = loadManyToOneRelations; metaData = queryExecutor.GetMetaData(); hints = queryExecutor.GetHints(); if (hints == null) { hints = new System.Collections.Generic.Dictionary <string, object>(); } else { hints = new System.Collections.Generic.Dictionary <string, object>(hints); } if (supportCache) { Net.Vpc.Upa.Impl.Util.CacheMap <Net.Vpc.Upa.NamedId, object> sharedCache = (Net.Vpc.Upa.Impl.Util.CacheMap <Net.Vpc.Upa.NamedId, object>)Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(hints, "queryCache"); if (sharedCache == null) { sharedCache = new Net.Vpc.Upa.Impl.Util.CacheMap <Net.Vpc.Upa.NamedId, object>(1000); hints["queryCache"] = sharedCache; } referencesCache = sharedCache; } loaderContext = new Net.Vpc.Upa.Impl.Persistence.Result.LoaderContext(referencesCache, hints); System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo> bindingToTypeInfos0 = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo>(); ofactory = Net.Vpc.Upa.UPA.GetPersistenceUnit().GetFactory(); Net.Vpc.Upa.Impl.Persistence.NativeField[] fields = queryExecutor.GetFields(); for (int i = 0; i < fields.Length; i++) { Net.Vpc.Upa.Impl.Persistence.NativeField nativeField = fields[i]; Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo f = new Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo(); f.dbIndex = i; f.nativeField = nativeField; f.name = nativeField.GetName(); string gn = nativeField.GetGroupName(); if (gn == null) { gn = nativeField.GetExprString(); } Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo t = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo>(bindingToTypeInfos0, gn); if (t == null) { if (nativeField.GetField() != null) { t = new Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo(gn, nativeField.GetField().GetEntity()); t.record = gn.Contains(".") ? relationAsRecord : defaultsToRecord; bindingToTypeInfos0[gn] = t; } else { t = new Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo(gn, null); t.record = false; //n.contains(".") ? relationAsRecord : defaultsToRecord; bindingToTypeInfos0[gn] = t; } } // if(!bindingToTypeInfos0.containsKey(nativeField.getExprString())) { // bindingToTypeInfos0.put(nativeField.getExprString(), t); // }else{ // System.out.println("why"); // } f.field = nativeField.GetField(); if (loadManyToOneRelations) { if (f.field != null) { if (f.field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Entity r = ((Net.Vpc.Upa.Types.ManyToOneType)f.field.GetDataType()).GetTargetEntity(); f.referencedEntity = r; } foreach (Net.Vpc.Upa.Relationship relationship in f.field.GetManyToOneRelationships()) { if (relationship.GetSourceRole().GetEntityField() != null) { t.manyToOneRelations.Add(relationship); } } } } f.typeInfo = t; t.allFields.Add(f); if (t.leadPrimaryField == null && f.nativeField.GetField() != null && f.nativeField.GetField().IsId()) { t.leadPrimaryField = f; } if (t.leadField == null) { t.leadField = f; } f.setterMethodName = Net.Vpc.Upa.Impl.Util.PlatformUtils.SetterName(nativeField.GetName()); t.fields[f.setterMethodName] = f; } bindingToTypeInfos = bindingToTypeInfos0; typeInfos = (bindingToTypeInfos0).Values.ToArray(); // all indexes to fill with values from the query System.Collections.Generic.ISet <int?> allIndexes = new System.Collections.Generic.HashSet <int?>(); for (int i = 0; i < (metaData.GetFields()).Count; i++) { allIndexes.Add(i); } // map expression to relative TypeInfo/FieldInfo System.Collections.Generic.IDictionary <string, object> visitedIndexes = new System.Collections.Generic.Dictionary <string, object>(); for (int i = 0; i < typeInfos.Length; i++) { Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo typeInfo = typeInfos[i]; // if (aliasName.equals(typeInfo.binding)) { // entityIndex = i; // } typeInfo.infosArray = typeInfo.allFields.ToArray(); typeInfo.update = false; foreach (Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo field in typeInfo.infosArray) { if (!field.nativeField.IsExpanded() && field.nativeField.GetIndex() >= 0) { field.update = true; field.indexesToUpdate.Add(field.nativeField.GetIndex()); allIndexes.Remove(field.nativeField.GetIndex()); visitedIndexes[field.nativeField.GetExprString()] = field; } } if (typeInfo.entity == null) { typeInfo.update = true; } else { System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> fields1 = metaData.GetFields(); for (int i1 = 0; i1 < (fields1).Count; i1++) { Net.Vpc.Upa.Persistence.ResultField resultField = fields1[i1]; if (resultField.GetExpression().ToString().Equals(typeInfo.binding)) { typeInfo.update = true; typeInfo.indexesToUpdate.Add(i1); allIndexes.Remove(i1); visitedIndexes[typeInfo.binding] = typeInfo; break; } } } } //when an expression is to be expanded twice, implementation ignores second expansion // so we must find the equivalent expression index to handle foreach (int?remaining in allIndexes) { string k = metaData.GetFields()[(remaining).Value].GetExpression().ToString(); object o = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(visitedIndexes, k); if (o is Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo) { ((Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo)o).indexesToUpdate.Add(remaining); } else if (o is Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo) { ((Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo)o).indexesToUpdate.Add(remaining); } else { throw new Net.Vpc.Upa.Exceptions.UPAException("Unsupported"); } } this.updatable = updatable; }
public virtual object CreateResult(Net.Vpc.Upa.Impl.Persistence.Result.ResultColumn[] row, Net.Vpc.Upa.Persistence.ResultMetaData metadata) { System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> fields = metadata.GetFields(); Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData d = (Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData)metadata; string[][] preferredNameAndBinding = (string[][])Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(d.GetProperties(), CACHE_KEY); if (preferredNameAndBinding == null) { preferredNameAndBinding = (string[][])Net.Vpc.Upa.Impl.FwkConvertUtils.CreateMultiArray(typeof(string), (fields).Count, 2); for (int i = 0; i < (fields).Count; i++) { Net.Vpc.Upa.Persistence.ResultField field = fields[i]; Net.Vpc.Upa.Expressions.Expression ss = field.GetExpression(); string binding = ss == null ? "null" : ss.ToString(); string preferredName = binding; if (preferredName.IndexOf('.') >= 0) { preferredName = preferredName.Substring(preferredName.LastIndexOf('.') + 1); } string alias = field.GetAlias(); if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(alias)) { preferredName = alias; } preferredNameAndBinding[i][0] = preferredName; preferredNameAndBinding[i][1] = binding; } d.GetProperties()[CACHE_KEY] = preferredNameAndBinding; } if ((fields).Count == 1 && row[0].GetValue() is Net.Vpc.Upa.Record) { return(row[0].GetValue()); } Net.Vpc.Upa.Record r = new Net.Vpc.Upa.Impl.DefaultRecord(); for (int i = 0; i < (fields).Count; i++) { string preferredName = preferredNameAndBinding[i][0]; r.SetObject(preferredName, row[i].GetValue()); } return(r); }