public override System.Collections.Generic.IList <T> GetValueList <T>(int index) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists()) { if (sessionAwareInstance == null) { sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this); } return(sessionAwareInstance.GetValueList <T>(index)); } try { Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = ExecuteQuery(Net.Vpc.Upa.Impl.Util.Filters.Fields2.READ); if (index < 0 || index > (queryExecutor.GetMetaData().GetFields()).Count) { throw new System.IndexOutOfRangeException("Invalid index " + index); } Net.Vpc.Upa.Impl.Persistence.ValueList <T> r = new Net.Vpc.Upa.Impl.Persistence.ValueList <T>(queryExecutor, index); allResults.Add(r); if (!IsLazyListLoadingEnabled()) { //force loading r.LoadAll(); } return(r); } catch (System.Exception e) { throw new Net.Vpc.Upa.Exceptions.FindException(e, new Net.Vpc.Upa.Types.I18NString("FindFailed")); } }
protected internal QueryResultLazyList(Net.Vpc.Upa.Impl.Persistence.QueryExecutor _queryExecutor) : base(null) { this.queryExecutor = _queryExecutor; this.@base = new Net.Vpc.Upa.Impl.Persistence.QueryResultReader <R>(queryExecutor.GetQueryResult(), this); closeListener = new Net.Vpc.Upa.Impl.Persistence.CloseListenerImpl <?>(this); queryExecutor.GetConnection().AddCloseListener(closeListener); }
public TypeList(Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor, System.Type entity, string[] fields) : base(queryExecutor) { Net.Vpc.Upa.Impl.Persistence.NativeField[] expressions = queryExecutor.GetFields(); this.fields = fields; beanType = Net.Vpc.Upa.Impl.Util.PlatformBeanTypeRepository.GetInstance().GetBeanType(entity); if (fields == null || fields.Length == 0) { System.Collections.Generic.ISet <string> fieldNames = beanType.GetPropertyNames(); this.fields = fieldNames.ToArray(); } fieldsByExpression = new string[expressions.Length]; for (int i = 0; i < fieldsByExpression.Length; i++) { Net.Vpc.Upa.Impl.Persistence.NativeField e = expressions[i]; string name = e.GetName(); foreach (string field in this.fields) { if (name.Equals(field)) { fieldsByExpression[i] = field; break; } } } columns = expressions.Length; }
protected internal virtual Net.Vpc.Upa.Impl.Persistence.QueryExecutor CreateNativeSQL(Net.Vpc.Upa.Filters.FieldFilter fieldFilter) { // applyParameters(); lastQueryExecutor = store.CreateExecutor(query, parametersByName, parametersByIndex, IsUpdatable(), fieldFilter, context.SetHints(GetHints())); Net.Vpc.Upa.Expressions.EntityStatement statement = lastQueryExecutor.GetMetaData().GetStatement(); return(lastQueryExecutor); }
public override System.Collections.Generic.IList <K2> GetIdList <K2>() /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists()) { if (sessionAwareInstance == null) { sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this); } return(sessionAwareInstance.GetIdList <K2>()); } try { if ((query is Net.Vpc.Upa.Expressions.QueryStatement)) { Net.Vpc.Upa.Entity entity = ResolveDefaultEntity(); if (entity != null) { Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = ExecuteQuery(Net.Vpc.Upa.Filters.Fields.Id()); Net.Vpc.Upa.Impl.Persistence.SingleEntityKeyList <K2> r = new Net.Vpc.Upa.Impl.Persistence.SingleEntityKeyList <K2>(queryExecutor, entity); allResults.Add(r); if (!IsLazyListLoadingEnabled()) { //force loading r.LoadAll(); } return(r); } } } catch (System.Exception e) { throw new Net.Vpc.Upa.Exceptions.FindException(e, new Net.Vpc.Upa.Types.I18NString("FindFailed")); } throw new Net.Vpc.Upa.Exceptions.FindException(new Net.Vpc.Upa.Types.I18NString("InvalidQuery")); }
public override bool IsEmpty() /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists()) { if (sessionAwareInstance == null) { sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this); } return(sessionAwareInstance.IsEmpty()); } try { Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = ExecuteQuery(Net.Vpc.Upa.Impl.Util.Filters.Fields2.READ); Net.Vpc.Upa.Persistence.QueryResult r = null; try { r = queryExecutor.GetQueryResult(); return(!r.HasNext()); } finally { if (r != null) { r.Close(); } } } catch (System.Exception e) { throw new Net.Vpc.Upa.Exceptions.FindException(e, new Net.Vpc.Upa.Types.I18NString("FindFailed")); } }
public override int ExecuteNonQuery() { if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists()) { if (sessionAwareInstance == null) { sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this); } return(sessionAwareInstance.ExecuteNonQuery()); } // Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = CreateNativeSQL(null); return(queryExecutor.Execute().GetResultCount()); }
protected internal virtual Net.Vpc.Upa.Impl.Persistence.QueryExecutor ExecuteQuery(Net.Vpc.Upa.Filters.FieldFilter fieldFilter) { // if (result != null) { // throw new FindException("QueryAlreadyExecutedException"); // } Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = CreateNativeSQL(fieldFilter); // DefaultResultMetaData m = new DefaultResultMetaData(); // for (NativeField x : queryExecutor.getFields()) { // m.addField(x.getName(), x.getTypeTransform(), x.getField()); // } // this.metadata = m; queryExecutor.Execute(); result = queryExecutor.GetQueryResult(); return(queryExecutor); }
public virtual System.Collections.Generic.IList <T> GetResultList <T>(Net.Vpc.Upa.Impl.Persistence.Result.QueryResultItemBuilder builder) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists()) { if (sessionAwareInstance == null) { sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this); } return(sessionAwareInstance.GetResultList <T>(builder)); } try { Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = ExecuteQuery(Net.Vpc.Upa.Impl.Util.Filters.Fields2.READ); Net.Vpc.Upa.QueryFetchStrategy fetchStrategy = (Net.Vpc.Upa.QueryFetchStrategy)Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(queryExecutor.GetHints(), Net.Vpc.Upa.QueryHints.FETCH_STRATEGY); if (fetchStrategy == default(Net.Vpc.Upa.QueryFetchStrategy)) { fetchStrategy = Net.Vpc.Upa.QueryFetchStrategy.JOIN; } bool itemAsRecord = builder is Net.Vpc.Upa.Impl.Persistence.Result.RecordQueryResultItemBuilder; bool relationAsRecord = false; bool supportCache = false; Net.Vpc.Upa.Impl.Persistence.Result.QueryResultRelationLoader loader = null; switch (fetchStrategy) { case Net.Vpc.Upa.QueryFetchStrategy.JOIN: { break; } case Net.Vpc.Upa.QueryFetchStrategy.SELECT: { supportCache = true; loader = new Net.Vpc.Upa.Impl.Persistence.Result.QueryRelationLoaderSelectObject(); break; } } Net.Vpc.Upa.Impl.Persistence.QueryResultLazyList <T> r = new Net.Vpc.Upa.Impl.Persistence.Result.DefaultObjectQueryResultLazyList <T>(queryExecutor, fetchStrategy != Net.Vpc.Upa.QueryFetchStrategy.JOIN, itemAsRecord, relationAsRecord, supportCache, IsUpdatable(), loader, builder); allResults.Add(r); if (!IsLazyListLoadingEnabled()) { //force loading r.LoadAll(); } return(r); } catch (System.Exception e) { throw new Net.Vpc.Upa.Exceptions.FindException(e, new Net.Vpc.Upa.Types.I18NString("FindFailed")); } }
public override System.Collections.Generic.IList <T> GetValueList <T>(string name) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists()) { if (sessionAwareInstance == null) { sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this); } return(sessionAwareInstance.GetValueList <T>(name)); } try { Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = ExecuteQuery(Net.Vpc.Upa.Impl.Util.Filters.Fields2.READ); System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> ne = queryExecutor.GetMetaData().GetFields(); int index = -1; for (int i = 0; i < (ne).Count; i++) { if (name.Equals(ne[i].GetAlias())) { index = i; break; } } if (index < 0) { throw new System.Exception("Field " + name + " not found"); } Net.Vpc.Upa.Impl.Persistence.ValueList <T> r = new Net.Vpc.Upa.Impl.Persistence.ValueList <T>(queryExecutor, index); if (!IsLazyListLoadingEnabled()) { //force loading r.LoadAll(); } allResults.Add(r); return(r); } catch (System.Exception e) { throw new Net.Vpc.Upa.Exceptions.FindException(e, new Net.Vpc.Upa.Types.I18NString("FindFailed")); } }
public MultiRecordList(Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor, bool forUpdate) : base(queryExecutor) { this.forUpdate = forUpdate; this.fields = queryExecutor.GetFields(); this.entities = new Net.Vpc.Upa.Entity[this.fields.Length]; this.recordName = new string[this.fields.Length]; this.currentRecords = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Persistence.MultiRecordListTracker>(); this.setterToProp = new System.Collections.Generic.Dictionary <string, System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking> >(); int fieldsCount = fields.Length; for (int i = 0; i < fieldsCount; i++) { Net.Vpc.Upa.Impl.Persistence.NativeField namedExpression = fields[i]; Net.Vpc.Upa.Field field = namedExpression.GetField(); entities[i] = field == null ? null : field.GetEntity(); if (namedExpression.GetGroupName() != null) { recordName[i] = namedExpression.GetGroupName(); } else if (entities[i] != null) { recordName[i] = entities[i].GetName(); } System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking> stringFieldTrackingMap = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking> >(setterToProp, recordName[i]); if (stringFieldTrackingMap == null) { stringFieldTrackingMap = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking>(); setterToProp[recordName[i]] = stringFieldTrackingMap; } if (field != null) { Net.Vpc.Upa.Impl.Persistence.FieldTracking t = new Net.Vpc.Upa.Impl.Persistence.FieldTracking(field.GetName(), Net.Vpc.Upa.Impl.Util.PlatformUtils.SetterName(field.GetName()), i); stringFieldTrackingMap[t.GetSetterMethodName()] = t; } } columns = this.fields.Length; }
public override System.Collections.Generic.IList <T> GetTypeList <T>(System.Type type, params string [] fields) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists()) { if (sessionAwareInstance == null) { sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this); } return(sessionAwareInstance.GetTypeList <T>(type, fields)); } try { Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = ExecuteQuery(Net.Vpc.Upa.Impl.Util.Filters.Fields2.READ); Net.Vpc.Upa.Impl.Persistence.TypeList <T> r = new Net.Vpc.Upa.Impl.Persistence.TypeList <T>(queryExecutor, type, fields); allResults.Add(r); if (!IsLazyListLoadingEnabled()) { //force loading r.LoadAll(); } return(r); } catch (System.Exception e) { throw new Net.Vpc.Upa.Exceptions.FindException(e, new Net.Vpc.Upa.Types.I18NString("FindFailed")); } }
public SingleEntityKeyList(Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor, Net.Vpc.Upa.Entity entity) : base(queryExecutor) { this.entity = entity; columns = queryExecutor.GetFields().Length; }
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 ValueList(Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor, int index) : base(queryExecutor) { this.index = index; }