Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        public override object Clone()
        {
            ONCollection lCollection = ONContext.GetComponent_Collection(ClassName, OnContext);

            lCollection.Union(this);

            return(lCollection);
        }
Esempio n. 3
0
        public static ONCollection operator +(ONCollection collection, ONInstance instance)
        {
            ONCollection lCollection = ONContext.GetComponent_Collection(collection.ClassName, collection.OnContext);

            lCollection.Union(collection);
            lCollection.Add(instance);

            return(lCollection);
        }
Esempio n. 4
0
        public static ONCollection Intersection(ONCollection collection1, ONCollection collection2)
        {
            ONCollection lCollection = ONContext.GetComponent_Collection(collection1.ClassName, collection1.OnContext);

            if ((collection1 == null) || (collection2 == null))
            {
                return(lCollection);
            }

            foreach (ONInstance lInstance in collection1)
            {
                if (!collection2.Contains(lInstance))
                {
                    lCollection.Add(lInstance);
                }
            }

            return(lCollection);
        }
        /// <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);
        }
Esempio n. 6
0
        /// <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);
            }
        }
Esempio n. 7
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);
        }