/// <summary> /// Handles the component mapping except for the TimeDimension when TRANSCODING is used /// </summary> /// <param name="reader">The IDataReader to read data from DDB</param> /// <param name="componentValues">The collection to store the component values</param> /// <param name="componentMappings">Component mappings list</param> /// <param name="info">The data retrieval information.</param> /// <returns> /// True all components were mapped - false when an unmapped code was found /// </returns> protected static bool HandleComponentMapping(IDataReader reader, IMappedValues componentValues, IList<IComponentMapping> componentMappings, DataRetrievalInfo info) { var dimensionAtObservationMapping = info.DimensionAtObservationMapping; for (int index = 0; index < componentMappings.Count; index++) { var componentMapping = componentMappings[index]; var val = componentMapping.MapComponent(reader); if (val != null) { componentValues.Add(index, val); if (componentMapping.Component.FrequencyDimension) { componentValues.FrequencyValue = val; } if (componentMapping.Equals(dimensionAtObservationMapping)) { componentValues.DimensionAtObservationValue = val; } } else { return false; } } return true; }
/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="info"> /// The current state of the data retrieval which containts the current query and mapping set /// </param> public void GenerateSql(DataRetrievalInfo info) { var seriesInfo = info as DataRetrievalInfoSeries; if (seriesInfo == null) { throw new ArgumentException("seriesInfo is not of DataRetrievalInfoSeries type"); } GenerateDataSetSql(seriesInfo); }
/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="info"> /// The current state of the data retrieval which containts the current query and mapping set /// </param> public void GenerateSql(DataRetrievalInfo info) { var seriesInfo = info as DataRetrievalInfoSeries; if (seriesInfo == null) { throw new ArgumentException("seriesInfo is not of DataRetrievalInfoSeries type"); } // generate sql queries for groups foreach (var groupEntity in seriesInfo.Groups) { var information = groupEntity.Value; information.SQL = GenerateGroupSql(information, seriesInfo); } }
/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="info"> /// The current state of the data retrieval which containts the current query and mapping set /// </param> public void GenerateSql(DataRetrievalInfo info) { Logger.Info(Resources.InfoBeginGenerateSql); var seriesInfo = info as DataRetrievalInfoSeries; if (seriesInfo == null) { throw new ArgumentException("seriesInfo is not of DataRetrievalInfoSeries type"); } SqlQuery sqlQuery = new SqlQuery(); string sql = string.Empty; try { sql = GenerateSelect(false, seriesInfo.ComponentMapping.Values); sqlQuery.appendSql(sql); sqlQuery.appendSql(GenerateFrom(seriesInfo.MappingSet)); AppendCachedWhere(seriesInfo, sqlQuery); //sqlQuery.appendSql(GenerateComplexWhere(info)); var orderComponents = _orderedComponentBuilder.Build(seriesInfo); sqlQuery.appendSql(GenerateOrderBy(seriesInfo, orderComponents)); } catch (DataRetrieverException) { throw; } catch (Exception ex) { Logger.Error(ex.ToString()); throw new DataRetrieverException(ex, SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.SemanticError), Resources.ErrorUnableToGenerateSQL); } // log for easy debug Logger.Info(string.Format(CultureInfo.InvariantCulture, Resources.InfoGeneratedSQLFormat1, sql)); Logger.Info(Resources.InfoEndGenerateSql); info.SqlString = sqlQuery.getSql(); }
/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="info"> /// The current state of the data retrieval which containts the current query and mapping set /// </param> public void GenerateSql(DataRetrievalInfo info) { Logger.Info(Resources.InfoBeginGenerateSql); SqlQuery sqlQuery = new SqlQuery(); string sql = string.Empty; try { sql = GenerateSelect(false, info.ComponentMapping.Values); sqlQuery.appendSql(sql); sqlQuery.appendSql(GenerateFrom(info.MappingSet)); if (info.ComplexQuery != null) { sqlQuery.appendSql(GenerateComplexWhere(info)); } else { sqlQuery.appendSql(GenerateWhere(info)); } var orderComponents = _orderedComponentBuilder.Build(info); sqlQuery.appendSql(GenerateOrderBy(info, orderComponents)); } catch (DataRetrieverException dex) { throw new DataRetrieverException(dex, dex.SdmxErrorCode, dex.Message); } catch (Exception ex) { Logger.Error(ex.ToString()); throw new DataRetrieverException(ex, SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.SemanticError), Resources.ErrorUnableToGenerateSQL); } // log for easy debug Logger.Info(string.Format(CultureInfo.InvariantCulture, Resources.InfoGeneratedSQLFormat1, sql)); Logger.Info(Resources.InfoEndGenerateSql); info.SqlString = sqlQuery.getSql(); }
/// <summary> /// Builds an ordered list of Components from the specified <paramref name="info"/> /// </summary> /// <param name="info"> /// The DataRetriever state information. /// </param> /// <returns> /// The list of components. /// </returns> public IList<ComponentEntity> Build(DataRetrievalInfo info) { DsdEntity dsd = info.MappingSet.Dataflow.Dsd; IBaseDataQuery baseDataQuery = (IBaseDataQuery)info.ComplexQuery ?? info.Query; // build a list of the components that that must affect the order, // in the correct order (dimensions, then time) var orderComponents = new List<ComponentEntity>(); var dimensionAtObservation = baseDataQuery.DimensionAtObservation; var allDimensions = DimensionAtObservation.GetFromEnum(DimensionAtObservationEnumType.All).Value; if (dimensionAtObservation.Equals(allDimensions)) { HandleFlat(orderComponents, dsd); } else { HandleOrdered(dsd, dimensionAtObservation, orderComponents); } return orderComponents; }
/// <summary> /// Get a <see cref="IDataQueryEngine"/> implementation based on the specified <paramref name="info"/> /// </summary> /// <param name="info"> /// The current data retrieval state /// </param> /// <returns> /// a <see cref="IDataQueryEngine"/> implementation based on the specified <paramref name="info"/> /// </returns> public IDataQueryEngine GetQueryEngine(DataRetrievalInfo info) { ICollection<MappingEntity> crossSectionalMeasureMappings = info.BuildXSMeasures(); IDataQueryEngine queryEngine = null; if (info.MeasureComponent == null) { if (info.MappingSet.Dataflow.Dsd.CrossSectionalMeasures.Count > 0) { queryEngine = CrossSectionalMeasuresDataQueryEngine.Instance; } else { queryEngine = CrossSectionalPrimaryDataQueryEngine.Instance; } } else if (crossSectionalMeasureMappings.Count > 0) { queryEngine = CrossSectionalMeasuresMappedDataQueryEngine.Instance; } return queryEngine; }
/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="info"> /// The current state of the data retrieval which containts the current query and mapping set /// </param> public void GenerateSql(DataRetrievalInfo info) { MappingSetEntity mappingSet = info.MappingSet; Logger.Info(Resources.InfoBeginGenerateSql); SqlQuery sqlQuery = new SqlQuery(); string sql = string.Empty; try { // Generate Query subparts sql = GenerateSelect(false, info.ComponentMapping.Values); sqlQuery.appendSql(sql); sqlQuery.appendSql(GenerateFrom(mappingSet)); //the WHERE part sqlQuery.appendSql(GenerateWhere(info)); sqlQuery.appendSql(GenerateXSOrderByLocalColumns(info)); } 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); info.SqlString = sqlQuery.getSql(); }
/// <summary> /// Store the SDMX compliant data for each component entity in the store /// </summary> /// <param name="componentValues"> /// The map between components and their values /// </param> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <returns> /// The number of observations stored /// </returns> protected override int StoreResults(IMappedValues componentValues, DataRetrievalInfo info) { var row = componentValues as MappedValues; if (row == null) { throw new ArgumentException("mappedValues not of MappedValues type"); } var seriesInfo = info as DataRetrievalInfoSeries; if (row.IsNewKey()) { TryWriteDataSet(row, seriesInfo); WriteSeries(seriesInfo, row); } return WriteObservation(seriesInfo, row, row.PrimaryMeasureValue.Value); }
/// <summary> /// Store the SDMX compliant data for each component entity in the store /// </summary> /// <param name="componentValues"> /// The map between components and their values /// </param> /// <param name="limit"> /// The limit. /// </param> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <returns> /// The number of observations stored /// </returns> protected override int StoreResults(IMappedValues componentValues, int limit, DataRetrievalInfo info) { return this.StoreResults(componentValues, info); }
/// <summary> /// This method executes an SQL query on the dissemination database and writes it to <see cref="DataRetrievalInfoSeries.SeriesWriter"/> . The SQL query is located inside <paramref name="info"/> at <see cref="DataRetrievalInfo.SqlString"/> /// </summary> /// <exception cref="System.ArgumentNullException"> /// <paramref name="info"/> /// is null /// </exception> /// <exception cref="DataRetrieverException"> /// <see cref="ErrorTypes"/> /// </exception> /// <param name="info"> /// The current DataRetrieval state /// </param> public void ExecuteSqlQuery(DataRetrievalInfo info) { this.ExecuteDbCommand(info); }
/// <summary> /// This method generates the WHERE part of the complex query /// </summary> /// <param name="info"> /// The current data retrieval state /// </param> /// <returns> /// The string containing the required SQL part. For example, "where (FREQ='M')" /// </returns> protected static string GenerateComplexWhere(DataRetrievalInfo info) { IComplexDataQuery query = info.ComplexQuery; Logger.Info(Resources.InfoBeginGenerateWhere); var whereBuilder = new StringBuilder(); if (query != null) { if (query.HasSelections()) { string dimId = ""; if (query.DataStructure.TimeDimension != null) { IList<IDimension> dimLst = query.DataStructure.DimensionList.Dimensions; foreach (IDimension dim in dimLst) { if (dim.FrequencyDimension) { dimId = dim.Id; break; //only one dimension has FrequencyDimension = true so no need to look further } } } IList<IComplexDataQuerySelectionGroup> selGrps = query.SelectionGroups; foreach (IComplexDataQuerySelectionGroup sg in selGrps) { IList<string> freqs = new List<string>(); if (sg.HasSelectionForConcept(dimId)) { IComplexDataQuerySelection selConcept = sg.GetSelectionsForConcept(dimId); if (selConcept.HasMultipleValues()) { foreach (IComplexComponentValue val in selConcept.Values) freqs.Add(val.Value); } else { freqs.Add(selConcept.Value.Value); } } else { // HACK FIX ME TODO freqs.Add(null); } string sqlWhere = ""; foreach (string freqVal in freqs) { if (sqlWhere != "") whereBuilder.Append(" AND "); sqlWhere = GenerateWhereClause(sg, info, freqVal); whereBuilder.Append(sqlWhere); } if (sg.PrimaryMeasureValue != null && sg.PrimaryMeasureValue.Count > 0) { if (sqlWhere != "") whereBuilder.Append(" AND "); foreach (IComplexComponentValue complexValue in sg.PrimaryMeasureValue) { sqlWhere = GenerateComponentWhere(PrimaryMeasure.FixedId, complexValue, info); whereBuilder.Append(sqlWhere); } } foreach (IComplexDataQuerySelection sel in sg.Selections) { if (sqlWhere != "") whereBuilder.Append(" AND "); if (sel.HasMultipleValues()) { int contor = 0; whereBuilder.Append("("); foreach (IComplexComponentValue val in sel.Values) { if (contor > 0) whereBuilder.Append(" OR "); sqlWhere = GenerateComponentWhere(sel.ComponentId, val, info); whereBuilder.Append(sqlWhere); contor++; } whereBuilder.Append(")"); } else { sqlWhere = GenerateComponentWhere(sel.ComponentId, sel.Value, info); whereBuilder.Append(sqlWhere); } } } } // MAT-274 if (whereBuilder.Length > 0) { whereBuilder.Insert(0, "where "); } } // log for easy debug Logger.Info(string.Format(CultureInfo.InvariantCulture, Resources.InfoGeneratedWhereFormat1, whereBuilder)); Logger.Info(Resources.InfoEndGenerateWhere); return whereBuilder.ToString(); }
private static bool HandleTimeDimensionMapping( IDataReader reader, DataRetrievalInfo info, IMappedValues mappedValues) { if (info.TimeMapping != null) { string val = info.TimeTranscoder.MapComponent(reader, mappedValues.FrequencyValue); if (val != null) { mappedValues.TimeValue = val; if (info.IsTimePeriodAtObservation) { mappedValues.DimensionAtObservationValue = val; } } else { return false; // null value found at time dimension } } return true; }
/// <summary> /// This method executes an SQL query on the dissemination database and writes it to <see cref="DataRetrievalInfoSeries.SeriesWriter"/> . The SQL query is located inside <paramref name="info"/> at <see cref="DataRetrievalInfo.SqlString"/> /// </summary> /// <exception cref="System.ArgumentNullException"> /// <paramref name="info"/> /// is null /// </exception> /// <exception cref="DataRetrieverException"> /// <see cref="ErrorTypes"/> /// </exception> /// <param name="info"> /// The current DataRetrieval state /// </param> public void ExecuteSqlQuery(DataRetrievalInfo info) { info.BuildXSMeasures(); this.ExecuteDbCommand(info); }
/// <summary> /// This method generates the ORDER BY part of the query /// </summary> /// <param name="info"> /// The current data retrieval state /// </param> /// <returns> /// The string containing the ORDER BY part of the query /// </returns> private static string GenerateXSOrderByLocalColumns(DataRetrievalInfo info) { DsdEntity dsd = info.MappingSet.Dataflow.Dsd; var orderComponents = _orderedComponentBuilder.Build(info); var crossOrderedComponents = new List<ComponentEntity>(orderComponents); crossOrderedComponents.Sort(OnCrossSectionalComparison); var orderBy = GenerateOrderBy(info, crossOrderedComponents); return orderBy; }
/// <summary> /// Create and return a <see cref="IMappedValues"/> implementation /// </summary> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <param name="reader"> /// The <see cref="IDataReader"/> to read data from DDB /// </param> /// <returns> /// a <see cref="IMappedValues"/> implementation /// </returns> protected abstract IMappedValues CreateMappedValues(DataRetrievalInfo info, IDataReader reader);
/// <summary> /// Conditionally set the PCAxis data limit if the <paramref name="connection"/> is a <see cref="PcAxisConnection"/> /// </summary> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <param name="connection"> /// The connection to DDB. /// </param> private static void SetPCAxisLimit(DataRetrievalInfo info, IDbConnection connection) { var pcAxisConnection = connection as PcAxisConnection; if (pcAxisConnection != null) { // to avoid loading all observations from px file pcAxisConnection.DataPreviewRows = info.Limit; } }
/// <summary> /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query. /// </summary> /// <param name="info"> /// The current state of the data retrieval which containts the current query and mapping set /// </param> public void GenerateSql(DataRetrievalInfo info) { Logger.Info(Resources.InfoBeginGenerateSql); var seriesInfo = info as DataRetrievalInfoSeries; if (seriesInfo == null) { throw new ArgumentException("seriesInfo is not of DataRetrievalInfoSeries type"); } MappingSetEntity mappingSet = info.MappingSet; SqlQuery sqlQuery = new SqlQuery(); string sql = string.Empty; try { // Generate Query subparts var mappingEntities = ConvertToMapping(seriesInfo.AllComponentMappings); mappingEntities.Add(seriesInfo.TimeMapping); sql = GenerateSelect(false, mappingEntities); sqlQuery.appendSql(sql); sqlQuery.appendSql(GenerateFrom(mappingSet)); AppendCachedWhere(seriesInfo, sqlQuery); sqlQuery.appendSql(GenerateOrderByLocalColumns(seriesInfo)); } catch (DataRetrieverException dex) { throw new DataRetrieverException(dex, dex.SdmxErrorCode, dex.Message); } catch (Exception ex) { Logger.Error(ex.ToString()); throw new DataRetrieverException(ex, SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.SemanticError), Resources.ErrorUnableToGenerateSQL); } // log for easy debug Logger.Info(string.Format(CultureInfo.InvariantCulture, Resources.InfoGeneratedSQLFormat1, sql)); Logger.Info(Resources.InfoEndGenerateSql); info.SqlString = sqlQuery.getSql(); }
/// <summary> /// Store the SDMX compliant data for each component entity in the store /// </summary> /// <param name="componentValues"> /// The map between components and their values /// </param> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <returns> /// The number of observations stored /// </returns> /// <exception cref="ArgumentException"> /// <paramref name="info"/> /// not /// <see cref="DataRetrievalInfoTabular"/> /// type /// -or- /// <paramref name="componentValues"/> /// not /// <see cref="MappedValuesFlat"/> /// type /// </exception> protected override int StoreResults(IMappedValues componentValues, DataRetrievalInfo info) { var mappedValues = componentValues as MappedValuesFlat; if (mappedValues == null) { throw new ArgumentException(Resources.ErrorComponentValuesNotMappedValuesFlaType); } var tabularInfo = info as DataRetrievalInfoTabular; if (tabularInfo == null) { throw new ArgumentException(Resources.ErrorInfoNotDataRetrievalInfoTabularType); } this.WriteData(mappedValues, tabularInfo); return 1; }
/// <summary> /// This method generates the ORDER BY part of the query /// </summary> /// <param name="info"> /// The current data retrieval state /// </param> /// <returns> /// The string containing the ORDER BY part of the query /// </returns> private static string GenerateOrderByLocalColumns(DataRetrievalInfo info) { var orderComponents = _orderedComponentBuilder.Build(info); var orderBy = GenerateOrderBy(info, orderComponents); return orderBy; }
/// <summary> /// Generates sql where clauses from <paramref name="time"/> /// </summary> /// <param name="time"> /// The <see cref="IComplexDataQuerySelectionGroup"/> /// </param> /// <param name="info"> /// The current data retrieval state /// </param> /// /// </param> /// <param name="freqValue"> /// The frequency value /// </param> /// <returns> /// The string containing the time part of the WHERE in an SQL query. /// </returns> private static string GenerateWhereClause(IComplexDataQuerySelectionGroup time, DataRetrievalInfo info, string freqValue) { return info.TimeTranscoder != null ? info.TimeTranscoder.GenerateWhere(time.DateFrom, time.DateTo, freqValue) : string.Empty; }
/// <summary> /// Maps a component to one or more local columns and it's value to one or more local codes /// </summary> /// <param name="id"> /// The DSD Component identifier e.g. FREQ /// </param> /// <param name="conditionValue"> /// The DSD Component condition value (from the SDMX Query) /// </param> /// <param name="info"> /// The current Data Retrieval status /// </param> /// <returns> /// An string containing the sql query where condition /// </returns> private static string GenerateComponentWhere(string id, IComplexComponentValue conditionValue, DataRetrievalInfo info) { var ret = new StringBuilder(); // MappingEntity mapping; // check if there is a mapping for this component if (id != null && conditionValue != null) { string sOperator = "="; if (conditionValue.OrderedOperator != null) sOperator = GetSqlOrderedOperator(conditionValue.OrderedOperator); else if (conditionValue.TextSearchOperator != null) sOperator = GetSqlTextSearchOperator(conditionValue.TextSearchOperator); IComponentMapping componentMappingType; if (info.ComponentIdMap.TryGetValue(id, out componentMappingType)) { ret.Append(componentMappingType.GenerateComponentWhere(conditionValue.Value, sOperator)); } else if (info.MeasureComponent == null || !id.Equals(info.MeasureComponent.Id)) { // component is not in the mapping ret.Append( string.Format( CultureInfo.InvariantCulture, " ('{0} is not mapped' " + sOperator + " '{1}') ", id.Replace("'", "''"), conditionValue.Value.Replace("'", "''"))); } } return ret.ToString(); }
/// <summary> /// Read data from DDB, perfom mapping and transcoding and store it in the writer specified <see cref="DataRetrievalInfo"/> /// </summary> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <param name="reader"> /// The <see cref="IDataReader"/> to read data from DDB /// </param> /// <param name="componentValues"> /// The component Values. /// </param> /// <param name="mappings"> /// The collection of component mappings /// </param> protected override void ReadData(DataRetrievalInfo info, IDataReader reader, IMappedValues componentValues, IList<IComponentMapping> mappings) { base.ReadData(info, reader, componentValues, mappings); var mappedValues = componentValues as MappedValues; if (mappedValues != null) { WriteXsMeasureCache(info as DataRetrievalInfoSeries, mappedValues.XSMeasureCaches); } }
/// <summary> /// Store the SDMX compliant data for each component entity in the store /// </summary> /// <param name="componentValues"> /// The map between components and their values /// </param> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <returns> /// The number of observations stored /// </returns> protected override int StoreResults(IMappedValues componentValues, DataRetrievalInfo info) { var row = componentValues as MappedValues; if (row == null) { throw new ArgumentException("mappedValues not of MappedValues type"); } var seriesInfo = info as DataRetrievalInfoSeries; ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).SetJsonStructure(componentValues); if (row.IsNewKey()) { if (((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).StartedObservations) { ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).CloseObject(); ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).CloseObject(); ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter)._startedObservations = false; } TryWriteDataSet(row, seriesInfo); WriteSdmxJsonSeries(seriesInfo, row); } return WriteObservation(seriesInfo, row, row.PrimaryMeasureValue.Value); }
/// <summary> /// Store the SDMX compliant data for each component entity in the store /// </summary> /// <param name="componentValues"> /// The map between components and their values /// </param> /// <param name="limit"> /// The limit. /// </param> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <returns> /// The number of observations stored /// </returns> protected override int StoreResults(IMappedValues componentValues, int limit, DataRetrievalInfo info) { var row = componentValues as MappedValues; if (row == null) { throw new ArgumentException("mappedValues not of MappedValues type"); } int maxMeasures = Math.Min(info.CrossSectionalMeasureMappings.Count, limit); int count = WriteXsMeasures(info as DataRetrievalInfoSeries, maxMeasures, row); return count; }
protected override void ReadData(DataRetrievalInfo info, IDataReader reader, IMappedValues componentValues, IList<IComponentMapping> mappings) { int count = 0; while (reader.Read()) { if (HandleMappings(reader, info, componentValues, mappings)) { count += this.StoreResults(componentValues, info); } } var seriesInfo = info as DataRetrievalInfoSeries; info.RecordsRead = count; if (count > 0) { ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).WriteSDMXJsonStructure(this._dfo); } }
/// <summary> /// Store the SDMX compliant data for each component entity in the store /// </summary> /// <param name="componentValues"> /// The map between components and their values /// </param> /// <param name="limit"> /// The limit. /// </param> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <returns> /// The number of observations stored /// </returns> protected abstract int StoreResults(IMappedValues componentValues, int limit, DataRetrievalInfo info);
private static bool HandleMappings(IDataReader reader, DataRetrievalInfo info, IMappedValues componentValues, IList<IComponentMapping> mappings) { return HandleComponentMapping(reader, componentValues, mappings, info) && HandleTimeDimensionMapping(reader, info, componentValues); // MAT-262 }
/// <summary> /// Create and return a <see cref="IMappedValues"/> implementation /// </summary> /// <param name="info"> /// The current Data Retrieval state /// </param> /// <param name="reader"> /// The <see cref="IDataReader"/> to read data from DDB /// </param> /// <returns> /// a <see cref="IMappedValues"/> implementation /// </returns> protected override IMappedValues CreateMappedValues(DataRetrievalInfo info, IDataReader reader) { return new MappedValuesFlat(info); }
/// <summary> /// This method generates the ORDER BY part of the query for the specified <paramref name="orderComponents"/> /// </summary> /// <param name="info"> /// The current Data retrieval state /// </param> /// <param name="orderComponents"> /// The order components. /// </param> /// <returns> /// the ORDER BY part of the query for the specified <paramref name="orderComponents"/> /// </returns> protected static string GenerateOrderBy(DataRetrievalInfo info, IEnumerable<ComponentEntity> orderComponents) { Logger.Info(Resources.InfoGenerateOrderBy); var orderBy = new StringBuilder("order by "); var orderColumns = new List<string>(); // add each components comtribution to the order by of the query foreach (ComponentEntity component in orderComponents) { MappingEntity mapping; if (info.ComponentMapping.TryGetValue(component, out mapping)) { foreach (DataSetColumnEntity column in mapping.Columns) { if (!orderColumns.Contains(column.Name)) { orderColumns.Add(column.Name); } } } } orderBy.Append(string.Join(CommaSeparator, orderColumns.ToArray())); IBaseDataQuery baseDataQuery = (IBaseDataQuery)info.ComplexQuery ?? info.Query; bool hasLastObs = baseDataQuery.LastNObservations.HasValue && baseDataQuery.LastNObservations.Value > 0 && (!baseDataQuery.FirstNObservations.HasValue || baseDataQuery.FirstNObservations.Value == 0); if (hasLastObs) { // we assume that the last dimension is the dimension at observarion. orderBy.Append(" DESC"); } // log for easy debug Logger.Info( string.Format(CultureInfo.InvariantCulture, Resources.InfoGeneratedOrderByFormat1, orderBy)); Logger.Info(Resources.InfoEndGenerateOrderBy); return orderBy.ToString(); }