protected static void RDFWriteSeries(DataRetrievalInfoSeries info, MappedValues row) { string values; values = RDFConstants.RdfDataset + info.MappingSet.DataSet.Description.ToString(); foreach (var dimensionValue in row.DimensionValues) { if (!dimensionValue.Key.Id.Equals(info.DimensionAtObservation)) { values += "/" + dimensionValue.Value; } } values += "/" + row.TimeValue; // start series info.SeriesWriter.StartSeries(values); values = ""; // write dimensions foreach (var dimensionValue in row.DimensionValues) { if (!dimensionValue.Key.Id.Equals(info.DimensionAtObservation)) { info.SeriesWriter.WriteSeriesKeyValue(dimensionValue.Key.Id, dimensionValue.Value, dimensionValue.Key.CodeList.Version, dimensionValue.Key.CodeList.Id); } } }
private static bool ProcessedKeySet( GroupInformation targetGroup, DataRetrievalInfoSeries info, MappedValues componentValues) { var current = new ReadOnlyKey(componentValues, info.GroupNameTable); if (!targetGroup.KeySet.ContainsKey(current)) { targetGroup.KeySet.Add(current, null); 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="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(); }
///// <summary> ///// Write the SDMX header (from <paramref name="info"/> ) to <paramref name="writer"/> ///// </summary> ///// <param name="writer"> ///// The writer. ///// </param> ///// <param name="info"> ///// The info. ///// </param> //private void WriteHeader(IWriterEngine writer, DataRetrievalInfo info) //{ // // retrieve header information // Logger.Info(Resources.DataRetriever_RetrieveData_Start_Retrieving_header_information); // IHeader header = _headerBuilder.Build(info); // Logger.Info(Resources.DataRetriever_RetrieveData_End_Retrieving_header_information); // writer.WriteHeader(header); //} private void RDFWriterStrucInfo(DataRetrievalInfoSeries info, string dataset, string struc) { info.SeriesWriter.RDFWriterStrucInfo(dataset, struc); }
/// <summary> /// Retrieve data from a DDB and write it to the specified <paramref name="writer"/> This is the main public method of the DataRetriever class. It is called with a populated QueryBean (containing essentially an SDMX-ML Query) and a database Connection to a "Mapping Store" database. This method is responsible for: /// <list type="bullet"> /// <item> /// Retrieving the <see cref="MappingSetEntity"/> (the class containing the performed mappings), according to the provided Dataflow ID, from the "Mapping Store". Mapping Sets are defined on a Dataflow basis. Thus, this method checks the input QueryBean for the Dataflow that data are requested and fetches the appropriate /// <see cref="MappingSetEntity"/>. If no <see cref="MappingSetEntity"/> exists, an exception (<see cref="DataRetrieverException"/>) is thrown. /// </item> /// <item> /// Calling the method generating the appropriate SQL for the dissemination database. /// </item> /// <item> /// Calling the method that executes the generated SQL and uses the /// <paramref name="writer"/> /// to write the output. /// </item> /// </list> /// <note type="note"> /// The "Data Retriever" expects exactly one Dataflow clause under the DataWhere clause, exactly one /// DataFlowBean within the DataWhereBean (which in turn resides inside the incoming QueryBean). /// </note> /// </summary> /// <exception cref="DataRetrieverException"> /// See the /// <see cref="ErrorTypes"/> /// for more details /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="query"/> /// is null /// -or- /// <paramref name="writer"/> /// is null /// </exception> /// <param name="query"> /// The query bean for which data will be requested /// </param> /// <param name="writer"> /// The <see cref="ISeriesWriter"/> (e.g. Compact, Generic) writer /// </param> /// <example> /// An example using this method in C# with <see cref="CompactWriter"/> /// <code source="ReUsingExamples\DataRetriever\ReUsingDataRetriever.cs" lang="cs"> /// </code> /// An example using this method in C# with <see cref="GenericDataWriter"/> /// <code source="ReUsingExamples\DataRetriever\ReUsingDataRetrieverGeneric.cs" lang="cs"> /// </code> /// </example> public void GetData(IDataQuery dataQuery, IRDFDataWriterEngine dataWriter) { if (dataQuery == null) { throw new ArgumentNullException("query"); } if (dataWriter == null) { throw new ArgumentNullException("writer"); } try { Logger.Info(Resources.InfoDataRetrieverBBInvoked); Logger.Info(Resources.InfoOutput + dataWriter.GetType().Name); // validate input and initialize the mappingset entitiy MappingSetEntity mappingSet = this.Initialize(dataQuery); var info = new DataRetrievalInfoSeries(mappingSet, dataQuery, this._connectionStringSettings, dataWriter) { DefaultHeader = this._defaultHeader }; ValidateMappingSet(info); //this.WriteHeader(dataWriter, info); //(SRA-345) //DR the info from I*DataQuery. DimensionAtObservation to IDataWriterEngine.StartDataSet IDatasetStructureReference dsr = new DatasetStructureReferenceCore("", dataQuery.DataStructure.AsReference, null, null, dataQuery.DimensionAtObservation); IDatasetHeader header = new DatasetHeaderCore(this._defaultHeader.DatasetId, this._defaultHeader.Action, dsr); dataWriter.StartDataset(dataQuery.Dataflow, dataQuery.DataStructure, header, info); // Generate sql query this.GenerateSql(info, _sqlBuilder); this.GenerateSql(info, SeriesDataSetSqlBuilder.Instance); this.GenerateSql(info, SeriesGroupSqlBuilder.Instance); // execute sql query this.ExecuteSql(info, RDFSeriesQueryEngineManager.Instance.GetQueryEngine(info)); // close output dataWriter.Close(); Logger.Info(Resources.InfoEndDataRetrieverBBInvoked); } catch (DataRetrieverException) { throw; } catch (SdmxException) { throw; } catch (DbException ex) { Logger.Error(ex.ToString()); throw new DataRetrieverException(ex, SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.InternalServerError), Resources.DataRetriever_ExecuteSqlQuery_Error_executing_generated_SQL_and_populating_SDMX_model); } catch (OutOfMemoryException) { throw; } catch (Exception ex) { Logger.Error(ex.ToString()); throw new DataRetrieverException(ex, SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.InternalServerError), Resources.DataRetriever_ExecuteSqlQuery_Error_during_writing_responce); } }
protected static void RDFWriterStrucInfo(DataRetrievalInfoSeries info, string dataset, string struc) { info.SeriesWriter.RDFWriterStrucInfo(dataset, struc); }
protected static int RDFWriteObservation(DataRetrievalInfoSeries info, MappedValues row, string value) { // write time and obs value info.SeriesWriter.RDFWriteObservation(row.TimeValue, value); return 1; }
/// <summary> /// Appends the cached where to <paramref name="sql"/> from <see cref="DataRetrievalInfoSeries.SqlWhereCache"/> if it is not null or from <see cref="SqlBuilderBase.GenerateWhere"/> /// </summary> /// <param name="info"> /// The current DataRetrieval state /// </param> /// <param name="sql"> /// The SQL String buffer to /// </param> private static void AppendCachedWhere(DataRetrievalInfoSeries info, SqlQuery sqq) { if (string.IsNullOrEmpty(info.SqlWhereCache)) { info.SqlWhereCache = GenerateWhere(info); } sqq.appendSql(info.SqlWhereCache); }
public void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, DataRetrievalInfoSeries info) { this._actions.Enqueue(() => this._dataWriterEngine.StartDataset(dataflow, dsd, header, info)); }
protected override void WriteFormatDataSet(IDatasetHeader header, DataRetrievalInfoSeries info) { if (this._startedDataSet) { return; } this._dimensionAtObservation = this.GetDimensionAtObservation(header); this.RDFWriteMessageTag(MessageElement, this.Namespaces); this.WriteStartElement(this.Namespaces.RDF, RDFElementNameTable.RDF); this.RDFWriteProvenance(info.MappingSet.DataSet.Description.ToString(), RDFConstants.RdfDataset); this.RDFWriterStrucInfo(info.MappingSet.DataSet.Description.ToString(), info.MappingSet.Dataflow.Dsd.Id.ToString()); this._startedDataSet = true; }
public void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, DataRetrievalInfoSeries info) { base.StartDataset(dataflow, dsd, header, info); }