Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        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);
        }