/// <summary> /// Initialize component mappings for coded components and time dimension used in mappings in the dataflow /// </summary> /// <param name="dataflowRef"> /// The dataflow Ref. /// </param> /// <remarks> /// This method should be called only once /// </remarks> private void Initialize(Sdmx.Model.Registry.DataflowRefBean dataflowRef) { this._mappingSet = DataAccess.GetMappingSet( this._connectionStringSettings, dataflowRef.Id, dataflowRef.Version, dataflowRef.AgencyID, this._allowedDataflows); if (this._mappingSet == null) { return; } NormallizeDatabaseProvider(this._connectionStringSettings); this._mastoreAccess = new StructureAccess(this._connectionStringSettings); this._xsMeasureDimensionConstraints.Clear(); this._componentMapping = new Dictionary<string, ComponentInfo>(this._mappingSet.Mappings.Count); this._innerSqlQuery = this._mappingSet.DataSet.Query; this._measureComponent = null; this._timeTranscoder = null; this._timeMapping = null; this._timeDimension = null; bool measureDimensionMapped = false; foreach (MappingEntity mapping in this._mappingSet.Mappings) { foreach (ComponentEntity component in mapping.Components) { if (component.ComponentType == SdmxComponentType.TimeDimension) { this._timeTranscoder = TimeDimensionMapping.Create( mapping, this._mappingSet.DataSet.Connection.DBType); this._timeMapping = mapping; this._timeDimension = component.Concept.Id; } else if (component.CodeList != null) { if (component.MeasureDimension) { measureDimensionMapped = true; } var compInfo = new ComponentInfo(); compInfo.Mapping = mapping; compInfo.ComponentMapping = ComponentMapping.CreateComponentMapping(component, mapping); compInfo.CodelistRef.Id = component.CodeList.Id; compInfo.CodelistRef.Version = component.CodeList.Version; compInfo.CodelistRef.AgencyID = component.CodeList.Agency; this._componentMapping.Add(component.Concept.Id, compInfo); } } } if (!measureDimensionMapped) { foreach (ComponentEntity component in this._mappingSet.Dataflow.Dsd.Dimensions) { if (component.MeasureDimension) { this._measureComponent = component.Concept.Id; } } foreach (ComponentEntity xsMeasure in this._mappingSet.Dataflow.Dsd.CrossSectionalMeasures) { this._xsMeasureDimensionConstraints.Add(xsMeasure.Concept.Id, xsMeasure); } } }
/// <summary> /// Initialize component mappings for coded components and time dimension used in mappings in the dataflow /// </summary> /// <param name="info"> /// The current structure retrieval state /// </param> /// <remarks> /// This method should be called only once /// </remarks> private static void Initialize(StructureRetrievalInfo info) { NormallizeDatabaseProvider(info.ConnectionStringSettings); info.MastoreAccess = new SpecialMutableObjectRetrievalManager(info.ConnectionStringSettings); info.XSMeasureDimensionConstraints.Clear(); info.ComponentMapping.Clear(); info.InnerSqlQuery = info.MappingSet.DataSet.Query; info.MeasureComponent = null; info.TimeTranscoder = null; info.TimeMapping = null; info.TimeDimension = null; bool measureDimensionMapped = false; foreach (MappingEntity mapping in info.MappingSet.Mappings) { foreach (ComponentEntity component in mapping.Components) { if (component.ComponentType == SdmxComponentType.TimeDimension) { info.TimeMapping = mapping; info.TimeDimension = component.Id; } else if (component.CodeList != null) { if (component.MeasureDimension) { measureDimensionMapped = true; } var compInfo = new ComponentInfo { Mapping = mapping, ComponentMapping = ComponentMapping.CreateComponentMapping(component, mapping) }; compInfo.CodelistRef.MaintainableId = component.CodeList.Id; compInfo.CodelistRef.Version = component.CodeList.Version; compInfo.CodelistRef.AgencyId = component.CodeList.Agency; var id = component.Id; info.ComponentMapping.Add(id, compInfo); if (id.Equals(info.RequestedComponent)) { info.RequestedComponentInfo = compInfo; } if (component.FrequencyDimension) { info.FrequencyInfo = compInfo; } } } } if (info.TimeMapping != null) { info.TimeTranscoder = TimeDimensionMapping.Create( info.TimeMapping, info.FrequencyInfo != null ? info.FrequencyInfo.ComponentMapping : null, info.MappingSet.DataSet.Connection.DBType); } if (!measureDimensionMapped) { foreach (ComponentEntity component in info.MappingSet.Dataflow.Dsd.Dimensions) { if (component.MeasureDimension) { info.MeasureComponent = component.Id; } } foreach (ComponentEntity xsMeasure in info.MappingSet.Dataflow.Dsd.CrossSectionalMeasures) { info.XSMeasureDimensionConstraints.Add(xsMeasure.Id, xsMeasure); } } }
/// <summary> /// Execute the query generated from <see cref="GenerateSql"/> against the DDB and populate the given set of available codes. /// </summary> /// <param name="component"> /// The component to get the codes for /// </param> /// <param name="codeSet"> /// The Set to populate with the DDB available codes /// </param> /// <param name="sqlQuery"> /// The SQL Query to execute /// </param> /// <exception cref="DbException"> /// DDB communication error /// </exception> private void ExecuteSql(ComponentInfo component, IDictionary<string, object> codeSet, string sqlQuery) { IComponentMapping cmap = component.ComponentMapping; using (DbConnection ddbConnection = this.CreateDdbConnection()) { using (DbCommand cmd = ddbConnection.CreateCommand()) { cmd.CommandText = sqlQuery; SetupUpCmd(cmd); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { string dsdCode = cmap.MapComponent(reader); if (dsdCode != null && !codeSet.ContainsKey(dsdCode)) { codeSet.Add(dsdCode, null); } } } } } }