/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="groupBean"> /// The group Bean. /// </param> /// <param name="info"> /// The current data retrieval state /// </param> /// <returns> /// The string containing the SQL query that needs to be executed on the dissemination database, in order to return the data required by the input query /// </returns> private static string GenerateGroupSql(GroupInformation groupBean, DataRetrievalInfoSeries info) { MappingSetEntity mappingSet = info.MappingSet; Logger.Info(Resources.InfoBeginGenerateSql); SqlQuery sqlQuery = new SqlQuery(); string sql = string.Empty; try { // Generate Query subparts sql = GenerateSelect(true, ConvertToMapping(groupBean.ComponentMappings)); sqlQuery.appendSql(sql); sqlQuery.appendSql(GenerateFrom(mappingSet)); if (string.IsNullOrEmpty(info.SqlWhereCache)) { info.SqlWhereCache = GenerateWhere(info); } sqlQuery.appendSql(info.SqlWhereCache); // In SDMX Group we don't care if it is flat or not. sqlQuery.appendSql(GenerateOrderBy(info, groupBean.ThisGroup.Dimensions)); } catch (Exception ex) { Logger.Error(ex.ToString()); throw new DataRetrieverException(ex, SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.SemanticError), Resources.ErrorUnableToGenerateSQL); //ErrorTypes.QUERY_PARSING_ERROR, Resources.ErrorUnableToGenerateSQL, ex); } // log for easy debug Logger.Info(string.Format(CultureInfo.InvariantCulture, Resources.InfoGeneratedSQLFormat1, sql)); Logger.Info(Resources.InfoEndGenerateSql); return sqlQuery.getSql(); }
/// <summary> /// Add <paramref name="componentMapping"/> to <see cref="_groups"/> /// </summary> /// <param name="componentMapping"> /// The group level attribute <see cref="IComponentMapping"/> /// </param> private void AddTimeSeriesGroups(IComponentMapping componentMapping) { foreach (var groupEntity in componentMapping.Component.AttAssignmentGroups) { GroupInformation information; if (!this._groups.TryGetValue(groupEntity, out information)) { information = new GroupInformation(groupEntity); this._groups.Add(groupEntity, information); } information.ComponentMappings.Add(componentMapping); } }
/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="groupBean"> /// The group Bean. /// </param> /// <param name="info"> /// The current data retrieval state /// </param> /// <returns> /// The string containing the SQL query that needs to be executed on the dissemination database, in order to return the data required by the input query /// </returns> private static string GenerateGroupSql(GroupInformation groupBean, DataRetrievalInfoSeries info) { MappingSetEntity mappingSet = info.MappingSet; Logger.Info(Resources.InfoBeginGenerateSql); SqlQuery sqlQuery = new SqlQuery(); string sql = string.Empty; try { // Generate Query subparts sql = GenerateSelect(true, ConvertToMapping(groupBean.ComponentMappings)); sqlQuery.appendSql(sql); sqlQuery.appendSql(GenerateFrom(mappingSet)); if (string.IsNullOrEmpty(info.SqlWhereCache)) { info.SqlWhereCache = GenerateWhere(info); } sqlQuery.appendSql(info.SqlWhereCache); bool bFlat = false; var allDimensions = DimensionAtObservation.GetFromEnum(DimensionAtObservationEnumType.All).Value; IBaseDataQuery baseDataQuery = (IBaseDataQuery)info.ComplexQuery ?? info.Query; //the Flat option will be read only when we have flat aka AllDimensions if (baseDataQuery.DimensionAtObservation.Equals(allDimensions)) Boolean.TryParse(ConfigurationManager.AppSettings["QueryFlatFormat"], out bFlat); if (!bFlat) sqlQuery.appendSql(GenerateOrderBy(info, groupBean.ThisGroup.Dimensions)); } catch (Exception ex) { Logger.Error(ex.ToString()); throw new DataRetrieverException(ex, SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.SemanticError), Resources.ErrorUnableToGenerateSQL); //ErrorTypes.QUERY_PARSING_ERROR, Resources.ErrorUnableToGenerateSQL, ex); } // log for easy debug Logger.Info(string.Format(CultureInfo.InvariantCulture, Resources.InfoGeneratedSQLFormat1, sql)); Logger.Info(Resources.InfoEndGenerateSql); return sqlQuery.getSql(); }