public QueryByOidFilter(ONOid oid) : base(oid.ClassName, "QueryByOid") { mOid = oid; Type lDataType = ONContext.GetType_Data(ClassName); InMemory = false; InData = !lDataType.IsSubclassOf(typeof(ONLVData)); InLegacy = lDataType.IsSubclassOf(typeof(ONLVData)); }
public QueryByRelatedFilter(string className, ONPath onPath, ONOid relatedOid) : base(className, "QueryByRelated") { ONPath = onPath; mRelatedOid = relatedOid; Type lDataType = ONContext.GetType_Data(ClassName); InMemory = false; InData = !lDataType.IsSubclassOf(typeof(ONLVData)); InLegacy = lDataType.IsSubclassOf(typeof(ONLVData)); }
/// <summary>This method adds to the SQL statement any path that appears in a formula</summary> /// <param name="onSql">This parameter has the current SQL statement</param> /// <param name="joinType">This parameter has the type of join</param> /// <param name="facet">First class, the beginning of the path</param> /// <param name="onPath">Path to add to SQL statement</param> /// <param name="processedOnPath">Path pocessed until the call of this method</param> /// <param name="initialClass">Domain of the object valued argument, object valued filter variables or AGENT when it should be necessary</param> /// <param name="forceLastAlias">Create almost the last alias in the sql</param> /// <param name="isLinkedTo">The alias belongs to a role in a linked To element</param> public static string AddPath(ONSqlSelect onSql, JoinType joinType, string facet, ONPath onPath, ONPath processedOnPath, string initialClass, bool forceLastAlias, bool isLinkedTo) { // initialClass is used for Object-valued arguments, object-valued filter variables, agent instance, ... ONPath lProcessedOnPath = new ONPath(processedOnPath); ONPath lOnPath = new ONPath(onPath); bool lOnPathExist = true; object[] lParameters = new object[8]; if (initialClass != "") { string lRol = lOnPath.RemoveHead(); lProcessedOnPath += lRol; // Solve path with initialPath lParameters[0] = onSql; lParameters[1] = joinType; lParameters[2] = facet; lParameters[3] = lOnPath; lParameters[4] = lProcessedOnPath; lParameters[5] = ""; lParameters[6] = forceLastAlias; lParameters[7] = isLinkedTo; return(ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string); } // Search max solved path ONPath lMaxSolvedPath = new ONPath(onPath); string lMaxSolvedPathDomain = facet; while ((lMaxSolvedPath.Count > 0) && (onSql.GetAlias(lMaxSolvedPathDomain, lProcessedOnPath + lMaxSolvedPath, isLinkedTo) == "")) { lMaxSolvedPath.RemoveTail(); lMaxSolvedPathDomain = GetTargetClassName(lMaxSolvedPath); } if (lMaxSolvedPath.Count > 0) { lProcessedOnPath += lMaxSolvedPath; for (int i = 0; i < lMaxSolvedPath.Count; i++) { lOnPath.RemoveHead(); } lParameters[0] = onSql; lParameters[1] = joinType; lParameters[2] = facet; lParameters[3] = lOnPath; lParameters[4] = lProcessedOnPath; lParameters[5] = ""; lParameters[6] = forceLastAlias; lParameters[7] = isLinkedTo; return(ONContext.InvoqueMethod(ONContext.GetType_Data(lMaxSolvedPathDomain), "AddPath", lParameters) as string); } // Create inheritance path if ((onPath == null) || (onPath.Count == 0)) { if (forceLastAlias) { return(AeronaveFacetAddSql(joinType, onSql, processedOnPath, forceLastAlias, isLinkedTo)); } if ((processedOnPath == null) || (processedOnPath.Count == 0)) { return(onSql.CreateAlias(joinType, "", CtesBD.TBL_AERONAVE, null, "Aeronave", false, isLinkedTo)); } else { return(onSql.CreateAlias(joinType, "", CtesBD.TBL_AERONAVE, processedOnPath, "Aeronave", false, isLinkedTo)); } } // Calculate processed path string lRole = lOnPath.RemoveHead() as string; lProcessedOnPath += lRole; // Search Path if (lOnPath.Count == 0) { string lAlias = onSql.GetAlias(facet, lProcessedOnPath, isLinkedTo); if ((lAlias != "") && (!forceLastAlias)) { return(lAlias); } else { lOnPathExist = false; } } else { string lTargetClass = GetTargetClassName(new ONPath(lRole)); // Agent & OV Argument Control if ((lTargetClass == "") && (initialClass != "")) { lTargetClass = initialClass; } string lAlias = onSql.GetAlias(lTargetClass, lProcessedOnPath, isLinkedTo); if (lAlias == "") { lOnPathExist = false; } } // Create path if (string.Compare(lRole, "PasajeroAeronave", true) == 0) { if (lOnPathExist) { return(PasajeroAeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias, isLinkedTo)); } else { return(PasajeroAeronaveRoleAddSql(onSql, joinType, facet, lOnPath, processedOnPath, lRole, forceLastAlias, isLinkedTo)); } } initialClass = "Aeronave"; // Solve path with initialPath lParameters[0] = onSql; lParameters[1] = joinType; lParameters[2] = facet; lParameters[3] = lOnPath; lParameters[4] = lProcessedOnPath; lParameters[5] = ""; lParameters[6] = forceLastAlias; lParameters[7] = isLinkedTo; return(ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string); }
/// <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>This method adds to the SQL statement any path that appears in a formula</summary> /// <param name="onSql">This parameter has the current SQL statement</param> /// <param name="joinType">This parameter has the type of join</param> /// <param name="facet">First class, the beginning of the path</param> /// <param name="onPath">Path to add to SQL statement</param> /// <param name="processedOnPath">Path pocessed until the call of this method</param> /// <param name="initialClass">Domain of the object valued argument, object valued filter variables or AGENT when it should be necessary</param> /// <param name="forceLastAlias">Create almost the last alias in the sql</param> public static string AddPath(ONSqlSelect onSql, JoinType joinType, string facet, ONPath onPath, ONPath processedOnPath, string initialClass, bool forceLastAlias) { // initialClass is used for Object-valued arguments, object-valued filter variables, agent instance, ... ONPath lProcessedOnPath = new ONPath(processedOnPath); ONPath lOnPath = new ONPath(onPath); // Calculate processed path string lRole = lOnPath.RemoveHead() as string; lProcessedOnPath += lRole; // Search Path if (lOnPath.Count == 0) { string lAlias = onSql.GetAlias(facet, lProcessedOnPath); if ((lAlias != "") && (!forceLastAlias)) { return(lAlias); } } // Create path if (initialClass == "") // Simple paths { if (string.Compare(lRole, "NaveNodriza", true) == 0) { return(NaveNodrizaData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias)); } if (string.Compare(lRole, "Aeronave", true) == 0) { return(AeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias)); } if (string.Compare(lRole, "Pasajero", true) == 0) { return(PasajeroData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias)); } if (string.Compare(lRole, "PasajeroAeronave", true) == 0) { return(PasajeroAeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias)); } if (string.Compare(lRole, "Revision", true) == 0) { return(RevisionData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias)); } if (string.Compare(lRole, "RevisionPasajero", true) == 0) { return(RevisionPasajeroData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias)); } if (string.Compare(lRole, "Administrador", true) == 0) { return(AdministradorData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias)); } } // Solve path with initialPath object[] lParameters = new object[6]; lParameters[0] = onSql; lParameters[1] = facet; lParameters[2] = lOnPath; lParameters[3] = lProcessedOnPath; lParameters[4] = ""; lParameters[5] = forceLastAlias; return(ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string); }