/// <summary> /// Converts the instances returned by a query in XML format in order to put it in XML message response /// </summary> /// <param name="agentOid">OID with the agent connected to the system</param> /// <param name="xmlWriter">This parameter has the response message XML</param> /// <param name="val">Instances that fullfils with the query request</param> /// <param name="startRowOID">OID necessary to start the search</param> /// <param name="blockSize">Represents the number of instances to be returned</param> /// <param name="displaySet">Attributes to be returned in the response</param> /// <param name="dtdVersion">Version of DTD that follows the XML message</param> public override void ONQuery2XML(ONOid agentOid, XmlWriter xmlWriter, ONCollection val, ONOid startRowOID, int blockSize, ONDisplaySet displaySet, double dtdVersion) { xmlWriter.WriteStartElement("Head"); xmlWriter.WriteStartElement("Head.OID"); xmlWriter.WriteAttributeString("Class", "Pasajero"); xmlWriter.WriteStartElement("Head.OID.Field"); xmlWriter.WriteAttributeString("Name", "id_Pasajero"); xmlWriter.WriteAttributeString("Type", "autonumeric"); xmlWriter.WriteEndElement(); // Head.OID.Field xmlWriter.WriteEndElement(); // Head.OID xmlWriter.WriteStartElement("Head.Cols"); foreach (ONDisplaySetItem lDisplaySetItem in displaySet) { xmlWriter.WriteStartElement("Head.Col"); xmlWriter.WriteAttributeString("Name", lDisplaySetItem.Path); string lType = ONInstance.GetTypeOfAttribute(typeof(PasajeroInstance), new ONPath(lDisplaySetItem.Path)); if (lType == "") { lType = "string"; } xmlWriter.WriteAttributeString("Type", lType); xmlWriter.WriteEndElement(); // Head.Col } xmlWriter.WriteEndElement(); // Head.Cols xmlWriter.WriteEndElement(); // Head // Search StartRow int i = 0; if (startRowOID != null) { i = val.IndexOf(startRowOID) + 1; } // Instance count int lInstances = 0; int lNumInstances = 0; string lLastBlock = "True"; if (i >= 0) { lNumInstances = val.Count - i; if ((blockSize > 0) && (lNumInstances > blockSize)) { lNumInstances = blockSize; lLastBlock = "False"; } } xmlWriter.WriteStartElement("Data"); xmlWriter.WriteAttributeString("Rows", lNumInstances.ToString()); xmlWriter.WriteAttributeString("LastBlock", lLastBlock); xmlWriter.WriteAttributeString("TotalRows", val.totalNumInstances.ToString()); while ((lInstances++ < lNumInstances) && (i < val.Count)) { PasajeroInstance lInstance = val[i++] as PasajeroInstance; xmlWriter.WriteStartElement("R"); ONXmlAutonumeric.ON2XML(xmlWriter, lInstance.Oid.Id_PasajeroAttr, dtdVersion, ONXml.XMLTAG_O); foreach (ONDisplaySetItem lDisplaySetItem in displaySet) { if (lDisplaySetItem.Visibility == VisibilityState.NotChecked) { if (ONInstance.IsVisible(lInstance.GetType(), lDisplaySetItem.Path, lInstance.OnContext)) { lDisplaySetItem.Visibility = VisibilityState.Visible; } else { lDisplaySetItem.Visibility = VisibilityState.NotVisible; } } if (lDisplaySetItem.Visibility == VisibilityState.NotVisible) // No Visibility { xmlWriter.WriteElementString("V", null); } else { ONSimpleType lAttribute; if (lDisplaySetItem.HasHV) { lAttribute = lInstance.DisplaysetItemValue(lDisplaySetItem.Path); } else { lAttribute = lInstance[lDisplaySetItem.Path] as ONSimpleType; } if (lAttribute is ONInt) { ONXmlInt.ON2XML(xmlWriter, lAttribute as ONInt, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONString) { ONXmlString.ON2XML(xmlWriter, lAttribute as ONString, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONBlob) { ONXmlBlob.ON2XML(xmlWriter, lAttribute as ONBlob, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONBool) { ONXmlBool.ON2XML(xmlWriter, lAttribute as ONBool, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONReal) { ONXmlReal.ON2XML(xmlWriter, lAttribute as ONReal, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONInt) { ONXmlAutonumeric.ON2XML(xmlWriter, lAttribute as ONInt, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONDate) { ONXmlDate.ON2XML(xmlWriter, lAttribute as ONDate, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONDateTime) { ONXmlDateTime.ON2XML(xmlWriter, lAttribute as ONDateTime, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONTime) { ONXmlTime.ON2XML(xmlWriter, lAttribute as ONTime, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONNat) { ONXmlNat.ON2XML(xmlWriter, lAttribute as ONNat, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONText) { ONXmlText.ON2XML(xmlWriter, lAttribute as ONText, dtdVersion, ONXml.XMLTAG_V); } else if (lAttribute is ONString) { ONXmlPassword.ON2XML(xmlWriter, lAttribute as ONString, dtdVersion, ONXml.XMLTAG_V); } } } xmlWriter.WriteEndElement(); // R } xmlWriter.WriteEndElement(); // Data }
/// <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); } }