/// <summary> /// Returns the instance with the Oid /// </summary> /// <param name="oid">OID to search the instance</param> /// <param name="onFilterList">Filters to theck</param> /// <returns>The instance searched</returns> public override ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet) { ONSqlSelect lOnSql = new ONSqlSelect(); // Create select and first table InhRetrieveInstances(lOnSql, displaySet, null, OnContext); // Fix instance InhFixInstance(lOnSql, null, null, oid); // Add filter formula onFilterList.FilterInData(lOnSql, this); // Execute ONCollection lCollection = ExecuteSql(lOnSql, onFilterList, displaySet, null, null, 0); if (lCollection.Count > 0) { return(lCollection[0] as ONInstance); } else { return(null); } }
/// <summary> /// Searchs a determinate instance /// </summary> /// <param name="oid">OID to search the instance</param> /// <param name="onFilterList">Filter list</param> public override ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet) { ONFilterList lOnFilterList = null; if (onFilterList != null) { lOnFilterList = new ONFilterList(onFilterList); } else { lOnFilterList = new ONFilterList(); } lOnFilterList.Add("QueryByOid", new QueryByOidFilter(oid)); ONCollection lCollection = ExecuteQuery(new ONLinkedToList(), lOnFilterList, displaySet, null, null, 0); if (lCollection.Count > 0) { return(lCollection[0] as ONInstance); } else { return(null); } }
/// <summary> /// Load the data retrieved from the Data Base to components of the application /// </summary> /// <param name="onContext">This parameter has the current context</param> /// <param name="columns">This parameter has the data collected from the database</param> /// <param name="index">This parameter has the position of the first data to fix in the application</param> public static AeronaveInstance LoadFacet(ONContext onContext, ONDisplaySet displaySet, object[] columns, ref int index) { AeronaveInstance lInstance = new AeronaveInstance(onContext); lInstance.Oid = new AeronaveOid(); // Field 'id_Aeronave' lInstance.Oid.Id_AeronaveAttr = new ONInt(Convert.ToInt32(columns[index++])); lInstance.StateObj = new ONString(((string)columns[index++]).TrimEnd()); lInstance.Lmd = new ONDateTime((DateTime)columns[index++]); // Field 'MaximoPasajeros' lInstance.MaximoPasajerosAttr = new ONInt(Convert.ToInt32(columns[index++])); if ((displaySet != null) && (displaySet.Contains("Nombre"))) { lInstance.NombreAttr = new ONText((string)columns[index++]); } if ((displaySet != null) && (displaySet.Contains("Origen"))) { lInstance.OrigenAttr = new ONText((string)columns[index++]); } if ((displaySet != null) && (displaySet.Contains("Destino"))) { lInstance.DestinoAttr = new ONText((string)columns[index++]); } lInstance.Modified = false; return(lInstance); }
public void LoadRelated(ONContext onContext, ONDisplaySet displaySet, object[] columns, int index, ONInstance instance) { // Related attributes for (; index < displaySet.ElementsInData; index++) { ONDisplaySetItem lDSItem = displaySet[index]; string lTypeName = ONInstance.GetTypeOfAttribute(instance.GetType(), new ONPath(lDSItem.Path)); instance.RelatedValues.Add(lDSItem.Path, ONDBData.GetBasicTypeFromDB(lTypeName, columns[index])); } }
public static string RetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { string lAlias = onSql.CreateAlias(CtesBD.TBL_REVISION, onPath, "Revision"); ONDisplaySet lSourceDS = null; if (displaySet != null) { lSourceDS = new ONDisplaySet(displaySet); displaySet.Clear(); } if (displaySet == null) { onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISION_ID_REVISARAERONAVE + ", " + lAlias + "." + CtesBD.FLD_REVISION_ESTADOOBJ + ", " + lAlias + "." + CtesBD.FLD_REVISION_FUM + ", " + lAlias + "." + CtesBD.FLD_REVISION_NOMBREREVISOR + ", " + lAlias + "." + CtesBD.FLD_REVISION_FECHAREVISION + ", " + lAlias + "." + CtesBD.FLD_REVISION_ID_AERONAVE); } else { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISION_ID_REVISARAERONAVE)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISION_ID_REVISARAERONAVE); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISION_ESTADOOBJ)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISION_ESTADOOBJ); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISION_FUM)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISION_FUM); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISION_NOMBREREVISOR)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISION_NOMBREREVISOR); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISION_FECHAREVISION)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISION_FECHAREVISION); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISION_ID_AERONAVE)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISION_ID_AERONAVE); } // Related attributes if (displaySet != null) { foreach (ONDisplaySetItem lDisplaySetItem in lSourceDS) { if ((lDisplaySetItem.Path.IndexOf(".") > 0) && (lDisplaySetItem.InData) && (!lDisplaySetItem.HasHV)) { displaySet.Add(lDisplaySetItem); string lPath = lDisplaySetItem.Path.Substring(0, lDisplaySetItem.Path.LastIndexOf(".")); string lFacetName = RevisionInstance.GetTargetClass(onContext, typeof(RevisionInstance), new ONPath(lDisplaySetItem.Path)); onSql.AddSelect(AddPath(onSql, JoinType.LeftJoin, lFacetName, new ONPath(lPath), onPath, "", false) + "." + ONInstance.GetFieldNameOfAttribute(typeof(RevisionInstance), new ONPath(lDisplaySetItem.Path))); } } } return(lAlias); }
public static string RetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { string lAlias = onSql.CreateAlias(CtesBD.TBL_PASAJERO, onPath, "Pasajero"); ONDisplaySet lSourceDS = null; if (displaySet != null) { lSourceDS = new ONDisplaySet(displaySet); displaySet.Clear(); } if (displaySet == null) { onSql.AddSelect(lAlias + "." + CtesBD.FLD_PASAJERO_ID_PASAJERO + ", " + lAlias + "." + CtesBD.FLD_PASAJERO_ESTADOOBJ + ", " + lAlias + "." + CtesBD.FLD_PASAJERO_FUM); } else { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_PASAJERO_ID_PASAJERO)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_PASAJERO_ID_PASAJERO); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_PASAJERO_ESTADOOBJ)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_PASAJERO_ESTADOOBJ); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_PASAJERO_FUM)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_PASAJERO_FUM); if (lSourceDS.Contains(CtesBD.FLD_PASAJERO_NOMBRE)) { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_PASAJERO_NOMBRE)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_PASAJERO_NOMBRE); } } // Related attributes if (displaySet != null) { foreach (ONDisplaySetItem lDisplaySetItem in lSourceDS) { if ((lDisplaySetItem.Path.IndexOf(".") > 0) && (lDisplaySetItem.InData) && (!lDisplaySetItem.HasHV)) { displaySet.Add(lDisplaySetItem); string lPath = lDisplaySetItem.Path.Substring(0, lDisplaySetItem.Path.LastIndexOf(".")); string lFacetName = PasajeroInstance.GetTargetClass(onContext, typeof(PasajeroInstance), new ONPath(lDisplaySetItem.Path)); onSql.AddSelect(AddPath(onSql, JoinType.LeftJoin, lFacetName, new ONPath(lPath), onPath, "", false) + "." + ONInstance.GetFieldNameOfAttribute(typeof(PasajeroInstance), new ONPath(lDisplaySetItem.Path))); } } } return(lAlias); }
/// <summary> /// Load the data retrieved from the Data Base to components of the application /// </summary> /// <param name="onContext">This parameter has the current context</param> /// <param name="columns">This parameter has the data collected from the database</param> /// <param name="index">This parameter has the position of the first data to fix in the application</param> public static NaveNodrizaInstance LoadFacet(ONContext onContext, ONDisplaySet displaySet, object[] columns, ref int index) { NaveNodrizaInstance lInstance = new NaveNodrizaInstance(onContext); lInstance.Oid = new NaveNodrizaOid(); // Field 'id_NaveNodriza' lInstance.Oid.Id_NaveNodrizaAttr = new ONInt(Convert.ToInt32(columns[index++])); lInstance.StateObj = new ONString(((string)columns[index++]).TrimEnd()); lInstance.Lmd = new ONDateTime((DateTime)columns[index++]); // Field 'Nombre_NaveNodriza' lInstance.Nombre_NaveNodrizaAttr = new ONString(((string)columns[index++]).TrimEnd()); lInstance.Modified = false; return(lInstance); }
/// <summary> /// Load the data retrieved from the Data Base to components of the application /// </summary> /// <param name="onContext">This parameter has the current context</param> /// <param name="columns">This parameter has the data collected from the database</param> /// <param name="index">This parameter has the position of the first data to fix in the application</param> public static AdministradorInstance LoadFacet(ONContext onContext, ONDisplaySet displaySet, object[] columns, ref int index) { AdministradorInstance lInstance = new AdministradorInstance(onContext); lInstance.Oid = new AdministradorOid(); // Field 'id_Administrador' lInstance.Oid.Id_AdministradorAttr = new ONInt(Convert.ToInt32(columns[index++])); // Field 'PassWord' lInstance.PassWordAttr = new ONString(((string)columns[index++]).TrimEnd()); lInstance.StateObj = new ONString(((string)columns[index++]).TrimEnd()); lInstance.Lmd = new ONDateTime((DateTime)columns[index++]); lInstance.Modified = false; return(lInstance); }
/// <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 PasajeroHorizontalVisibility()); // Linked To List if (linkedTo == null) linkedTo = new ONLinkedToList(); // Call Data try { PasajeroData lData = new PasajeroData(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: PasajeroQuery"; if (e is ONSystemException) { ONSystemException lException = e as ONSystemException; lException.addTraceInformation(ltraceItem); throw lException; } throw new ONSystemException(e, ltraceItem); } } }
/// <summary> /// Load the data retrieved from the Data Base to components of the application /// </summary> /// <param name="onContext">This parameter has the current context</param> /// <param name="columns">This parameter has the data collected from the database</param> /// <param name="index">This parameter has the position of the first data to fix in the application</param> public static RevisionInstance LoadFacet(ONContext onContext, ONDisplaySet displaySet, object[] columns, ref int index) { RevisionInstance lInstance = new RevisionInstance(onContext); lInstance.Oid = new RevisionOid(); // Field 'id_RevisarAeronave' lInstance.Oid.Id_RevisarAeronaveAttr = new ONInt(Convert.ToInt32(columns[index++])); lInstance.StateObj = new ONString(((string)columns[index++]).TrimEnd()); lInstance.Lmd = new ONDateTime((DateTime)columns[index++]); // Field 'NombreRevisor' lInstance.NombreRevisorAttr = new ONString(((string)columns[index++]).TrimEnd()); // Field 'FechaRevision' lInstance.FechaRevisionAttr = new ONDate(Convert.ToDateTime(columns[index++])); // Field 'Id_Aeronave' lInstance.Id_AeronaveAttr = new ONString(((string)columns[index++]).TrimEnd()); lInstance.Modified = false; return(lInstance); }
/// <summary> /// Treatment of the XML message that has a query request /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <param name="xmlReader">Variable with the message XML to be treated</param> /// <param name="xmlWriter">Variable with the message XML to response</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> public void XMLRequestQuery(ref string ticket, ONOid agentOID, XmlTextReader xmlReader, out XmlTextWriter xmlWriter, double dtdVersion, string clientName) { try { // Read Request ONDisplaySet lDisplaySet; using (ONContext lOnContext = new ONContext()) { lOnContext.OidAgent = agentOID; lDisplaySet = new ONDisplaySet(ClassName, xmlReader.GetAttribute("DisplaySet"), lOnContext.LeafActiveAgentFacets); } ONDisplaySet lDSRequested = new ONDisplaySet(lDisplaySet); xmlReader.ReadStartElement("Query.Request"); // Create XMLWriterRequest MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Query.Response"); // Get start row & block size ONCollection lCollection = null; ONOid lStartRowOID = null; int lBlockSize = 1; // Execute if (xmlReader.IsStartElement("Query.Instance")) // QueryByOID { // Read Request xmlReader.ReadStartElement("Query.Instance"); if (xmlReader.IsStartElement(ONXml.XMLTAG_ALTERNATEKEY)) { lCollection = QueryByAlternateKey(ref ticket, ref agentOID, xmlReader, lDisplaySet, dtdVersion, clientName); } else { lCollection = QueryByOid(ref ticket, ref agentOID, xmlReader, lDisplaySet, dtdVersion, clientName); } } else if (xmlReader.IsStartElement("Query.Related")) // QueryByRelated { lCollection = QueryByRelated(ref ticket, ref agentOID, xmlReader, lDisplaySet, out lStartRowOID, out lBlockSize, dtdVersion, clientName); } else if (xmlReader.IsStartElement("Query.Filter")) // QueryByFilter { // Read Request string lFilterName = xmlReader.GetAttribute("Name"); object[] ParametersList = new object[8]; ParametersList[0] = ticket; ParametersList[1] = agentOID; ParametersList[2] = xmlReader; ParametersList[3] = lDisplaySet; ParametersList[4] = lStartRowOID; ParametersList[5] = lBlockSize; ParametersList[6] = dtdVersion; ParametersList[7] = clientName; // Execute lCollection = ONContext.InvoqueMethod(this, typeof(ONFilterXMLAttribute), "<Filter>" + lFilterName + "</Filter>", ParametersList) as ONCollection; ticket = ParametersList[0] as string; agentOID = ParametersList[1] as ONOid; lStartRowOID = ParametersList[4] as ONOid; lBlockSize = (int)ParametersList[5]; } // Generate response ONQuery2XML(agentOID, xmlWriter, lCollection, lStartRowOID, lBlockSize, lDSRequested, dtdVersion); lCollection.Dispose(); // Read Request xmlReader.ReadEndElement(); // Query.Request // Write Response xmlWriter.WriteEndElement(); // Query.Response } catch (ONException e) { MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Query.Response"); CreateXMLError(xmlWriter, e, dtdVersion); xmlWriter.WriteEndElement(); // Query.Response return; } catch (Exception e) { string message = e.Message; MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Query.Response"); xmlWriter.WriteStartElement("Error"); xmlWriter.WriteAttributeString("Type", "External"); xmlWriter.WriteAttributeString("Number", "999"); if (dtdVersion <= 2) { xmlWriter.WriteString(e.Message); } else { if ((e is ONSystemException) || (e.InnerException is ONSystemException)) { ONSystemException lException = null; if (e is ONSystemException) { lException = e as ONSystemException; } else { lException = e.InnerException as ONSystemException; } ArrayList trace = lException.mTraceInformation; xmlWriter.WriteElementString("Error.Message", message); xmlWriter.WriteElementString("Error.Params", ""); xmlWriter.WriteStartElement("Error.Trace"); int length = trace.Count; int i = 0; while (length > 0) { string mensaje = (string)trace[length - 1]; xmlWriter.WriteStartElement("Error.TraceItem"); xmlWriter.WriteAttributeString("Type", "External"); xmlWriter.WriteAttributeString("Number", i.ToString()); xmlWriter.WriteStartElement("Error.Message"); xmlWriter.WriteString(mensaje); xmlWriter.WriteEndElement(); // Error.Message xmlWriter.WriteElementString("Error.Params", ""); xmlWriter.WriteEndElement(); // Error.TraceItem i += 1; length -= 1; } xmlWriter.WriteEndElement(); // Error.Trace } else { xmlWriter.WriteElementString("Error.Message", message); xmlWriter.WriteElementString("Error.Params", ""); xmlWriter.WriteElementString("Error.Trace", ""); } } xmlWriter.WriteEndElement(); // Error xmlWriter.WriteEndElement(); // Query.Response return; } }
/// <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); } }
public static string RetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { string lAlias = onSql.CreateAlias(CtesBD.TBL_AERONAVE, onPath, "Aeronave"); ONDisplaySet lSourceDS = null; if(displaySet != null) { lSourceDS = new ONDisplaySet(displaySet); displaySet.Clear(); } if (displaySet == null) onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_ID_AERONAVE + ", " + lAlias + "." + CtesBD.FLD_AERONAVE_ESTADOOBJ + ", " + lAlias + "." + CtesBD.FLD_AERONAVE_FUM + ", " + lAlias + "." + CtesBD.FLD_AERONAVE_MAXIMOPASAJEROS); else { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_AERONAVE_ID_AERONAVE)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_ID_AERONAVE); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_AERONAVE_ESTADOOBJ)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_ESTADOOBJ); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_AERONAVE_FUM)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_FUM); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_AERONAVE_MAXIMOPASAJEROS)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_MAXIMOPASAJEROS); if (lSourceDS.Contains(CtesBD.FLD_AERONAVE_NOMBRE)) { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_AERONAVE_NOMBRE)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_NOMBRE); } if (lSourceDS.Contains(CtesBD.FLD_AERONAVE_ORIGEN)) { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_AERONAVE_ORIGEN)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_ORIGEN); } if (lSourceDS.Contains(CtesBD.FLD_AERONAVE_DESTINO)) { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_AERONAVE_DESTINO)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_AERONAVE_DESTINO); } } // Related attributes if (displaySet != null) { foreach (ONDisplaySetItem lDisplaySetItem in lSourceDS) { if((lDisplaySetItem.Path.IndexOf(".") > 0) && (lDisplaySetItem.InData) && (! lDisplaySetItem.HasHV)) { displaySet.Add(lDisplaySetItem); string lPath = lDisplaySetItem.Path.Substring(0, lDisplaySetItem.Path.LastIndexOf(".")); string lFacetName = AeronaveInstance.GetTargetClass(onContext, typeof(AeronaveInstance), new ONPath(lDisplaySetItem.Path)); onSql.AddSelect(AddPath(onSql, JoinType.LeftJoin, lFacetName, new ONPath(lPath), onPath, "", false) + "." + ONInstance.GetFieldNameOfAttribute(typeof(AeronaveInstance), new ONPath(lDisplaySetItem.Path))); } } } return (lAlias); }
/// <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; }
public void LoadRelated(ONContext onContext, ONDisplaySet displaySet, object[] columns, int index, ONInstance instance) { // Related attributes for (; index < displaySet.ElementsInData; index++) { ONDisplaySetItem lDSItem = displaySet[index]; string lTypeName = ONInstance.GetTypeOfAttribute(instance.GetType(), new ONPath(lDSItem.Path)); instance.RelatedValues.Add(lDSItem.Path, ONDBData.GetBasicTypeFromDB(lTypeName, columns[index])); } }
public static string RetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { string lAlias = onSql.CreateAlias(CtesBD.TBL_NAVENODRIZA, onPath, "NaveNodriza"); ONDisplaySet lSourceDS = null; if(displaySet != null) { lSourceDS = new ONDisplaySet(displaySet); displaySet.Clear(); } if (displaySet == null) onSql.AddSelect(lAlias + "." + CtesBD.FLD_NAVENODRIZA_ID_NAVENODRIZA + ", " + lAlias + "." + CtesBD.FLD_NAVENODRIZA_ESTADOOBJ + ", " + lAlias + "." + CtesBD.FLD_NAVENODRIZA_FUM + ", " + lAlias + "." + CtesBD.FLD_NAVENODRIZA_NOMBRE_NAVENODRIZA); else { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_NAVENODRIZA_ID_NAVENODRIZA)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_NAVENODRIZA_ID_NAVENODRIZA); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_NAVENODRIZA_ESTADOOBJ)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_NAVENODRIZA_ESTADOOBJ); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_NAVENODRIZA_FUM)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_NAVENODRIZA_FUM); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_NAVENODRIZA_NOMBRE_NAVENODRIZA)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_NAVENODRIZA_NOMBRE_NAVENODRIZA); } // Related attributes if (displaySet != null) { foreach (ONDisplaySetItem lDisplaySetItem in lSourceDS) { if((lDisplaySetItem.Path.IndexOf(".") > 0) && (lDisplaySetItem.InData) && (! lDisplaySetItem.HasHV)) { displaySet.Add(lDisplaySetItem); string lPath = lDisplaySetItem.Path.Substring(0, lDisplaySetItem.Path.LastIndexOf(".")); string lFacetName = NaveNodrizaInstance.GetTargetClass(onContext, typeof(NaveNodrizaInstance), new ONPath(lDisplaySetItem.Path)); onSql.AddSelect(AddPath(onSql, JoinType.LeftJoin, lFacetName, new ONPath(lPath), onPath, "", false) + "." + ONInstance.GetFieldNameOfAttribute(typeof(NaveNodrizaInstance), new ONPath(lDisplaySetItem.Path))); } } } return (lAlias); }
/// <summary> /// Searchs a determinate instance /// </summary> /// <param name="oid">OID to search the instance</param> /// <param name="onFilterList">Filter list</param> public override ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet) { ONFilterList lOnFilterList = null; if (onFilterList != null) lOnFilterList = new ONFilterList(onFilterList); else lOnFilterList = new ONFilterList(); lOnFilterList.Add("QueryByOid", new QueryByOidFilter(oid)); ONCollection lCollection = ExecuteQuery(new ONLinkedToList(), lOnFilterList, displaySet, null, null, 0); if (lCollection.Count > 0) return lCollection[0] as ONInstance; else return null; }
/// <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); }
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); }
/// <summary> /// Returns the instance with the Oid /// </summary> /// <param name="oid">OID to search the instance</param> /// <param name="onFilterList">Filters to theck</param> /// <returns>The instance searched</returns> public abstract ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet);
/// <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);
/// <summary> /// Method to convert the data providen by the system to a message with XML format.Is empty, it implementation is done in child classes /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <param name="xmlWriter">Variable with the message XML to be treated</param> /// <param name="val">Variable with the message XML to be treated</param> /// <param name="startRowOID">OID to start the searching</param> /// <param name="blockSize">Number of instance to be retrieved for the query</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> public virtual void ONQuery2XML(ONOid agentOID, XmlWriter xmlWriter, ONCollection val, ONOid startRowOID, int blockSize, ONDisplaySet displaySet, double dtdVersion) { }
/// <summary> /// Process the XML message that is a search of instances related with an instance. /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <param name="xmlReader">Variable with the message XML to be treated</param> /// <param name="startRowOID">OID to start the searching</param> /// <param name="blockSize">Number of instance to be retrieved for the query</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> public virtual ONCollection QueryByRelated(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, out ONOid startRowOID, out int blockSize, double dtdVersion, string clientName) { startRowOID = null; blockSize = -1; return(null); }
/// <summary> /// Process the XML message that is a search of an instance with an alternate key. Is empty, its implementation is done in child classes /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <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 virtual ONCollection QueryByAlternateKey(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, double dtdVersion, string clientName) { return(null); }
/// <summary> /// Process the request dedicated to loof for an instance with an OID given /// </summary> /// <param name="agentOid">OID with the agent connected to the system</param> /// <param name="xmlReader">XML with the request message</param> /// <param name="dtdVersion">Version of DTD that follows the XML message</param> public override ONCollection QueryByOid(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, double dtdVersion, string clientName) { // Get OID class string lClass = xmlReader.GetAttribute("Class"); // Set OID parameter ONOid lOID = XML2ON(xmlReader, dtdVersion); // Read Request xmlReader.ReadEndElement(); // Query.Instance // Read Order Criteria if (xmlReader.IsStartElement("Sort")) // Sort xmlReader.Skip(); //Read Filter Navigation if (xmlReader.IsStartElement("NavFilt")) xmlReader.Skip(); // Create Context ONContext lOnContext = new ONContext(); lOnContext.OidAgent = agentOid; // Execute PasajeroQuery lQuery = new PasajeroQuery(lOnContext); ONCollection lCollection = lQuery.QueryByOid(lOID, displaySet); ticket = lOnContext.GetTicket(dtdVersion, clientName); return lCollection; }
/// <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> /// Method to convert the data providen by the system to a message with XML format.Is empty, it implementation is done in child classes /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <param name="xmlWriter">Variable with the message XML to be treated</param> /// <param name="val">Variable with the message XML to be treated</param> /// <param name="startRowOID">OID to start the searching</param> /// <param name="blockSize">Number of instance to be retrieved for the query</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> public virtual void ONQuery2XML(ONOid agentOID, XmlWriter xmlWriter, ONCollection val, ONOid startRowOID, int blockSize, ONDisplaySet displaySet, double dtdVersion) { }
/// <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); } }
public ONCollection QueryByRelated(ONLinkedToList linkedTo, ONDisplaySet displaySet, string orderCriteria, ONOid startRowOID, int blockSize) { return QueryByFilter(linkedTo, null, displaySet, orderCriteria, startRowOID, blockSize); }
public virtual string InhRetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { return(""); }
/// <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> /// 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 virtual string InhRetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { return ""; }
public override string InhRetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { return RetrieveInstances(onSql, displaySet, onPath, onContext); }
/// <summary> /// Returns the instance with the Oid /// </summary> /// <param name="oid">OID to search the instance</param> /// <param name="onFilterList">Filters to theck</param> /// <returns>The instance searched</returns> public override ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet) { ONSqlSelect lOnSql = new ONSqlSelect(); // Create select and first table InhRetrieveInstances(lOnSql, displaySet, null, OnContext); // Fix instance InhFixInstance(lOnSql, null, null, oid); // Add filter formula onFilterList.FilterInData(lOnSql, this); // Execute ONCollection lCollection = ExecuteSql(lOnSql, onFilterList, displaySet, null, null, 0); if (lCollection.Count > 0) return lCollection[0] as ONInstance; else return null; }
public override string InhRetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { return(RetrieveInstances(onSql, displaySet, onPath, onContext)); }
/// <summary> /// Load the data retrieved from the Data Base to components of the application /// </summary> /// <param name="onContext">This parameter has the current context</param> /// <param name="columns">This parameter has the data collected from the database</param> /// <param name="index">This parameter has the position of the first data to fix in the application</param> public static AeronaveInstance LoadFacet(ONContext onContext, ONDisplaySet displaySet, object[] columns, ref int index) { AeronaveInstance lInstance = new AeronaveInstance(onContext); lInstance.Oid = new AeronaveOid(); // Field 'id_Aeronave' lInstance.Oid.Id_AeronaveAttr = new ONInt(Convert.ToInt32(columns[index++])); lInstance.StateObj = new ONString(((string) columns[index++]).TrimEnd()); lInstance.Lmd = new ONDateTime((DateTime) columns[index++]); // Field 'MaximoPasajeros' lInstance.MaximoPasajerosAttr = new ONInt(Convert.ToInt32(columns[index++])); if ((displaySet != null) && (displaySet.Contains("Nombre"))) { lInstance.NombreAttr = new ONText((string) columns[index++]); } if ((displaySet != null) && (displaySet.Contains("Origen"))) { lInstance.OrigenAttr = new ONText((string) columns[index++]); } if ((displaySet != null) && (displaySet.Contains("Destino"))) { lInstance.DestinoAttr = new ONText((string) columns[index++]); } lInstance.Modified = false; return lInstance; }
/// <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> /// 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; }
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; }
/// <summary> /// Returns the instance with the Oid /// </summary> /// <param name="oid">OID to search the instance</param> /// <param name="onFilterList">Filters to theck</param> /// <returns>The instance searched</returns> public abstract ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet);
/// <summary> /// Process the XML message that is a search of instances related with an instance. /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <param name="xmlReader">Variable with the message XML to be treated</param> /// <param name="startRowOID">OID to start the searching</param> /// <param name="blockSize">Number of instance to be retrieved for the query</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> public virtual ONCollection QueryByRelated(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, out ONOid startRowOID, out int blockSize, double dtdVersion, string clientName) { startRowOID = null; blockSize = -1; return null; }
/// <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> /// Process the request dedicated to loof for an instance with an OID given /// </summary> /// <param name="agentOid">OID with the agent connected to the system</param> /// <param name="xmlReader">XML with the request message</param> /// <param name="dtdVersion">Version of DTD that follows the XML message</param> public override ONCollection QueryByOid(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, double dtdVersion, string clientName) { // Get OID class string lClass = xmlReader.GetAttribute("Class"); // Set OID parameter ONOid lOID = XML2ON(xmlReader, dtdVersion); // Read Request xmlReader.ReadEndElement(); // Query.Instance // Read Order Criteria if (xmlReader.IsStartElement("Sort")) // Sort { xmlReader.Skip(); } //Read Filter Navigation if (xmlReader.IsStartElement("NavFilt")) { xmlReader.Skip(); } // Create Context ONContext lOnContext = new ONContext(); lOnContext.OidAgent = agentOid; // Execute PasajeroQuery lQuery = new PasajeroQuery(lOnContext); ONCollection lCollection = lQuery.QueryByOid(lOID, displaySet); ticket = lOnContext.GetTicket(dtdVersion, clientName); return(lCollection); }
public ONCollection QueryByFilter_LMD(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["LMD"] = GetFilter_LMD(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 } //Read Filter Navigation if (xmlReader.IsStartElement("NavFilt")) xmlReader.Skip(); // Create Context ONContext lOnContext = new ONContext(); lOnContext.OidAgent = agentOid; // 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; }
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); }
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; }
public static string RetrieveInstances(ONSqlSelect onSql, ONDisplaySet displaySet, ONPath onPath, ONContext onContext) { string lAlias = onSql.CreateAlias(CtesBD.TBL_REVISIONPASAJERO, onPath, "RevisionPasajero"); ONDisplaySet lSourceDS = null; if(displaySet != null) { lSourceDS = new ONDisplaySet(displaySet); displaySet.Clear(); } if (displaySet == null) onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_ID_REVISIONPASAJERO + ", " + lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_FK_REVISION_1 + ", " + lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_FK_PASAJEROAERO_1 + ", " + lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_ESTADOOBJ + ", " + lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_FUM); else { displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISIONPASAJERO_ID_REVISIONPASAJERO)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_ID_REVISIONPASAJERO); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISIONPASAJERO_FK_REVISION_1)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_FK_REVISION_1); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISIONPASAJERO_FK_PASAJEROAERO_1)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_FK_PASAJEROAERO_1); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISIONPASAJERO_ESTADOOBJ)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_ESTADOOBJ); displaySet.Add(new ONDisplaySetItem(CtesBD.FLD_REVISIONPASAJERO_FUM)); onSql.AddSelect(lAlias + "." + CtesBD.FLD_REVISIONPASAJERO_FUM); } // Related attributes if (displaySet != null) { foreach (ONDisplaySetItem lDisplaySetItem in lSourceDS) { if((lDisplaySetItem.Path.IndexOf(".") > 0) && (lDisplaySetItem.InData) && (! lDisplaySetItem.HasHV)) { displaySet.Add(lDisplaySetItem); string lPath = lDisplaySetItem.Path.Substring(0, lDisplaySetItem.Path.LastIndexOf(".")); string lFacetName = RevisionPasajeroInstance.GetTargetClass(onContext, typeof(RevisionPasajeroInstance), new ONPath(lDisplaySetItem.Path)); onSql.AddSelect(AddPath(onSql, JoinType.LeftJoin, lFacetName, new ONPath(lPath), onPath, "", false) + "." + ONInstance.GetFieldNameOfAttribute(typeof(RevisionPasajeroInstance), new ONPath(lDisplaySetItem.Path))); } } } return (lAlias); }
/// <summary> /// Process the XML message that is a search of an instance with their OID. Is empty, it implementation is done in child classes /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <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 virtual ONCollection QueryByOid(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, double dtdVersion, string clientName) { return null; }
/// <summary> /// Load the data retrieved from the Data Base to components of the application /// </summary> /// <param name="onContext">This parameter has the current context</param> /// <param name="columns">This parameter has the data collected from the database</param> /// <param name="index">This parameter has the position of the first data to fix in the application</param> public static NaveNodrizaInstance LoadFacet(ONContext onContext, ONDisplaySet displaySet, object[] columns, ref int index) { NaveNodrizaInstance lInstance = new NaveNodrizaInstance(onContext); lInstance.Oid = new NaveNodrizaOid(); // Field 'id_NaveNodriza' lInstance.Oid.Id_NaveNodrizaAttr = new ONInt(Convert.ToInt32(columns[index++])); lInstance.StateObj = new ONString(((string) columns[index++]).TrimEnd()); lInstance.Lmd = new ONDateTime((DateTime) columns[index++]); // Field 'Nombre_NaveNodriza' lInstance.Nombre_NaveNodrizaAttr = new ONString(((string) columns[index++]).TrimEnd()); lInstance.Modified = false; return lInstance; }
/// <summary> /// Treatment of the XML message that has a query request /// </summary> /// <param name="agentOID">OID of the agent connected to the system</param> /// <param name="xmlReader">Variable with the message XML to be treated</param> /// <param name="xmlWriter">Variable with the message XML to response</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> public void XMLRequestQuery(ref string ticket, ONOid agentOID, XmlTextReader xmlReader, out XmlTextWriter xmlWriter, double dtdVersion, string clientName) { try { // Read Request ONDisplaySet lDisplaySet; using (ONContext lOnContext = new ONContext()) { lOnContext.OidAgent = agentOID; lDisplaySet = new ONDisplaySet(ClassName, xmlReader.GetAttribute("DisplaySet"), lOnContext.LeafActiveAgentFacets); } ONDisplaySet lDSRequested = new ONDisplaySet(lDisplaySet); xmlReader.ReadStartElement("Query.Request"); // Create XMLWriterRequest MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Query.Response"); // Get start row & block size ONCollection lCollection = null; ONOid lStartRowOID = null; int lBlockSize = 1; // Execute if (xmlReader.IsStartElement("Query.Instance")) // QueryByOID { // Read Request xmlReader.ReadStartElement("Query.Instance"); if (xmlReader.IsStartElement(ONXml.XMLTAG_ALTERNATEKEY)) lCollection = QueryByAlternateKey(ref ticket, ref agentOID, xmlReader, lDisplaySet, dtdVersion, clientName); else lCollection = QueryByOid(ref ticket, ref agentOID, xmlReader, lDisplaySet, dtdVersion, clientName); } else if (xmlReader.IsStartElement("Query.Related")) // QueryByRelated lCollection = QueryByRelated(ref ticket, ref agentOID, xmlReader, lDisplaySet, out lStartRowOID, out lBlockSize, dtdVersion, clientName); else if (xmlReader.IsStartElement("Query.Filter")) // QueryByFilter { // Read Request string lFilterName = xmlReader.GetAttribute("Name"); object[] ParametersList = new object[8]; ParametersList[0] = ticket; ParametersList[1] = agentOID; ParametersList[2] = xmlReader; ParametersList[3] = lDisplaySet; ParametersList[4] = lStartRowOID; ParametersList[5] = lBlockSize; ParametersList[6] = dtdVersion; ParametersList[7] = clientName; // Execute lCollection = ONContext.InvoqueMethod(this, typeof (ONFilterXMLAttribute), "<Filter>" + lFilterName + "</Filter>", ParametersList) as ONCollection; ticket = ParametersList[0] as string; agentOID = ParametersList[1] as ONOid; lStartRowOID = ParametersList[4] as ONOid; lBlockSize = (int) ParametersList[5]; } // Generate response ONQuery2XML(agentOID, xmlWriter, lCollection, lStartRowOID, lBlockSize, lDSRequested, dtdVersion); lCollection.Dispose(); // Read Request xmlReader.ReadEndElement(); // Query.Request // Write Response xmlWriter.WriteEndElement(); // Query.Response } catch (ONException e) { MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Query.Response"); CreateXMLError(xmlWriter, e, dtdVersion); xmlWriter.WriteEndElement(); // Query.Response return; } catch (Exception e) { string message = e.Message; MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Query.Response"); xmlWriter.WriteStartElement("Error"); xmlWriter.WriteAttributeString("Type", "External"); xmlWriter.WriteAttributeString("Number", "999"); if (dtdVersion <= 2) { xmlWriter.WriteString(e.Message); } else { if ((e is ONSystemException) || (e.InnerException is ONSystemException)) { ONSystemException lException = null; if (e is ONSystemException) lException = e as ONSystemException; else lException = e.InnerException as ONSystemException; ArrayList trace = lException.mTraceInformation; xmlWriter.WriteElementString("Error.Message", message); xmlWriter.WriteElementString("Error.Params", ""); xmlWriter.WriteStartElement("Error.Trace"); int length = trace.Count; int i = 0; while (length > 0) { string mensaje = (string)trace[length - 1]; xmlWriter.WriteStartElement("Error.TraceItem"); xmlWriter.WriteAttributeString("Type", "External"); xmlWriter.WriteAttributeString("Number", i.ToString()); xmlWriter.WriteStartElement("Error.Message"); xmlWriter.WriteString(mensaje); xmlWriter.WriteEndElement(); // Error.Message xmlWriter.WriteElementString("Error.Params", ""); xmlWriter.WriteEndElement(); // Error.TraceItem i += 1; length -= 1; } xmlWriter.WriteEndElement(); // Error.Trace } else { xmlWriter.WriteElementString("Error.Message", message); xmlWriter.WriteElementString("Error.Params", ""); xmlWriter.WriteElementString("Error.Trace", ""); } } xmlWriter.WriteEndElement(); // Error xmlWriter.WriteEndElement(); // Query.Response return; } }
public ONCollection GetPopulation(ONDisplaySet displaySet, string orderCriteria, ONOid startRowOID, int blockSize) { return QueryByFilter(null, null, displaySet, orderCriteria, startRowOID, blockSize); }
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); }
public abstract ONCollection QueryByFilter(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, string orderCriteria, ONOid startRowOID, int blockSize);
/// <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 }
public ONCollection QueryByOid(ONOid oid, ONDisplaySet displaySet) { //Create filters ONFilterList lOnFilterList = new ONFilterList(); lOnFilterList.Add("QueryByOid", new QueryByOidFilter(oid)); return QueryByFilter(null, lOnFilterList, displaySet, null, null, 0); }