/// <summary> /// This method recovers all the population of the database /// </summary> /// <param name="onContext">Recovers the context of the execution of the service</param> /// <param name="linkedTo">List to reach the class to retrieve the related instance</param> /// <param name="comparer">Order Criteria that must be followed</param> /// <param name="${startRowOid}">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> /// <returns>The population</returns> public override ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList linkedTo, ONOrderCriteria comparer, ONOid startRowOID, int blockSize) { if (InData) { return(null); } ONLinkedToList lLinkedToList = new ONLinkedToList(); // Add linkedToList to the new list foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in linkedTo) { lLinkedToList.mLinkedToList.Add(lDictionaryEntry.Key, lDictionaryEntry.Value); } // Add relatedOid to the new list if (mRelatedOid != null) { lLinkedToList.mLinkedToList.Add(ONPath, mRelatedOid); } // Add parameters object[] lParameters = new object[5]; lParameters[0] = onContext; lParameters[1] = linkedTo; lParameters[2] = comparer; lParameters[3] = startRowOID; lParameters[4] = blockSize; return(ONContext.InvoqueMethod(ONContext.GetType_LV(ClassName), "QueryByRelated", lParameters) as ONCollection); }
public ONOrderCriteria GetOrderCriteria(string orderCriteria) { ONOrderCriteria lComparer = ONContext.GetComponent_OrderCriteria(ClassName, orderCriteria); if ((lComparer != null) && (!lComparer.IsVisible(OnContext))) { lComparer = null; } return(lComparer); }
/// <summary>Solves the filters defined in this class</summary> /// <param name="linkedTo">This parameter has the related instance to retrieve the requested instances</param> /// <param name="filters">This parameter has all the filters defined with this class</param> /// <param name="orderCriteria">This parameter has the name of the order criteria to add to SQL statement</param> /// <param name="startRowOID">This parameter has the OID necessary to start the search</param> /// <param name="blockSize">This parameter represents the number of instances to be returned</param> public override ONCollection QueryByFilter(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, string orderCriteria, ONOid startRowOID, int blockSize) { // OrderCriteria ONOrderCriteria lComparer = GetOrderCriteria(orderCriteria); // Horizontal visibility if (filters == null) { filters = new ONFilterList(); } filters.Add("HorizontalVisibility", new NaveNodrizaHorizontalVisibility()); // Linked To List if (linkedTo == null) { linkedTo = new ONLinkedToList(); } // Call Data try { NaveNodrizaData lData = new NaveNodrizaData(OnContext); ONCollection lCollection = lData.ExecuteQuery(linkedTo, filters, displaySet, lComparer, startRowOID, blockSize); // OrderCriteria if (lComparer != null) { lCollection.Sort(lComparer); } return(lCollection); } catch (Exception e) { if (e is ONException) { throw e; } else { string ltraceItem = "Error in query, Method: ExecuteQuery, Component: NaveNodrizaQuery"; if (e is ONSystemException) { ONSystemException lException = e as ONSystemException; lException.addTraceInformation(ltraceItem); throw lException; } throw new ONSystemException(e, ltraceItem); } } }
/// <summary> /// This method recovers an instance with the OID /// </summary> /// <param name="onContext">Recovers the context of the execution of the service</param> /// <param name="linkedTo">List to reach the class to retrieve the related instance</param> /// <param name="comparer">Order Criteria that must be followed</param> /// <param name="${startRowOid}">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> /// <returns>The instance</returns> public override ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList linkedTo, ONOrderCriteria comparer, ONOid startRowOID, int blockSize) { if (InData) return null; // Add parameters object[] lParameters = new object[2]; lParameters[0] = onContext; lParameters[1] = mOid; ONCollection lCollection = ONContext.GetComponent_Collection(mOid.ClassName, onContext); ONInstance lInstance = ONContext.InvoqueMethod(ONContext.GetType_LV(mOid.ClassName), "QueryByOid", lParameters) as ONInstance; if (lInstance != null) lCollection.Add(lInstance); return lCollection; }
/// <summary> /// This method recovers all the population of the database /// </summary> /// <param name="onContext">Recovers the context of the execution of the service</param> /// <param name="linkedTo">List to reach the class to retrieve the related instance</param> /// <param name="comparer">Order Criteria that must be followed</param> /// <param name="${startRowOid}">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> /// <returns>The population</returns> public override ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList linkedTo, ONOrderCriteria comparer, ONOid startRowOID, int blockSize) { if (InData) return null; ONLinkedToList lLinkedToList = new ONLinkedToList(); // Add linkedToList to the new list foreach (KeyValuePair<ONPath, ONOid> lDictionaryEntry in linkedTo) lLinkedToList.mLinkedToList.Add(lDictionaryEntry.Key, lDictionaryEntry.Value); // Add relatedOid to the new list if (mRelatedOid != null) lLinkedToList.mLinkedToList.Add(ONPath, mRelatedOid); // Add parameters object[] lParameters = new object[5]; lParameters[0] = onContext; lParameters[1] = linkedTo; lParameters[2] = comparer; lParameters[3] = startRowOID; lParameters[4] = blockSize; return ONContext.InvoqueMethod(ONContext.GetType_LV(ClassName), "QueryByRelated", lParameters) as ONCollection; }
public void FilterInLegacy(ONContext onContext, ONLinkedToList lLinkedToList, ONOrderCriteria comparer, ONOid startRowOid, int blockSize) { foreach (ONFilter lOnFilter in Values) { lOnFilter.FilterInLegacy(onContext, lLinkedToList, comparer, startRowOid, blockSize); } }
///<summary> This method adds the order criteria to the SQL statement </summary> ///<param name = "onSql"> This parameter represents the SQL component </param> ///<param name = "comparer"> This parameter has all the information refering to the order criteria to add to SQL statement</param> /// <param name="startRowOid">This parameter has the OID necessary to start the search</param> /// <param name="blockSize">This parameter represents the number of instances to be returned</param> protected override void AddOrderCriteria(ONSqlSelect onSql, ONOrderCriteria comparer, ONOid startRowOid, int blockSize, ONPath initialPath) { //Initilizate StartRow AeronaveInstance lInstance = null; if (startRowOid != null) { lInstance = new AeronaveInstance(OnContext); lInstance.Oid = startRowOid as AeronaveOid; } //Default OrderCriteria if (comparer == null) { string lAlias = onSql.GetAlias("Aeronave", initialPath); if (lInstance != null) { onSql.AddOrderBy(lAlias, CtesBD.FLD_AERONAVE_ID_AERONAVE, OrderByTypeEnumerator.Asc, lInstance.Oid.Id_AeronaveAttr); } else { onSql.AddOrderBy(lAlias, CtesBD.FLD_AERONAVE_ID_AERONAVE, OrderByTypeEnumerator.Asc, null); } return; } //Add OrderCriteria bool lUseStartRow = (!comparer.InMemory); foreach (ONOrderCriteriaItem lOrderCriteriaItem in comparer.OrderCriteriaSqlItem) { ONPath lPath = new ONPath(lOrderCriteriaItem.OnPath); if((lInstance != null) && (lUseStartRow)) { ONSimpleType lAttrStartRow = null; if (lPath.Path == "") lAttrStartRow = lInstance[lOrderCriteriaItem.Attribute] as ONSimpleType; else { ONCollection lCollection = (lInstance[lPath.Path] as ONCollection); if((lCollection != null) && (lCollection.Count > 0)) lAttrStartRow = lCollection[0][lOrderCriteriaItem.Attribute] as ONSimpleType; } onSql.AddOrderBy(AeronaveData.AddPath(onSql, JoinType.LeftJoin, lOrderCriteriaItem.Facet, lPath, null, lOrderCriteriaItem.DomainArgument, false), lOrderCriteriaItem.Attribute, lOrderCriteriaItem.Type, lAttrStartRow); lUseStartRow = (lAttrStartRow != null); } else onSql.AddOrderBy(AeronaveData.AddPath(onSql, JoinType.LeftJoin, lOrderCriteriaItem.Facet, lPath, null, lOrderCriteriaItem.DomainArgument, false), lOrderCriteriaItem.Attribute, lOrderCriteriaItem.Type, null); } return; }
/// <summary> /// Executes the SQL statment over the Data Base connected /// </summary> /// <param name="onSql">This parameter has the current SQL statment</param> /// <param name="onFilterList">List of filters to check</param> /// <param name="comparer">This parameter has all the information refering to the order criteria to add to SQL statment</param> /// <param name="startRowOid">This parameter has the OID necessary to start the search</param> /// <param name="blockSize">This parameter represents the number of instances to be returned</param> public override ONCollection ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria orderCriteria, ONOid startRowOid, int blockSize) { AeronaveCollection lQuery = null; bool lWithStartRow = (startRowOid != null).TypedValue; long lCount = -1; if (!lWithStartRow) lCount = 0; IDataReader lDataReader = null; ONSQLConnection lOnSQLConnection = null; try { lDataReader = Execute(onSql) as IDataReader; AeronaveInstance lInstance = null; AeronaveInstance lAntInstance = null; if (lDataReader != null) { object[] lColumns; if(displaySet == null) lColumns = new object[4]; else lColumns = new object[displaySet.ElementsInData]; lQuery = new AeronaveCollection(OnContext); bool lFoundStartRow = false; while (lDataReader.Read()) { lAntInstance = lInstance; // Read Columns lDataReader.GetValues(lColumns); // Read Instance int lIndex = 0; lInstance = LoadFacet(OnContext, displaySet, lColumns, ref lIndex); // Read related attributes if (displaySet != null) LoadRelated(OnContext, displaySet, lColumns, lIndex, lInstance); if (lCount >= 0) // Add the load instance { if ((onFilterList == null) || (!onFilterList.InMemory)) { // Add to the Instance list lQuery.Add(lInstance); lCount++; } else { ONSQLConnection lSQLConnectionOld = (ONSQLConnection) lInstance.OnContext.SqlConnection; // Set another connection because it is imposible to use // the same connection that is used in the DataReader if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; if (onFilterList.FilterInMemory(lInstance)) { // Add to the Instance list lQuery.Add(lInstance); lCount++; } lInstance.OnContext.SqlConnection = lSQLConnectionOld; } } else { if ((orderCriteria != null) && (orderCriteria.InMemory)) // Need to load for ordering in memory after loading { if (lAntInstance != null) { // Set another connection because it is imposible to use // the same connection that is used in the DataReader ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection; if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance); if (lCompare != 0) { if (lFoundStartRow) lCount = 1; else lQuery.Clear(); } // Restores the old connection lInstance.OnContext.SqlConnection = lOnSQLConnectionOld; } if ((onFilterList == null) || (!onFilterList.InMemory)) { // Add to the Instance list lQuery.Add(lInstance); } else { ONSQLConnection lSQLConnectionOld = (ONSQLConnection)lInstance.OnContext.SqlConnection; // Set another connection because it is imposible to use // the same connection that is used in the DataReader if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; if (onFilterList.FilterInMemory(lInstance)) { // Add to the Instance list lQuery.Add(lInstance); } else lCount--; lInstance.OnContext.SqlConnection = lSQLConnectionOld; } if (lInstance.Oid.Equals(startRowOid)) lFoundStartRow = true; } else if (lInstance.Oid.Equals(startRowOid)) // Search the start row lCount = 0; } // Stop loading if ((blockSize != 0) && (lCount > blockSize)) { if (orderCriteria == null) break; else { // Set another connection because it is imposible to use // the same connection that is used in the DataReader ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection; if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance); // Restores the old connection lInstance.OnContext.SqlConnection = lOnSQLConnectionOld; if (lCompare > 0) break; } } } } } catch (Exception e) { string ltraceItem = "Method: ExecuteSql, Component: AeronaveData"; if (e is ONSystemException) { ONSystemException lException = e as ONSystemException; lException.addTraceInformation(ltraceItem); throw lException; } throw new ONSystemException(e, ltraceItem); } finally { if (lOnSQLConnection != null) ONDBData.CloseConnection(lOnSQLConnection); if (lDataReader != null) { if (mSqlCommand != null) mSqlCommand.Cancel(); lDataReader.Close(); } Close(); if ((onFilterList != null) && (onFilterList.InMemory) && !lWithStartRow && (lCount <= blockSize)) lQuery.totalNumInstances = lQuery.Count; } return lQuery; }
/// <summary> /// Retrieve all the instances of a determinate class that fulfil a determinate formula of searching /// </summary> /// <param name="linkedTo">List to reach the class to retrieve the related instance</param> /// <param name="filters">Formula to search concrete instances</param> /// <param name="comparer">Order Criteria that must be followed by the query</param> /// <param name="startRowOid">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> /// <returns>Instances that check the filter list</returns> protected virtual ONCollection SolveQuery(ONLinkedToList linkedTo, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize) { ONSqlSelect lOnSql = new ONSqlSelect(); try { // Create select and first table InhRetrieveInstances(lOnSql, displaySet, null, OnContext); // Fix related instance if (!AddLinkedTo(lOnSql, linkedTo)) return ONContext.GetComponent_Collection(ClassName, OnContext); // Add filter formula if (onFilterList != null) onFilterList.FilterInData(lOnSql, this); // Retrieve query instance number int lTotalNumInstances = -1; if (OnContext.CalculateQueryInstancesNumber) { if ((onFilterList == null) || (!onFilterList.InMemory)) { ArrayList lSqlParameters; string lNumInstancesSqlSentence = ONSqlSelect.GenerateSQLAsCount(lOnSql, out lSqlParameters); lTotalNumInstances = Convert.ToInt32(ExecuteScalar(lNumInstancesSqlSentence, lSqlParameters)); } OnContext.CalculateQueryInstancesNumber = false; } // OrderCriteria AddOrderCriteria(lOnSql, comparer, startRowOid, blockSize); // Execute ONCollection lONCollection = ExecuteSql(lOnSql, onFilterList, displaySet, comparer, startRowOid, blockSize); // Set Query instance number if (lTotalNumInstances > -1) lONCollection.totalNumInstances = lTotalNumInstances; return lONCollection; } catch (Exception e) { string ltraceItem = "Method: SolveQuery, Component: ONDBData"; if (e is ONSystemException) { ONSystemException lException = e as ONSystemException; lException.addTraceInformation(ltraceItem); throw lException; } throw new ONSystemException(e, ltraceItem); } }
/// <summary> This method adds the order criteria to the SQL statement </summary> /// <param name="onSql"> This parameter represents the SQL component </param> /// <param name="comparer"> This parameter has all the information refering to the order criteria to add to SQL statement</param> /// <param name="startRowOid">This parameter has the OID necessary to start the search</param> /// <param name="blockSize">This parameter represents the number of instances to be returned</param> /// <param name="initialPath"> This parameter has the path of the instances reached in a For All</param> protected virtual void AddOrderCriteria(ONSqlSelect onSql, ONOrderCriteria comparer, ONOid startRowOid, int blockSize, ONPath initialPath) { }
/// <summary> /// Execution of a sql /// </summary> /// <param name="onSql">Sentence SQL to be executed</param> /// <param name="onFilterList">List of filters to check</param> /// <param name="comparer">Order Criteria that must be followed by the query</param> /// <param name="startRowOID">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> public virtual ONCollection ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOID, int blockSize) { return null; }
/// <summary> /// Retrieve all the instances of a determinate class that fulfil a determinate formula of searching /// </summary> /// <param name="linkedTo">List to reach the class to retrieve the related instance</param> /// <param name="filters">Formula to search concrete instances</param> /// <param name="comparer">Order Criteria that must be followed by the query</param> /// <param name="startRowOID">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> public override ONCollection ExecuteQuery(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize) { try { ONCollection lInstances = null; Type lTypeInstance = ONContext.GetType_Instance(ClassName); Type lTypeQuery = ONContext.GetType_Query(ClassName); // Initialize the list of related queries if (linkedTo == null) linkedTo = new ONLinkedToList(); // Initialize the filter list if (filters == null) filters = new ONFilterList(); ONLinkedToList lLinkedToLegacy = new ONLinkedToList(); ONLinkedToList lLinkedToLocal = new ONLinkedToList(); ONLinkedToList lLinkedToMixed = new ONLinkedToList(); #region Treatment of LinkedTo foreach(KeyValuePair<ONPath, ONOid> lDictionaryEntry in linkedTo) { ONPath lPath = lDictionaryEntry.Key as ONPath; ONOid lOid = lDictionaryEntry.Value as ONOid; ONPath lInversePath = new ONPath(ONInstance.InversePath(lTypeInstance, lPath)); Type lTypeTargetClassInstance = ONContext.GetType_Instance(ONInstance.GetTargetClass(OnContext, lTypeInstance, lPath)); if ((lInversePath.Count == 0) || (!ONInstance.IsVisible(lTypeTargetClassInstance, lInversePath, OnContext))) return ONContext.GetComponent_Collection(ClassName, OnContext); bool lexistLV = false; ONData lData = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext); if (lData.GetType().BaseType == typeof(ONLVData)) { if (!lOid.Exist(OnContext, null)) return ONContext.GetComponent_Collection(ClassName, OnContext); } foreach (string lRole in lInversePath.Roles) { lData = ONContext.GetComponent_Data(lData.InhGetTargetClassName(new ONPath(lRole)), OnContext); if (lData.GetType().BaseType == typeof(ONLVData)) lexistLV = true; } if(!lexistLV) lLinkedToLocal.mLinkedToList.Add(lPath, lOid); else lLinkedToMixed.mLinkedToList.Add(lPath, lOid); } #endregion #region displaySet if (!filters.PreloadRelatedAttributes) displaySet = null; #endregion displaySet #region No link item if ((linkedTo.mLinkedToList.Count == 0) || (lLinkedToMixed.mLinkedToList.Count > 0)) { if ((GetType().BaseType != typeof(ONLVData)) || (filters.InData)) lInstances = SolveQuery(new ONLinkedToList(), filters, displaySet, comparer, startRowOid, blockSize); } #endregion #region Local Link if (lLinkedToLocal.mLinkedToList.Count > 0) { ONCollection lInstancesAux = SolveQuery(lLinkedToLocal, filters, displaySet, comparer, startRowOid, blockSize); if (lInstances != null) lInstances.Intersection(lInstancesAux); else lInstances = lInstancesAux; } #endregion #region Hybrid Link if (lLinkedToMixed.mLinkedToList.Count > 0) { ONCollection lInstancesAux = null; foreach(KeyValuePair<ONPath, ONOid> lDictionaryEntry in lLinkedToMixed) { ONPath lPath = lDictionaryEntry.Key as ONPath; ONOid lOid = lDictionaryEntry.Value as ONOid; if (lPath.Roles.Count == 1) { ONLinkedToList lLinked = new ONLinkedToList(); lLinked[lPath] = lOid; ONCollection lInstanceColl = SolveQuery(lLinked, filters, displaySet, comparer, startRowOid, blockSize); if (lInstances != null) lInstances.Intersection(lInstanceColl); else lInstances = lInstanceColl; continue; } #region Optimized Path ONLinkedToList linkedToOptimized = new ONLinkedToList(); ONPath lInversePath = new ONPath(ONInstance.InversePath(lTypeInstance, lPath)); ONPath lOptimizedRole = new ONPath(lInversePath.RemoveHead() as string); Type lTypeInstanceDestiny = ONContext.GetType_Instance(InhGetTargetClassName(lPath)); bool lBeginIsLegacy = (ONInstance.IsLegacy(lTypeInstanceDestiny, lOptimizedRole)); bool lEnterLoop = true; ONData lData = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext); if(lData.GetType().BaseType != typeof(ONLVData)) if (ONContext.GetType_Data(lData.InhGetTargetClassName(lOptimizedRole)).BaseType == typeof(ONLVData)) lEnterLoop = false; lPath.RemoveTail(); if (lEnterLoop) { while (lInversePath.Roles.Count > 0) { lData = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext); if ((!lBeginIsLegacy) && (ONContext.GetType_Data(lData.InhGetTargetClassName(new ONPath(lInversePath.Roles[0]))).BaseType == typeof(ONLVData))) break; if ((lBeginIsLegacy) && (ONContext.GetType_Data(lData.InhGetTargetClassName(new ONPath(lInversePath.Roles[0]))).BaseType != typeof(ONLVData))) break; lOptimizedRole.Roles.Add(lInversePath.RemoveHead()); lPath.RemoveTail(); } } linkedToOptimized[ONInstance.InversePath(lTypeInstanceDestiny, lOptimizedRole)] = lOid; if ((lPath.Count > 0) || (lBeginIsLegacy)) // It is not the last role or it is leged lInstancesAux = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext).ExecuteQuery(linkedToOptimized, null, null, comparer, startRowOid, blockSize); else // It is the last role and it is local lInstancesAux = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext).ExecuteQuery(linkedToOptimized, null, displaySet, comparer, startRowOid, blockSize); #endregion #region Rest of the path lInstancesAux = lInstancesAux[lInversePath] as ONCollection; #endregion if (lInstances != null) lInstances.Intersection(lInstancesAux); else lInstances = lInstancesAux; } } #endregion return lInstances; } catch (Exception e) { string ltraceItem = "Method: SolveQuery, Component: ONDBData"; if (e is ONSystemException) { ONSystemException lException = e as ONSystemException; lException.addTraceInformation(ltraceItem); throw lException; } throw new ONSystemException(e, ltraceItem); } }
/// <summary> This method adds the order criteria to the SQL statement </summary> /// <param name="onSql"> This parameter represents the SQL component </param> /// <param name="comparer"> This parameter has all the information refering to the order criteria to add to SQL statement</param> /// <param name="startRowOid">This parameter has the OID necessary to start the search</param> /// <param name="blockSize">This parameter represents the number of instances to be returned</param> public void AddOrderCriteria(ONSqlSelect onSql, ONOrderCriteria comparer, ONOid startRowOid, int blockSize) { AddOrderCriteria(onSql, comparer, startRowOid, blockSize, null); }
/// <summary> /// Retrieve all the instances of a determinate class that fulfil a determinate formula of searching /// </summary> /// <param name="linkedTo">List to reach the class to retrieve the related instance</param> /// <param name="filters">Formula to search concrete instances</param> /// <param name="comparer">Order Criteria that must be followed by the query</param> /// <param name="startRowOID">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> public abstract ONCollection ExecuteQuery(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize);
public override ONCollection ExecuteQuery(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize) { ONCollection lInstances = null; Type lTypeInstance = ONContext.GetType_Instance(ClassName); ONLinkedToList lLinkedToLegacy = new ONLinkedToList(); ONLinkedToList lLinkedToLocal = new ONLinkedToList(); if (linkedTo == null) linkedTo = new ONLinkedToList(); if (filters == null) filters = new ONFilterList(); #region Treatment of LinkedTo foreach (KeyValuePair<ONPath, ONOid> lDictionaryEntry in linkedTo) { ONPath lPath = lDictionaryEntry.Key as ONPath; ONOid lOid = lDictionaryEntry.Value as ONOid; if (ONInstance.IsLegacy(lTypeInstance, lPath)) lLinkedToLegacy.mLinkedToList.Add(lPath, lOid); else lLinkedToLocal.mLinkedToList.Add(lPath, lOid); } #endregion Treatment of LinkedTo ONFilterList lFiltersToLegacy = new ONFilterList(); ONFilterList lFiltersToLocal = new ONFilterList(); #region Treatment of Filters ONFilterList lFiltersToMixed = new ONFilterList(); foreach (ONFilter lFilter in filters.Values) { if (lFilter.InLegacy) lFiltersToLegacy.Add(lFilter.FilterName, lFilter); else lFiltersToLocal.Add(lFilter.FilterName, lFilter); } #endregion Treatment of Filters if ((lFiltersToLegacy.Count <= 1) && (lFiltersToLocal.Count == 0) && (lLinkedToLocal.mLinkedToList.Count == 0)) { #region No leged filters if (lFiltersToLegacy.Count == 0) { QueryByRelatedFilter lFilter = new QueryByRelatedFilter(ClassName, null, null); lInstances = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, startRowOid, (blockSize == 0 ? 0 : blockSize + 1)); } #endregion No leged filters #region Solve leged filters foreach (ONFilter lFilter in lFiltersToLegacy.Values) { ONCollection lInstancesAux = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, startRowOid, (blockSize == 0 ? 0 : blockSize + 1)); if (lInstances == null) lInstances = lInstancesAux; else lInstances.Intersection(lInstancesAux); } #endregion Solve leged filters if ((lInstances.totalNumInstances == -1) && (lInstances.Count <= blockSize) && ((startRowOid == null).TypedValue)) lInstances.totalNumInstances = lInstances.Count; } else { #region Solve leged filters foreach (ONFilter lFilter in lFiltersToLegacy.Values) { ONCollection lInstancesAux = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, null, 0); if (lInstances == null) lInstances = lInstancesAux; else lInstances.Intersection(lInstancesAux); } #endregion Solve leged filters #region Solve local filters in data if ((lFiltersToLocal.InData) || (lLinkedToLocal.mLinkedToList.Count > 0)) { ONCollection lInstancesAux = base.ExecuteQuery(lLinkedToLocal, lFiltersToLocal, displaySet, null, null, 0); if (lInstances == null) lInstances = lInstancesAux; else lInstances.Intersection(lInstancesAux); } #endregion Solve local filters in data #region No leged filters if (lFiltersToLegacy.Count == 0) { int maxNumberQueries = Convert.ToInt32(ONContext.GetType_LV(ClassName).GetField("maxNumberQueries").GetValue(null)); if ((lInstances == null || lInstances.Count > maxNumberQueries) || (lLinkedToLegacy.mLinkedToList.Count > 0) || (comparer != null)) { ONCollection lInstancesAux = lInstances; QueryByRelatedFilter lFilter = new QueryByRelatedFilter(ClassName, null, null); lInstances = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, null, 0); if (lInstancesAux != null) lInstances.Intersection(lInstancesAux); } else { ONCollection lInstancesAux = ONContext.GetComponent_Collection(ClassName, OnContext); foreach (object lobject in lInstances) { ONInstance lInstance = lobject as ONInstance; QueryByOidFilter lFilter = new QueryByOidFilter(lInstance.Oid); lInstancesAux.AddRange(lFilter.FilterInLegacy(OnContext, null, null, null, 0)); } lInstances = lInstancesAux.Clone() as ONCollection; } } #endregion No leged filters #region Solve local filters in memory if ((lInstances != null) && (lFiltersToLocal.InMemory)) { ONCollection lInstancesAux = lInstances; lInstances = ONContext.GetComponent_Collection(ClassName, OnContext); foreach (ONInstance lInstance in lInstancesAux) if (lFiltersToLocal.FilterInMemory(lInstance)) lInstances.Add(lInstance); } #endregion Solve local filters in memory lInstances.totalNumInstances = lInstances.Count; } return lInstances; }
public virtual ONCollection ExecuteQuery(ONSql onSql, ONFilterList onFilterList, ONOrderCriteria comparer, ONOid startRowOID, int blockSize, ONInstance instance) { return null; }
public virtual ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList lLinkedToList, ONOrderCriteria comparer, ONOid startRowOid, int blockSize) { return(null); }
public virtual ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList lLinkedToList, ONOrderCriteria comparer, ONOid startRowOid, int blockSize) { return null; }
/// <summary> /// This method recovers an instance with the OID /// </summary> /// <param name="onContext">Recovers the context of the execution of the service</param> /// <param name="linkedTo">List to reach the class to retrieve the related instance</param> /// <param name="comparer">Order Criteria that must be followed</param> /// <param name="${startRowOid}">OID frontier</param> /// <param name="blockSize">Number of instances to be returned</param> /// <returns>The instance</returns> public override ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList linkedTo, ONOrderCriteria comparer, ONOid startRowOID, int blockSize) { if (InData) { return(null); } // Add parameters object[] lParameters = new object[2]; lParameters[0] = onContext; lParameters[1] = mOid; ONCollection lCollection = ONContext.GetComponent_Collection(mOid.ClassName, onContext); ONInstance lInstance = ONContext.InvoqueMethod(ONContext.GetType_LV(mOid.ClassName), "QueryByOid", lParameters) as ONInstance; if (lInstance != null) { lCollection.Add(lInstance); } return(lCollection); }