public RDFDelayedDataWriterEngine(IRDFDataWriterEngine dataWriterEngine, Queue<Action> actions) { if (dataWriterEngine == null) { throw new ArgumentNullException("dataWriterEngine"); } this._dataWriterEngine = dataWriterEngine; this._actions = actions ?? new Queue<Action>(); }
/// <summary> /// Initializes a new instance of the <see cref="DataRetrievalInfoSeries" /> class. /// </summary> /// <param name="mappingSet">The mapping set of the dataflow found in the sdmx query</param> /// <param name="query">The current SDMX Query object</param> /// <param name="connectionStringSettings">The Mapping Store connection string settings</param> /// <param name="seriesWriter">The series Writer.</param> /// <param name="sdmxSchemaVersion">The SDMX schema version.</param> public DataRetrievalInfoSeries(MappingSetEntity mappingSet, IDataQuery query, ConnectionStringSettings connectionStringSettings, IRDFDataWriterEngine seriesWriter) : base(mappingSet, query, connectionStringSettings) { this._seriesWriter = seriesWriter; this._seriesObsComponents = new List<IComponentMapping>(); this._dataSetAttributes = new List<IComponentMapping>(); this._groups = new Dictionary<GroupEntity, GroupInformation>(); this._useDataSetSqlQuery = mappingSet.Dataflow.Dsd.Groups.Count > 0; this.BuildSeriesMappings(); // add dimension mappings to groups this.BuildTimeSeriesGroupMappings(); }
/// <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); } }
/// <summary> /// Write a DataMessage in XmlWriter /// </summary> /// <param name="writer">Stream Destination</param> public override void WriteDataMessage(IFlyWriter writer) { try { IRDFDataWriterEngine dataWriterEngine = null; switch (MessageType) { case MessageTypeEnum.Rdf: dataWriterEngine = new RDFDataWriterEngine(writer.__SdmxXml); break; } if (dataWriterEngine == null) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.InternalError, new Exception("No Type Message recognized")); } DataStructureObjectImpl dsd = _retrievalManager._dsd; // start dataset dataWriterEngine.StartDataset(dsd.Immutated.TimeDimension.Id, _retrievalManager.DataFlowID, _retrievalManager._dsd.Id); //// Aggiungo dataset Title //if (FlyConfiguration.DatasetTitle && !string.IsNullOrEmpty(this._retrievalManager.DataFlowTitle)) // dataWriterEngine.WriteAttributeValue("Title", this._retrievalManager.DataFlowTitle); //Aggiungo gli Attributi di Dataset //bool AddedDatasetAttribute = false; this.LastSeriesKey = null; List <DataMessageObject> dmo = _tableResponse.GetNext(); do { if (dmo == null) { break; } //if (!AddedDatasetAttribute) //{ // foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyDatasetAttribute(att))) // dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString()); // AddedDatasetAttribute = true; //} //SERIE //if (CheckChanged(dmo)) //{ List <string> Vals = new List <string>(); Vals.Add(RDFProvider.Constants.RDFConstants.RdfDataset + _retrievalManager.DataFlowID); foreach (DataMessageObject seriesKey in dmo.FindAll(dim => OnlySeriesKey(dim))) { Vals.Add(seriesKey.Val.ToString()); } dataWriterEngine.StartSeries(string.Join("/", Vals), _retrievalManager.DataFlowID); foreach (DataMessageObject seriesKey in dmo.FindAll(dim => OnlySeriesKey(dim))) { if (seriesKey.ColImpl.ConceptDSDInfo != null) { dataWriterEngine.WriteSeriesKeyValue(seriesKey.ColImpl.ConceptObjectCode, seriesKey.Val.ToString(), seriesKey.ColImpl.ConceptDSDInfo.CodelistVersion, seriesKey.ColImpl.ConceptDSDInfo.CodelistId); } else { dataWriterEngine.WriteSeriesKeyValue(seriesKey.ColImpl.ConceptObjectCode, seriesKey.Val.ToString(), FlyConfiguration.Version, string.Format("CL_{0}", seriesKey.ColImpl.ConceptObjectCode)); } } //foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlySeriesAttribute(att))) // dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString()); //} //OBSERVATION DataMessageObject val = dmo.Find(dimV => dimV.ColImpl.ConceptType == ConceptTypeEnum.Attribute && ((IAttributeConcept)dimV.ColImpl).IsValueAttribute); DataMessageObject time = dmo.Find(dimT => dimT.ColImpl.ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)dimT.ColImpl).DimensionType == DimensionTypeEnum.Time); dataWriterEngine.RDFWriteObservation(time.ColImpl.ConceptObjectCode, time.Val.ToString(), val.Val.ToString()); //foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyObservationAttribute(att))) // dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString()); dmo = _tableResponse.GetNext(); } while (dmo != null); dataWriterEngine.Close(); writer.__SdmxXml.Flush(); } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteDataMessage, ex); } }