/// <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>
        /// 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)
            {
                queryEngine = SeriesDataQueryEngine.Instance;
            }
            else if (crossSectionalMeasureMappings.Count > 0)
            {
                queryEngine = SeriesDataQueryEngineXsMeasureBuffered.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)
        {
            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>
        /// 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="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;
        }
 /// <summary>
 /// Generate the SQL string using <paramref name="sqlBuilder"/> with <paramref name="info"/>
 /// </summary>
 /// <param name="info">
 /// The current dataretrieval state. 
 /// </param>
 /// <param name="sqlBuilder">
 /// The sql builder. 
 /// </param>
 private void GenerateSql(DataRetrievalInfo info, ISqlBuilder sqlBuilder)
 {
     // Generate sql query
     Logger.Info(Resources.InfoStartGeneratingSQLDDB);
     sqlBuilder.GenerateSql(info);
     Logger.Info(Resources.InfoEndGeneratingSQLDDB);
 }
 /// <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);
     }
 }
Example #12
0
 /// <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>
 /// This method executes an SQL query on the dissemination database and writes it to <see cref="DataRetrievalInfoXS.XSWriter"/> . 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 virtual void ExecuteSqlQuery(DataRetrievalInfo info)
 {
     this.ExecuteDbCommand(info);
 }
 /// <summary>
 /// Check if the <see cref="DataRetrievalInfo.MappingSet"/> from <paramref name="info"/> is complete
 /// </summary>
 /// <param name="info">
 /// The current data retrieval state 
 /// </param>
 /// <exception cref="DataRetrieverException">
 /// Incomplete mapping set. Please check if all dimensions, measure(s) and mandatory attributes are mapped
 /// </exception>
 private static void ValidateMappingSet(DataRetrievalInfo info)
 {
     // check if mapping is complete first
     if (!MappingUtils.IsMappingSetComplete(info.MappingSet.Dataflow.Dsd, info.ComponentMapping))
     {
         throw new IncompleteMappingSetException(Resources.ErrorIncompleteMappingSet);
     }
 }
        /// <summary>
        /// Execute any additional queries if overridden in a subclass. This override executes queries for DataSet and Groups
        /// </summary>
        /// <param name="info">
        /// The current Data Retrieval state 
        /// </param>
        /// <param name="connection">
        /// The <see cref="DbConnection"/> to the DDB 
        /// </param>
        protected override void RunAdditionalQueries(DataRetrievalInfo info, DbConnection connection)
        {
            var seriesInfo = info as DataRetrievalInfoSeries;
            if (seriesInfo == null)
            {
                throw new ArgumentException(Resources.ErrorTypeNotDataRetrievalInfoSeries, "info");
            }

            // handle dataset attributes
            if (seriesInfo.DataSetAttributes.Count > 0)
            {
                ExecuteDataSetAttributeSqlQuery(seriesInfo, connection);
            }

            // check if there are groups and mapped group attributes
            foreach (var groupInformation in seriesInfo.Groups)
            {
                this.ExecuteGroupSqlQuery(groupInformation.Value, seriesInfo, connection);
            }
        }
Example #16
0
        /// <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();
        }
Example #17
0
        /// <summary>
        /// Checks if the dimension at observation is in the dimension references of the component <paramref name="componentMappings"/>
        /// </summary>
        /// <param name="componentValue">
        /// The component value 
        /// </param>
        /// /// <param name="info">
        /// The data retrieval info 
        /// </param>
        private bool IsDimensionObsReference(ComponentValue componentValue, DataRetrievalInfo info)
        {
            IBaseDataQuery baseDataQuery = (IBaseDataQuery)info.ComplexQuery ?? info.Query;

            foreach (IAttributeObject attr in baseDataQuery.DataStructure.AttributeList.Attributes)
            {
                if (attr.Id.Equals(componentValue.Key.Id))
                {
                    if (attr.DimensionReferences.Contains(info.DimensionAtObservation))
                        return true;
                    return false;
                }
            }

            return false;
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MappedValues"/> class.
 /// </summary>
 /// <param name="info">
 /// The current data retrieval state 
 /// </param>
 /// <param name="componentMappings">
 /// The component Mappings. 
 /// </param>
 public MappedValues(DataRetrievalInfo info, IEnumerable<IComponentMapping> componentMappings)
 {
     this.SetComponentOrder(componentMappings, info);
     this.SetTimeDimensionComponent(info.TimeTranscoder);
     if (info.TimeTranscoder != null && !info.IsTimePeriodAtObservation &&
             info.TimeTranscoder.Component.ComponentType == SdmxComponentType.TimeDimension)
         this._keyValues.Add(this.TimeDimensionValue);
     this._previousKeyValues = new string[this._keyValues.Count];
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MappedValues"/> class.
 /// </summary>
 /// <param name="info">
 /// The current data retrieval state 
 /// </param>
 public MappedValues(DataRetrievalInfo info)
     : this(info, info.AllComponentMappings)
 {
 }
Example #20
0
        /// <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();
        }
Example #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MappedXsValues"/> class.
        /// </summary>
        /// <param name="info">
        /// The info. 
        /// </param>
        public MappedXsValues(DataRetrievalInfo info)
        {
            var values = (CrossSectionalLevels[])Enum.GetValues(typeof(CrossSectionalLevels));

            for (int i = 0; i < values.Length; i++)
            {
                this._dimensionValues.Add(new List<ComponentValue>());
                this._attributeValues.Add(new List<ComponentValue>());
                this._keyValues.Add(new List<ComponentValue>());
            }

            this._dataSetIndex = GetIndex(CrossSectionalLevels.DataSet);
            this._groupIndex = GetIndex(CrossSectionalLevels.Group);
            this._sectionIndex = GetIndex(CrossSectionalLevels.Section);
            this._observationIndex = GetIndex(CrossSectionalLevels.Observation);

            this.SetComponentOrder(info.AllComponentMappings);
            if (info.TimeTranscoder != null)
            {
                var timeDimensionComponent = this.SetTimeDimensionComponent(info.TimeTranscoder);
                this.HandleTimeDimension(timeDimensionComponent);
            }

            for (int i = 0; i < this._keyValues.Count; i++)
            {
                List<ComponentValue> keyValue = this._keyValues[i];
                this._previousKeyValues[i] = new string[keyValue.Count];
            }
        }
 /// <summary>
 /// This method executes an SQL query on the dissemination database and writes it to <see cref="DataRetrievalInfoXS.XSWriter"/> . 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 override void ExecuteSqlQuery(DataRetrievalInfo info)
 {
     info.BuildXSMeasures();
     base.ExecuteSqlQuery(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)
 {
     info.BuildXSMeasures();
     this.ExecuteDbCommand(info);
 }
 /// <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 MappedXsValues(info);
 }
        /// <summary>
        /// This method executes an SQL query on the dissemination database
        /// </summary>
        /// <param name="info">
        /// The current Data Retrieval state 
        /// </param>
        /// <param name="queryEngine">
        /// The query engine. 
        /// </param>
        private void ExecuteSql(DataRetrievalInfo info, IDataQueryEngine queryEngine)
        {
            Logger.Info(Resources.InfoStartExecutingSql);
            queryEngine.ExecuteSqlQuery(info);
            Logger.Info(Resources.InfoEndExecutingSql);

            if (info.RecordsRead == 0 && (info.ComplexQuery != null || this._sdmxSchemaVersion == SdmxSchemaEnumType.VersionTwoPointOne))
            {
                throw new DataRetrieverException(Resources.NoRecordsFound,
                            SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.NoResultsFound));
            }
        }
        /// <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 MappedXsValues;
            if (row == null)
            {
                throw new ArgumentException(Resources.ErrorTypeNotMappedXsValues, "componentValues");
            }

            var xsInfo = info as DataRetrievalInfoXS;
            if (xsInfo == null)
            {
                throw new ArgumentException("info not of DataRetrievalInfoXS type");
            }

            WriteDataSet(row, xsInfo);

            if (row.IsNewGroupKey())
            {
                WriteGroup(row, xsInfo);
            }

            if (row.IsNewSectionKey())
            {
                WriteSection(row, xsInfo);
            }

            return this.WriteObservation(row, xsInfo);
        }
        /// <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)
        {
            var seriesInfo = info as DataRetrievalInfoSeries;
            if (seriesInfo == null)
            {
                throw new ArgumentException(Resources.ErrorTypeNotDataRetrievalInfoSeries, "info");
            }

            return new MappedValues(info) { StartedDataSet = seriesInfo.DataSetAttributes.Count > 0 };
        }
 /// <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);
 }
Example #29
0
        /// <summary>
        /// Initialize the internal order of the components based on the specified <paramref name="componentMappings"/>
        /// </summary>
        /// <param name="componentMappings">
        /// The component mappings 
        /// </param>
        /// /// <param name="info">
        /// The data retrieval info 
        /// </param>
        private void SetComponentOrder(IEnumerable<IComponentMapping> componentMappings, DataRetrievalInfo info)
        {
            foreach (IComponentMapping componentMapping in componentMappings)
            {
                var componentValue = new ComponentValue(componentMapping.Component);
                this.ComponentValues.Add(componentValue);
                switch (componentMapping.Component.ComponentType)
                {
                    case SdmxComponentType.Dimension:
                        this._dimensionValues.Add(componentValue);
                        if (!componentValue.Key.Id.Equals(info.DimensionAtObservation))
                            this._keyValues.Add(componentValue);
                        break;
                    case SdmxComponentType.Attribute:
                        switch (componentMapping.Component.AttributeAttachmentLevel)
                        {
                            case AttachmentLevel.DataSet:
                                this._attributeDataSetValues.Add(componentValue);
                                break;
                            case AttachmentLevel.Group:
                                // NOTE we expect only the attributes of a specific group to be in _attributeGroupValues
                                this._attributeGroupValues.Add(componentValue);
                                break;
                            case AttachmentLevel.Series:
                                if (IsDimensionObsReference(componentValue, info))
                                    this._attributeObservationValues.Add(componentValue);
                                else
                                    this._attributeSeriesValues.Add(componentValue);
                                break;
                            case AttachmentLevel.Observation:
                                this._attributeObservationValues.Add(componentValue);
                                break;
                        }

                        break;
                    case SdmxComponentType.PrimaryMeasure:
                        this.PrimaryMeasureValue = componentValue;
                        break;
                    case SdmxComponentType.CrossSectionalMeasure:
                        this._xsMeasures.Add(componentValue);
                        break;
                }
            }
        }
Example #30
0
        /// <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();
        }