示例#1
0
 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);
     }
 }
示例#2
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);
            }
        }
示例#3
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);
        }
示例#4
0
        public ONCollection QueryByFilter_FUM(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, out ONOid startRowOID, out int blockSize, double dtdVersion, string clientName)
        {
            ONLinkedToList lLinkedTo = null;
            ONFilterList   lFilters  = new ONFilterList();

            // Read Request
            blockSize = int.Parse(xmlReader.GetAttribute("BlockSize"));
            if (!xmlReader.IsEmptyElement)
            {
                xmlReader.ReadStartElement("Query.Filter");
                if (xmlReader.IsStartElement("StartRow"))
                {
                    xmlReader.ReadStartElement("StartRow");
                    startRowOID = XML2ON(xmlReader, dtdVersion);
                    xmlReader.ReadEndElement();                     // StartRow
                }
                else
                {
                    startRowOID = null;
                }

                // Fill relations
                lLinkedTo = GetLinkedTo(xmlReader, dtdVersion);

                // Fill filter variables
                lFilters["FUM"] = GetFilter_FUM(xmlReader, dtdVersion);

                // Read Request
                xmlReader.ReadEndElement();                 // Query.Filter
            }
            else
            {
                xmlReader.ReadStartElement("Query.Filter");
                lLinkedTo   = new ONLinkedToList();
                startRowOID = null;
            }

            // Read Order Criteria
            string lOrderCriteria = "";

            if (xmlReader.IsStartElement("Sort"))
            {
                lOrderCriteria = xmlReader.GetAttribute("Criterium");
                xmlReader.Skip();                 // Sort
            }

            // Create Context
            ONContext lOnContext = new ONContext();

            lOnContext.OidAgent = agentOid;

            // Execute
            PasajeroQuery lQuery      = new PasajeroQuery(lOnContext);
            ONCollection  lCollection = lQuery.QueryByFilter(lLinkedTo, lFilters, displaySet, lOrderCriteria, startRowOID, blockSize);

            ticket = lOnContext.GetTicket(dtdVersion, clientName);

            return(lCollection);
        }
        /// <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);
                }
            }
        }
示例#6
0
        public PasajeroAeronaveCollection PasajeroAeronaveRoleHV()
        {
            PasajeroAeronaveData ldata = new PasajeroAeronaveData(OnContext);

            //Fix related instance
            ONLinkedToList lLinkedTo = new ONLinkedToList();

            lLinkedTo["Aeronave"] = Oid;

            ONFilterList lFilterList = new ONFilterList();

            lFilterList.Add("HorizontalVisibility", new PasajeroAeronaveHorizontalVisibility());

            //Execute
            return(ldata.ExecuteQuery(lLinkedTo, lFilterList, null, null, null, 1) as PasajeroAeronaveCollection);
        }
        public RevisionPasajeroCollection RevisionPasajeroRoleHV()
        {
            RevisionPasajeroData ldata = new RevisionPasajeroData(OnContext);

            //Fix related instance
            ONLinkedToList lLinkedTo = new ONLinkedToList();

            lLinkedTo["Revision"] = Oid;

            ONFilterList lFilterList = new ONFilterList();

            lFilterList.Add("HorizontalVisibility", new RevisionPasajeroHorizontalVisibility());

            //Execute
            return(ldata.ExecuteQuery(lLinkedTo, lFilterList, null, null, null, 1) as RevisionPasajeroCollection);
        }
        /// <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);
        }
示例#9
0
        /// <summary>
        /// Fix related instance
        /// </summary>
        /// <param name="onSql">Sentence SQL to be executed</param>
        /// <param name="linkedTo">List to reach the class to retrieve the related instance</param>
        protected bool AddLinkedTo(ONSqlSelect onSql, ONLinkedToList linkedTo)
        {
            // Fix related instance
            foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in linkedTo)
            {
                ONPath lPath = lDictionaryEntry.Key as ONPath;
                ONOid  lOID  = lDictionaryEntry.Value as ONOid;

                string lAliasRelated = InhAddPath(onSql, lOID.ClassName, lPath, "", true);

                // Check Visibility
                if (!ONInstance.IsVisibleInv(ONContext.GetType_Instance(ClassName), lPath, OnContext))
                {
                    return(false);
                }

                ONDBData lData = ONContext.GetComponent_Data(lOID.ClassName, OnContext) as ONDBData;
                lData.InhFixInstance(onSql, null, lPath, lOID, true);
            }

            return(true);
        }
示例#10
0
        /// <summary>
        /// Treatment the part of the XML message that has links items
        /// </summary>
        /// <param name="xmlReader">Variable with the message XML to be treated</param>
        /// <param name="dtdVersion">Version of the DTD that follows the XML message</param>
        public ONLinkedToList GetLinkedTo(XmlReader xmlReader, double dtdVersion)
        {
            ONLinkedToList lLinkedToList = new ONLinkedToList();

            if (!xmlReader.IsStartElement("LinkedTo"))
            {
                return(lLinkedToList);
            }

            if (xmlReader.IsEmptyElement)
            {
                xmlReader.ReadStartElement("LinkedTo");
                return(lLinkedToList);
            }

            xmlReader.ReadStartElement("LinkedTo");
            while (xmlReader.IsStartElement("Link.Item"))
            {
                ONPath lPath = new ONPath(xmlReader.GetAttribute("Role"));
                xmlReader.ReadStartElement("Link.Item");

                object[] lParam = new object[2];
                lParam[0] = xmlReader;
                lParam[1] = dtdVersion;

                string lClassInstance = xmlReader.GetAttribute("Class");
                ONOid  lInstance      = ONContext.InvoqueMethod(ONContext.GetType_XML(lClassInstance), "XML2ON", lParam) as ONOid;

                lLinkedToList[lPath] = lInstance;

                xmlReader.ReadEndElement();         // Link.Item
            }
            xmlReader.ReadEndElement();             // LinkedTo

            return(lLinkedToList);
        }
示例#11
0
        public override ONCollection QueryByRelated(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, out ONOid startRowOID, out int blockSize, double dtdVersion, string clientName)
        {
            ONLinkedToList lLinkedTo = null;
            ONFilterList   lFilters  = new ONFilterList();

            // Read Request
            blockSize = int.Parse(xmlReader.GetAttribute("BlockSize"));
            if (!xmlReader.IsEmptyElement)
            {
                xmlReader.ReadStartElement("Query.Related");
                if (xmlReader.IsStartElement("StartRow"))
                {
                    xmlReader.ReadStartElement("StartRow");
                    startRowOID = XML2ON(xmlReader, dtdVersion);
                    xmlReader.ReadEndElement();                     // StartRow
                }
                else
                {
                    startRowOID = null;
                }

                // Fill relations
                lLinkedTo = GetLinkedTo(xmlReader, dtdVersion);

                // Read Request
                xmlReader.ReadEndElement();                 // Query.Related
            }
            else
            {
                xmlReader.ReadStartElement("Query.Related");
                lLinkedTo   = new ONLinkedToList();
                startRowOID = null;
            }

            // Read Order Criteria
            string lOrderCriteria = "";

            if (xmlReader.IsStartElement("Sort"))
            {
                lOrderCriteria = xmlReader.GetAttribute("Criterium");
                xmlReader.Skip();                 // Sort
            }

            //Read Navigational Filter
            string lNavFilterId    = "";
            ONOid  lSelectedObject = null;

            if (xmlReader.IsStartElement("NavFilt"))
            {
                xmlReader.ReadStartElement("NavFilt");
                if (xmlReader.IsStartElement("NavFilt.SelectedObject"))
                {
                    lNavFilterId = xmlReader.GetAttribute("NavFilterID");
                    xmlReader.ReadStartElement("NavFilt.SelectedObject");
                    string lClassName = xmlReader.GetAttribute("Class");
                    if (lClassName == "")
                    {
                        lClassName = "GlobalTransaction";
                    }
                    object[] lArgs = new object[2];
                    lArgs[0]        = xmlReader;
                    lArgs[1]        = dtdVersion;
                    lSelectedObject = ONContext.InvoqueMethod(ONContext.GetType_XML(lClassName), "XML2ON", lArgs) as ONOid;

                    lArgs    = new Object[1];
                    lArgs[0] = lSelectedObject;

                    lFilters.Add(lNavFilterId, ONContext.GetComponent_NavigationalFilter(lNavFilterId, lArgs) as ONFilter);
                }
                else if (xmlReader.IsStartElement("NavFilt.Argument"))
                {
                    string lClassName = xmlReader.GetAttribute("Class");
                    if (lClassName == "")
                    {
                        lClassName = "GlobalTransaction";
                    }
                    string lServiceName  = xmlReader.GetAttribute("Service");
                    string lArgumentName = xmlReader.GetAttribute("Argument");
                    xmlReader.ReadStartElement("NavFilt.Argument");

                    string lFilterName = lClassName + "_" + lServiceName + "Service_" + lArgumentName + "_NavigationalFilter";
                    if (xmlReader.IsStartElement("Arguments"))
                    {
                        object[] lArgs = new object[3];
                        lArgs[0] = xmlReader;
                        lArgs[1] = dtdVersion;
                        lArgs[2] = lArgumentName;

                        lFilters.Add(lFilterName, ONContext.InvoqueMethod(ONContext.GetComponent_XML(lClassName), typeof(ONNavigationalFilterXMLAttribute), "<Filter>" + lServiceName + "</Filter>", lArgs) as ONFilter);
                    }
                    else
                    {
                        lFilters.Add(lFilterName, ONContext.GetComponent_Filter(lFilterName, null) as ONFilter);
                    }

                    xmlReader.ReadEndElement();                     //NavFilt.Argument
                }
                else if (xmlReader.IsStartElement("NavFilt.ServiceIU"))
                {
                    lNavFilterId = xmlReader.GetAttribute("NavFilterID");
                    xmlReader.ReadStartElement("NavFilt.ServiceIU");

                    if (xmlReader.IsStartElement("Arguments"))
                    {
                        object[] lArgs = new object[2];
                        lArgs[0] = xmlReader;
                        lArgs[1] = dtdVersion;

                        ONServiceInfo lSInfo = new ONServiceInfo("", "", "", "");
                        lSInfo.XML2ON(xmlReader, dtdVersion, false);

                        HybridDictionary lArguments = new HybridDictionary(true);
                        foreach (ONArgumentInfo lArgument in lSInfo.mArgumentList.Values)
                        {
                            lArguments.Add(lArgument.Name, lArgument.Value);
                        }
                        lFilters.Add(lNavFilterId, ONContext.GetComponent_NavigationalFilter(lNavFilterId, new object[1] {
                            lArguments
                        }) as ONFilter);
                    }
                    else
                    {
                        lFilters.Add(lNavFilterId, ONContext.GetComponent_NavigationalFilter(lNavFilterId, null) as ONFilter);
                    }

                    xmlReader.ReadEndElement();                     //NavFilt.ServiceIU
                }
                else if (xmlReader.IsStartElement("NavFilt.Variable"))
                {
                    string lClassName        = xmlReader.GetAttribute("Class");
                    string lSourceFilterName = xmlReader.GetAttribute("Filter");
                    string lVariableName     = xmlReader.GetAttribute("Variable");

                    xmlReader.ReadStartElement("NavFilt.Variable");
                    string lFilterName = lClassName + "_" + lSourceFilterName + "Filter_" + lVariableName + "_NavigationalFilter";
                    if (xmlReader.IsStartElement("Filter.Variables"))
                    {
                        object[] lArgs = new object[3];
                        lArgs[0] = xmlReader;
                        lArgs[1] = dtdVersion;
                        lArgs[2] = lVariableName;

                        lFilters.Add(lFilterName, ONContext.InvoqueMethod(ONContext.GetComponent_XML(lClassName), typeof(ONNavigationalFilterXMLAttribute), "<Filter>" + lSourceFilterName + "</Filter>", lArgs) as ONFilter);
                    }
                    else
                    {
                        lFilters.Add(lFilterName, ONContext.GetComponent_Filter(lFilterName, null) as ONFilter);
                    }

                    xmlReader.ReadEndElement();                     //NavFilt.Variable
                }
            }

            // Create Context
            ONContext lOnContext = new ONContext();

            lOnContext.OidAgent = agentOid;

            foreach (ONFilter lFilter in lFilters.Values)
            {
                lFilter.CheckFilterVariables(lOnContext);
            }

            // Execute
            lOnContext.CalculateQueryInstancesNumber = true;
            PasajeroQuery lQuery      = new PasajeroQuery(lOnContext);
            ONCollection  lCollection = lQuery.QueryByFilter(lLinkedTo, lFilters, displaySet, lOrderCriteria, startRowOID, blockSize);

            ticket = lOnContext.GetTicket(dtdVersion, clientName);

            return(lCollection);
        }
示例#12
0
 public ONCollection QueryByRelated(ONLinkedToList linkedTo, ONDisplaySet displaySet, string orderCriteria, ONOid startRowOID, int blockSize)
 {
     return(QueryByFilter(linkedTo, null, displaySet, orderCriteria, startRowOID, blockSize));
 }
示例#13
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 abstract ONCollection ExecuteQuery(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize);
示例#14
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);
        }
示例#15
0
 public virtual ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList lLinkedToList, ONOrderCriteria comparer, ONOid startRowOid, int blockSize)
 {
     return(null);
 }
示例#16
0
 public abstract ONCollection QueryByFilter(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, string orderCriteria, ONOid startRowOID, int blockSize);
示例#17
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);
            }
        }