Пример #1
0
 public List <GroupChannelMap> GetGroupMap()
 {
     using (IDataQuery dataQuery = OpenQuery())
     {
         return(dataQuery.Open <DAO.GroupChannelMap>().List().Select(dao => dao.ToObj()).ToList());
     }
 }
Пример #2
0
        public IQueryable <From> InitQuery <From>(IDataQuery q, string continuationToken)
        {
            var options = new FeedOptions
            {
                EnableScanInQuery = true,
                MaxItemCount      = (!q.Rows.HasValue)
                    ? -1                             // set max item if provided, else set to -1 for no limit
                    : q.Rows.Value + (q.Offset ?? 0) // limit to only needed records
            };

            // if no provided PartionKey, enable cross partition querying
            if (string.IsNullOrEmpty(partitionKey))
            {
                options.EnableCrossPartitionQuery = true;
            }
            else
            {
                options.PartitionKey = new PartitionKey(partitionKey);
            }

            // append continuation token is provided
            if (!string.IsNullOrEmpty(continuationToken))
            {
                options.RequestContinuation = continuationToken;
            }

            return(client.CreateDocumentQuery <From>(
                       UriFactory.CreateDocumentCollectionUri(databaseId, collectionId),
                       options));
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public List <DAO.ServiceInfo> GetServiceInstances()
 {
     using (IDataQuery dataQuery = OpenQuery())
     {
         return(dataQuery.Open <DAO.ServiceInfo>().List().ToList());
     }
 }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public List <Contact> GetContacts()
 {
     using (IDataQuery dataQuery = OpenQuery())
     {
         return(dataQuery.Open <DAO.Contact>().List().Select(dao => dao.ToObj()).ToList());
     }
 }
	    public void GetData(IDataQuery dataQuery, IDataWriterEngine writerEngine) {
			// process query clauses
			// ...
			// write sample response of query results based on Chapter3 data writing
			SampleDataWriter writer = new SampleDataWriter();
			writer.WriteSampleData(dataQuery.DataStructure, dataQuery.Dataflow, writerEngine);
		}
 /// <summary>
 /// Получить сообщение.
 /// </summary>
 /// <param name="msgLink"></param>
 /// <returns></returns>
 public virtual Message GetMessage(int msgLink)
 {
     using (IDataQuery dataQuery = OpenQuery())
     {
         return(dataQuery.Get <DAO.Message>(msgLink).ToObj());
     }
 }
Пример #7
0
 public List <ChannelInfo> GetChannels()
 {
     using (IDataQuery dataQuery = OpenQuery())
     {
         return(dataQuery.Open <DAO.ChannelInfo>().List().Select(dao => dao.ToObj()).ToList());
     }
 }
        /// <summary>
        ///     Gets the data.
        /// </summary>
        /// <param name="dataQuery">The data query.</param>
        /// <param name="dataWriter">The data writer.</param>
        /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxNoResultsException">0 observations found (SDMX v2.1 behavior)</exception>
        /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxResponseTooLargeException">Emulating default limit</exception>
        /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxResponseSizeExceedsLimitException">Emulating server side limit</exception>
        /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxSemmanticException">Invalid component in query</exception>
        /// <exception cref="SdmxNoResultsException">Invalid component in query</exception>
        public void GetData(IDataQuery dataQuery, IDataWriterEngine dataWriter)
        {
            dataWriter.StartDataset(null, dataQuery.DataStructure, null);
            this.Validate(dataQuery, dataWriter);

            WriteData(dataQuery, dataWriter);
        }
Пример #9
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="observationLimit">
        /// The maximum number of observations to return
        /// </param>
        /// <param name="tempFileName">
        /// The temporary fila name
        /// </param>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, int observationLimit, string tempFileName)
        {
            query = new DataQueryFluentBuilder().Initialize(query.DataStructure, query.Dataflow)
                    .WithDataQuerySelectionGroup(query.SelectionGroups).Build();

            this.ExecuteQuery(query, operationName, tempFileName);
        }
Пример #10
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <exception cref="NsiClientException">Failute to execute query</exception>
        /// <returns>
        /// The SDMX-ML data as a stream.
        /// </returns>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            try
            {
                this.SendSdmxQuery(query, operationName, tempFileName);
            }

            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
            }
        }
Пример #11
0
        private async Task <IEnumerable <T> > QueryAsync(IDataQuery q, CancellationToken cancellationToken = default(CancellationToken))
        {
            // set queue size if provided (fallsback to feed option MaxLimit setting)
            var resultQueue = (q.Rows.HasValue)
                                    ? new Queue <T>(q.Rows.Value)
                                    : new Queue <T>();

            string continuationToken = null;

            // create a negative offset to skip results
            var offset = -1 * q.Offset ?? 0;

            do
            {
                var pagedResults = await GetQuery <T>(q, continuationToken).ToPagedResults(cancellationToken);

                continuationToken = pagedResults.ContinuationToken;

                foreach (var item in pagedResults.Results)
                {
                    // don't add results until past offset
                    if (offset >= 0)
                    {
                        resultQueue.Enqueue(item);
                    }

                    offset++;
                }
            }while (!string.IsNullOrEmpty(continuationToken));

            return(resultQueue);
        }
        void queryTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (_started)
            {
                var  messages = new List <Message>();
                bool sending  = false;

                try
                {
                    using IDataQuery dataQuery = _dataAdapter.OpenQuery();
                    var query = CreateOfflineSelectMessagesQuery();
                    messages = query.GetExecutableQueryOver(dataQuery.Session)
                               .Take(_portion).List()
                               .Select(msg => msg.ToObj()).ToList();

                    _logger.LogTrace($"Найдено {messages.Count} новых сообщений.");

                    if (messages.Count > 0)
                    {
                        PreProcessSelectedMessages(messages, _cancellationToken);

                        if (this.NewMessages != null)
                        {
                            if (this.NewMessages.Invoke(messages.ToArray()))
                            {
                                sending = true;
                                string links      = String.Join(",", messages.Select(msg => msg.LINK));
                                string statusInfo = "Сообщение доставляется.";
                                string statusDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss");
                                string sql        = $"UPDATE {Database.Tables.MESSAGES} SET STATUS='{MessageStatus.SENDING}', STATUS_INFO='{statusInfo}', STATUS_DATE='{statusDate}' WHERE LINK IN ({links})";
                                int    count      = _dataAdapter.ExecuteUpdate(sql);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    var error = new InvalidOperationException("Ошибка сканирования новых сообщений.", ex);
                    _logger.LogError(ex);
                    //this.Error?.Invoke(error);
                }
                finally
                {
                    if (_started)
                    {
                        if (sending)
                        {
                            _queryTimer.Interval = 1;
                        }
                        else
                        {
                            _queryTimer.Interval = _interval.TotalMilliseconds;
                        }

                        _queryTimer.Start();
                    }
                }
            }
        }
Пример #13
0
        public virtual void AddConditions(IDynamoCommonQuery dynamoQ, IDataQuery q)
        {
            if (q.Conditions.Count == 0)
            {
                return;
            }

            var dbConditions         = new List <DataConditionExpression>();
            var args                 = new Dictionary <string, object>();
            var sb                   = StringBuilderCache.Allocate();
            var isMultipleWithOrTerm = q.Conditions.Any(x => x.Term == QueryTerm.Or) &&
                                       q.Conditions.Count > 1;

            foreach (var condition in q.Conditions)
            {
                var fmt      = DynamoQueryConditions.GetExpressionFormat(condition.QueryCondition.Alias);
                var multiFmt = DynamoQueryConditions.GetMultiExpressionFormat(condition.QueryCondition.Alias);

                if (fmt == null && multiFmt == null && isMultipleWithOrTerm)
                {
                    throw new NotSupportedException(
                              $"DynamoDB does not support {condition.QueryCondition.Alias} filter with multiple OR queries");
                }

                if (fmt == null && multiFmt == null)
                {
                    continue;
                }

                dbConditions.Add(condition);

                if (sb.Length > 0)
                {
                    sb.Append(condition.Term == QueryTerm.Or ? " OR " : " AND ");
                }

                if (fmt != null)
                {
                    var pId = "p" + args.Count;
                    args[pId] = condition.Value;

                    sb.Append(string.Format(fmt, dynamoQ.GetFieldLabel(condition.Field.Name), ":" + pId));
                }
                else
                {
                    var multiExpr = GetMultiConditionExpression(dynamoQ, condition, multiFmt, args);
                    sb.Append(multiExpr);
                }
            }

            var filter = StringBuilderCache.Retrieve(sb);

            if (filter.Length > 0)
            {
                dynamoQ.AddFilter(filter, args);
            }

            q.Conditions.RemoveAll(dbConditions.Contains);
        }
Пример #14
0
        /// <summary>
        /// Get the SDMX Query Request
        /// </summary>
        /// <param name="query">
        /// The query
        /// </param>
        /// <param name="request">
        /// The output request
        /// </param>
        public void GetSdmxQuery(IDataQuery query, out string request)
        {
            IDataQueryFormat <string> structureQueryFormat    = new RestQueryFormat();
            IDataQueryFactory         dataQueryFactory        = new DataQueryFactory();
            IDataQueryBuilderManager  dataQueryBuilderManager = new DataQueryBuilderManager(dataQueryFactory);

            request = dataQueryBuilderManager.BuildDataQuery(query, structureQueryFormat);
        }
 public string BuildRestDataQuery(IDataQuery query)
 {
     IDataQueryFormat<string> dataQueryFormat = new RestQueryFormat();
     IDataQueryFactory dataQueryFactory = new DataQueryFactory();
     IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(dataQueryFactory);
     string restDataRequest = dataQueryBuilderManager.BuildDataQuery(query, dataQueryFormat);
     return restDataRequest;
 }
Пример #16
0
        protected override Task <IMultipleObjectResult <ICollection <Account>, Account> > GetByCriteria(Func <IQueryable <Account>, IQueryable <Account> > queryFunc)
        {
            IDataQuery <Account> dataQuery = Repository as IDataQuery <Account>;

            Contract.Assert(dataQuery != null);

            return(dataQuery.GetByCriteria(queryFunc: queryFunc));
        }
Пример #17
0
        /// <summary>
        /// Get the SDMX Query Request
        /// </summary>
        /// <param name="query">
        /// The SDMX Query
        /// </param>
        /// <param name="operation">
        /// The Web Service function
        /// </param>
        /// <param name="tempFileName">
        /// The temp file name
        /// </param>

        /* private void SendSdmxQuery(
         *   IDataQuery query,
         *   SDMXWSFunction operation,
         *   string tempFileName)*/
        public void GetSdmxQuery(IDataQuery query, out string request)
        {
            IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(new DataQueryFactory());
            var xdoc = dataQueryBuilderManager.BuildDataQuery(query, new QueryMessageV2Format());
            var doc  = new XmlDocument();

            request = xdoc.ToString();
        }
Пример #18
0
 /// <summary>
 /// 创建实例。
 /// </summary>
 /// <param name="query">数据查询。</param>
 /// <param name="reader">数据查询读取器。</param>
 /// <param name="type">类型。</param>
 public DataQueryEnumerator(IDataQuery <T> query, IDataQueryReader reader, System.Type type)
 {
     _query  = query;
     _reader = reader;
     _dataBinderObjectCache = query?.DataBinderObjectCache;
     _type = type;
     query?.DataContext.DisposableObjects.Add(this);
 }
Пример #19
0
        /// <summary>
        /// Parse request from <paramref name="input"/>
        /// </summary>
        /// <param name="input">
        /// The reader for the SDMX-ML or REST request
        /// </param>
        /// <returns>
        /// The <see cref="IStreamController{TWriter}"/>.
        /// </returns>
        public override IStreamController <TWriter> ParseRequest(IDataQuery input)
        {
            if (input == null)
            {
                throw new SdmxSemmanticException(Resources.ErrorOperationNotAccepted);
            }

            return(base.ParseRequest(input));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataRetrievalInfoTabular"/> 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="tabularWriter">
 /// The tabular Writer. 
 /// </param>
 public DataRetrievalInfoTabular(
     MappingSetEntity mappingSet,
     IDataQuery query,
     ConnectionStringSettings connectionStringSettings,
     ITabularWriter tabularWriter)
     : base(mappingSet, query, connectionStringSettings)
 {
     this._tabularWriter = tabularWriter;
 }
        /// <summary>
        /// Sends the SDMX Query Request
        /// </summary>
        /// <param name="query">
        /// The SDMX Query
        /// </param>
        /// <param name="operation">
        /// The Web Service function
        /// </param>
        /// <param name="tempFileName">
        /// The temp file name
        /// </param>
        private void SendSdmxQuery(IDataQuery query, SDMXWSFunction operation, string tempFileName)
        {
            IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(new DataQueryFactory());
            var xdoc = dataQueryBuilderManager.BuildDataQuery(query, new QueryMessageV2Format());
            var doc  = new XmlDocument();

            doc.LoadXml(xdoc.ToString());
            this.SendRequest(doc, operation, tempFileName);
        }
Пример #22
0
        /// <summary>
        /// Sends the SDMX Query Request
        /// </summary>
        /// <param name="query">
        /// The query
        /// </param>
        /// <param name="tempFileName">
        /// The output stream
        /// </param>
        private void SendSdmxQuery(IDataQuery query, string tempFileName)
        {
            IDataQueryFormat <string> structureQueryFormat    = new RestQueryFormat();
            IDataQueryFactory         dataQueryFactory        = new DataQueryFactory();
            IDataQueryBuilderManager  dataQueryBuilderManager = new DataQueryBuilderManager(dataQueryFactory);
            string request = dataQueryBuilderManager.BuildDataQuery(query, structureQueryFormat);

            this.SendRequest(request, tempFileName, RequestType.Data);
        }
Пример #23
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="observationLimit">
        /// The maximum number of observations to return
        /// </param>
        /// <returns>
        /// The SDMX-ML data as a stream.
        /// </returns>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, int observationLimit, string tempFileName)
        {
            query = new DataQueryFluentBuilder().Initialize(query.DataStructure, query.Dataflow)
                    .WithOrderAsc(true)
                    .WithDataQuerySelectionGroup(query.SelectionGroups).WithMaxObservations(observationLimit).
                    WithDataProviders(query.DataProvider).WithDataQueryDetail(query.DataQueryDetail).
                    WithDimensionAtObservation(query.DimensionAtObservation).Build();

            this.ExecuteQuery(query, operationName, tempFileName);
        }
Пример #24
0
        public async ValueTask <T> ExecuteScalar <T>(IDataQuery query, CancellationToken token = default)
        {
            await using var conn = new NpgsqlConnection(options.PostgreSQLMediaServer);
            var commandDef = new CommandDefinition(query.CmdText,
                                                   query.Parameters,
                                                   commandTimeout: options.CommandTimeout,
                                                   cancellationToken: token);

            return(await conn.ExecuteScalarAsync <T>(commandDef));
        }
Пример #25
0
        public virtual int Count(IDataQuery q)
        {
            var query = InitQuery(q)
                        .ApplyLimits(q.Offset, q.Rows)
                        .ApplyConditions(q.Conditions);

            var result = query.Count();

            return(result);
        }
        public override List <Into> LoadSelect <Into, From>(IDataQuery q)
        {
            var results = GetQuery <From>(q).ConvertTo <IEnumerable <Into> >().ToList(); // materialize results

            if (results.Count == 0)
            {
                throw HttpError.NotFound("No results found.");
            }

            return(results);
        }
        /// <summary>
        /// Выборка сообщений.
        /// </summary>
        /// <param name="dataQuery"></param>
        /// <returns></returns>
        public virtual IQueryOver <DAO.Message, DAO.Message> QueryMessages(IDataQuery dataQuery)
        {
            #region Validate parameters
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            #endregion

            return(dataQuery.Open <DAO.Message>());
        }
Пример #28
0
        public async ValueTask <int> Insert(IDataQuery query, object obj, CancellationToken token = default)
        {
            using (var conn = new NpgsqlConnection(config.PostgreSQL))
            {
                var commandDef = new CommandDefinition(query.CmdText,
                                                       obj,
                                                       commandTimeout: config.ConnectionTimeout,
                                                       cancellationToken: token);

                return(await conn.ExecuteAsync(commandDef));
            }
        }
Пример #29
0
        private IList<IViewTopUsers> GetTopUsers( IDataQuery query )
        {
            var getTopUsers = _repository.Find(query);
            IList<IViewTopUsers> filteredResult = getTopUsers;

            query.From = "viewTopUsersPercentage";
            this.Total = _repository.Count(query);

            _collection = filteredResult;

            return filteredResult;
        }
Пример #30
0
        public async ValueTask <T> FirstOrDefault <T>(IDataQuery query, CancellationToken token = default)
        {
            using (var conn = new NpgsqlConnection(config.PostgreSQL))
            {
                var commandDef = new CommandDefinition(query.CmdText,
                                                       query.Parameters,
                                                       commandTimeout: config.ConnectionTimeout,
                                                       cancellationToken: token);

                return(await conn.QueryFirstOrDefaultAsync <T>(commandDef));
            }
        }
Пример #31
0
 /// <summary>
 /// Executes a query
 /// </summary>
 /// <typeparam name="T">The type of data produced by the query.</typeparam>
 /// <param name="query">The query to be executed</param>
 /// <returns>The rows (if any) that satisfy the query</returns>
 /// <seealso cref="ExecuteSelect"/>
 internal IEnumerable <T> ExecuteQuery <T>(IDataQuery <T> query)
 {
     using (IDbCommandFactory c = GetCommandFactory())
         using (IDbCommand cmd = c.GetCommand(query.Text))
             using (IDataReader reader = cmd.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     yield return(query.CreateInstance(reader));
                 }
             }
 }
Пример #32
0
        private IList <IViewTopUsers> GetTopUsers(IDataQuery query)
        {
            var getTopUsers = _repository.Find(query);
            IList <IViewTopUsers> filteredResult = getTopUsers;

            query.From = "viewTopUsersPercentage";
            this.Total = _repository.Count(query);

            _collection = filteredResult;

            return(filteredResult);
        }
Пример #33
0
        private IList <IViewTopSongs> GetTopSongs(IDataQuery query)
        {
            query.OrderBy = " ArtistName ";
            var results = _repository.Find(query);

            query.From = "ViewTopSongsPercentage";
            this.Total = _repository.Count(query);

            _collection = results;

            return(results);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="status"></param>
        /// <param name="skip"></param>
        /// <param name="take"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public virtual List <Message> GetLastMessages(string status, int?skip, int?take, out int totalCount)
        {
            using (IDataQuery dataQuery = OpenQuery())
            {
                var query = dataQuery.Open <DAO.Message>();
                //if (String.IsNullOrEmpty(channel))
                //	query.Where(msg => msg.Channel == null || msg.Channel == "");
                //else if (channel != "*")
                //	query.Where(msg => msg.Channel == channel);

                if (status == MessageStatus.DRAFT)
                {
                    query.AndRestrictionOn(msg => msg.Status.Value).IsNull();
                }
                else if (!String.IsNullOrWhiteSpace(status))
                {
                    string[] statuses = status.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    query.AndRestrictionOn(msg => msg.Status.Value).IsIn(statuses);
                }
                totalCount = query.RowCount();


                //query = dataQuery.Open<DAO.Message>();
                //if ( status == MessageStatus.DRAFT )
                //{
                //	query.AndRestrictionOn(msg => msg.Status.Value).IsNull();
                //}
                //else if ( !String.IsNullOrWhiteSpace(status) )
                //{
                //	string[] statuses = status.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                //	query.AndRestrictionOn(msg => msg.Status.Value).IsIn(statuses);
                //}

                if (skip != null && skip > 0)
                {
                    query.Skip(skip.Value);
                }

                if (take != null)
                {
                    query.Take(take.Value);
                }

                //if ( String.IsNullOrEmpty(channel) )
                //	query.Where(msg => msg.Channel == null || msg.Channel == "");
                //else if ( channel != "*" )
                //	query.Where(msg => msg.Channel == channel);

                query.OrderBy(msg => msg.LINK).Desc();
                return(query.List().Select(msg => msg.ToObj()).ToList());
            }
        }
Пример #35
0
        /// <summary>
        /// Sends the SDMX Query Request
        /// </summary>
        /// <param name="query">
        /// The SDMX Query
        /// </param>
        /// <param name="operation">
        /// The Web Service function
        /// </param>
        /// <param name="output">
        /// The output stream
        /// </param>
        private void SendSdmxQuery(IDataQuery query, SDMXWSFunctionV21 operation, string tempFileName)
        {
            IDataQueryFormat <XDocument>             queryFormat = new StructSpecificDataFormatV21();
            IBuilder <IComplexDataQuery, IDataQuery> transformer = new DataQuery2ComplexQueryBuilder(true);
            IComplexDataQuery complexDataQuery = transformer.Build(query);

            IComplexDataQueryBuilderManager complexDataQueryBuilderManager = new ComplexDataQueryBuilderManager(new ComplexDataQueryFactoryV21());
            var xdoc = complexDataQueryBuilderManager.BuildComplexDataQuery(complexDataQuery, queryFormat);
            var doc  = new XmlDocument();

            doc.LoadXml(xdoc.ToString());
            this.SendRequest(doc, operation, tempFileName);
        }
        /// <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();
        }
Пример #37
0
        public IDbCommand CreateCommandFor(IDataQuery dataQuery)
        {
            _dbCommand = _databaseCommandProvider.CreateCommandForCurrentConnection();
            _dbCommand.CommandType = dataQuery.CommandType;
            _dbCommand.CommandText = dataQuery.CommandText;

            if (dataQuery.CommandTimeout.HasValue)
            {
                _dbCommand.CommandTimeout = (int) dataQuery.CommandTimeout.Value.TotalSeconds;
            }

            AddParametersForStoredProc(dataQuery);

            return _dbCommand;
        }
Пример #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataRetrievalInfoXS"/> 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="xsWriter">
 /// The ICrossSectionalWriter Writer. 
 /// </param>
 public DataRetrievalInfoXS(
     MappingSetEntity mappingSet,
     IDataQuery query,
     ConnectionStringSettings connectionStringSettings,
     ICrossSectionalWriterEngine xsWriter)
     : base(mappingSet, query, connectionStringSettings)
 {
     this._xsWriter = xsWriter;
     if (this.MeasureComponent == null)
     {
         foreach (var crossSectionalMeasure in this.MappingSet.Dataflow.Dsd.CrossSectionalMeasures)
         {
             this._xsMeasureCodeToConcept.Add(
                 crossSectionalMeasure.CrossSectionalMeasureCode, crossSectionalMeasure.Id);
         }
     }
 }
Пример #39
0
 public object ExecuteScalar(IDataQuery dataQuery)
 {
     try
     {
         using (var dbCommand = _databaseCommandFactory.CreateCommandFor(dataQuery))
         {
             using (_connectionHandler.GetHandler(dbCommand, _transactionManager))
             {
                 return dbCommand.ExecuteScalar();
             }
         }
     }
     catch(Exception)
     {
         _connectionHandler.CleanUp();
         throw;
     }
 }
Пример #40
0
 public object ExecuteScalar(IDataQuery dataQuery)
 {
     try
     {
         using (var dbCommand = _databaseCommandFactory.CreateCommandFor(dataQuery))
         {
             using (_connectionHandler.GetHandler(dbCommand, _transactionWrapper))
             {
                 return dbCommand.ExecuteScalar();
             }
         }
     }
     catch(Exception)
     {
         _connectionHandler.RollbackTransactionAndCloseConnection();
         throw;
     }
 }
Пример #41
0
        public IDatabaseReader ExecuteReader(IDataQuery dataQuery)
        {
            try
            {
                using (var dbCommand = _databaseCommandFactory.CreateCommandFor(dataQuery))
                {
                    if (_transactionWrapper.TransactionInProgress)
                        return _databaseReaderFactory.CreateDataReader(dbCommand.ExecuteReader());

                    return _databaseReaderFactory.CreateDataReader(dbCommand.ExecuteReader(CommandBehavior.CloseConnection));
                }
            }
            catch (Exception)
            {
                _connectionHandler.RollbackTransactionAndCloseConnection();
                throw;
            }
        }
Пример #42
0
 private void AddParametersForStoredProc(IDataQuery dataQuery)
 {
     foreach (var parameter in dataQuery.Parameters)
     {
         IDbDataParameter dataParameter = _dbCommand.CreateParameter();
         dataParameter.ParameterName = parameter.Key;
         dataParameter.Value = parameter.Value.Value; //TODO: sort this nonsense out!
         if (parameter.Value.Direction.HasValue)
         {
             dataParameter.Direction = parameter.Value.Direction.Value;
         }
         if (parameter.Value.Size.HasValue)
         {
             dataParameter.Size = parameter.Value.Size.Value;
         }
         if (parameter.Value.Type.HasValue)
         {
             dataParameter.DbType = ConvertSqlDbTypeToDbType(parameter.Value.Type.Value);
         }
         _dbCommand.Parameters.Add(dataParameter);
     }
 }
 /// <summary>
 /// Gets the data.
 /// </summary>
 /// <param name="dataQuery">
 /// The data query.
 /// </param>
 /// <param name="dataWriter">
 /// The data writer.
 /// </param>
 public virtual void GetData(IDataQuery dataQuery, ICrossSectionalWriterEngine dataWriter)
 {
     this._dataRetrievalWithCrossWriter.GetData(dataQuery, dataWriter);
 }
Пример #44
0
 /// <summary>
 /// Sends the SDMX Query Request
 /// </summary>
 /// <param name="query">
 /// The SDMX Query
 /// </param>
 /// <param name="operation">
 /// The Web Service function
 /// </param>
 /// <param name="tempFileName">
 /// The temp file name
 /// </param>
 private void SendSdmxQuery(IDataQuery query, SDMXWSFunction operation, string tempFileName)
 {
     IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(new DataQueryFactory());
     var xdoc = dataQueryBuilderManager.BuildDataQuery(query, new QueryMessageV2Format());
     var doc = new XmlDocument();
     doc.LoadXml(xdoc.ToString());
     this.SendRequest(doc, operation, tempFileName);
 }
        /// <summary>
        /// Gets the list of <paramref name="dimension"/> values inside a <paramref name="query"/>
        /// </summary>
        /// <param name="query">
        /// The SDMX Model query 
        /// </param>
        /// <param name="dimension">
        /// The <see cref="ComponentEntity"/> of a dimension 
        /// </param>
        /// <returns>
        /// the list of <paramref name="dimension"/> values inside a <paramref name="query"/> 
        /// </returns>
        private static IEnumerable<string> GetFromQueryDimensionValues(IDataQuery query, ComponentEntity dimension)
        {
            var xsMeasureValues = new List<string>();

            foreach (IDataQuerySelectionGroup sg in query.SelectionGroups)
            {
                if (sg.HasSelectionForConcept(dimension.Id))
                {
                    var selection = sg.GetSelectionsForConcept(dimension.Id);
                    if (selection.HasMultipleValues)
                    {
                        xsMeasureValues.AddRange(selection.Values);
                    }
                    else
                    {
                        xsMeasureValues.Add(selection.Value);
                    }
                }
            }

            return xsMeasureValues;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DataRetrievalInfo" /> 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="schemaVersion">The schema version.</param>
        /// <exception cref="System.ArgumentNullException">
        /// mappingSet
        /// or
        /// connectionStringSettings
        /// </exception>
        public DataRetrievalInfo(MappingSetEntity mappingSet, IDataQuery query, ConnectionStringSettings connectionStringSettings, SdmxSchemaEnumType schemaVersion)
        {
            if (mappingSet == null)
            {
                throw new ArgumentNullException("mappingSet");
            }

            if (connectionStringSettings == null)
            {
                throw new ArgumentNullException("connectionStringSettings");
            }

            this._mappingSet = mappingSet;
            this._query = query;
            this._connectionStringSettings = connectionStringSettings;
            this._schemaVersion = schemaVersion;

            if (schemaVersion == SdmxSchemaEnumType.VersionTwoPointOne)
            {
                this._isTimePeriodAtObservation = DimensionObject.TimeDimensionFixedId.Equals(query.DimensionAtObservation);
                if (!this._isTimePeriodAtObservation)
                {
                    this._dimensionAtObservation = query.DimensionAtObservation;
                }

                this._limit = 0; // REST does not support default limit.
            }
            else
            {
                this._limit = query.FirstNObservations.HasValue ? query.FirstNObservations.Value : 0;
                this._isTimePeriodAtObservation = true;
            }

            this.BuildMappings();
            this._buildEffectiveDimensionAtObservation = this.BuildEffectiveDimensionAtObservation();
            
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataRetrievalInfo"/> 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>
 public DataRetrievalInfo(MappingSetEntity mappingSet, IDataQuery query, ConnectionStringSettings connectionStringSettings)
     : this(mappingSet, query, connectionStringSettings, SdmxSchemaEnumType.VersionTwo)
 {
 }
Пример #48
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="observationLimit">
        /// The maximum number of observations to return
        /// </param>
        /// <param name="tempFileName">
        /// The temporary fila name
        /// </param>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, int observationLimit, string tempFileName)
        {
            query = new DataQueryFluentBuilder().Initialize(query.DataStructure, query.Dataflow)
                .WithDataQuerySelectionGroup(query.SelectionGroups).Build();

             this.ExecuteQuery(query, operationName, tempFileName);
        }
 /// <summary>
 /// Gets the data.
 /// </summary>
 /// <param name="dataQuery">The data query.</param>
 /// <param name="dataWriter">The data writer.</param>
 public virtual void GetData(IDataQuery dataQuery, IDataWriterEngine dataWriter)
 {
     this._dataRetrievalWithWriter.GetData(dataQuery, dataWriter);
 }
Пример #50
0
        /// <summary>
        /// SRA-349 Filter data to be returned
        /// </summary>
        /// <param name="query">
        /// The IDataQuery containing the SDMX query 
        /// </param>
        /// <returns>
        /// The filtered mapping set entity for the dataflow in <paramref name="query"/> 
        /// </returns>
        private MappingSetEntity FilterMappingSet(IDataQuery query, MappingSetEntity mappingSet)
        {
            return mappingSet;

            if (query.DataQueryDetail.EnumType == DataQueryDetailEnumType.DataOnly || query.DataQueryDetail.EnumType == DataQueryDetailEnumType.SeriesKeysOnly)
            {
                mappingSet.Dataflow.Dsd.Attributes.Clear();
                mappingSet.Dataflow.Dsd.Groups.Clear();
            }

            bool bReiterate = false;
            //Request details of the data to be returned (Full, DataOnly, SeriesKeyOnly, NoData) SRA-349
            switch (query.DataQueryDetail.EnumType)
            {
                case DataQueryDetailEnumType.DataOnly: //No Data attributes.
                    //Remove all attributes mappings from the MappingSetEntity
                    foreach (MappingEntity mapEntity in mappingSet.Mappings)
                    {
                        bReiterate = true;
                        while (bReiterate)
                        {
                            bReiterate = false;
                            foreach (ComponentEntity comp in mapEntity.Components)
                            {
                                if (IsAttributeComponent(comp))
                                {
                                    bReiterate = true;
                                    mapEntity.Components.Remove(comp);
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case DataQueryDetailEnumType.SeriesKeysOnly: //Only dimensions, only the Series element
                    //Remove all attributes & observation mapping  from the MappingSetEntity 
                    foreach (MappingEntity mapEntity in mappingSet.Mappings)
                    {
                        bReiterate = true;
                        while (bReiterate)
                        {
                            bReiterate = false;
                            foreach (ComponentEntity comp in mapEntity.Components)
                            {
                                if (IsObservationComponent(comp) || IsAttributeComponent(comp))
                                {
                                    bReiterate = true;
                                    mapEntity.Components.Remove(comp);
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case DataQueryDetailEnumType.NoData: //Groups, Series, Annotations, Attributes, Dimensions but no observations.
                    //Remove all observation mapping  from the MappingSetEntity
                    foreach (MappingEntity mapEntity in mappingSet.Mappings)
                    {
                        bReiterate = true;
                        while (bReiterate)
                        {
                            bReiterate = false;
                            foreach (ComponentEntity comp in mapEntity.Components)
                            {
                                if (IsObservationComponent(comp))
                                {
                                    bReiterate = true;
                                    mapEntity.Components.Remove(comp);
                                    break;
                                }
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
            return mappingSet;
        }
Пример #51
0
        /// <summary>
        /// This method initializes the Data Retriever. It performs some validation the Query, and retrieves from the Mapping Store the mapping set (if any) of the dataflow of the QueryBean 
        /// <note type="note">
        /// The
        /// <see cref="KeyFamilyBean"/>
        /// method should be called only after
        /// this method has been called.
        /// </note>
        /// </summary>
        /// <exception cref="DataRetrieverException">
        /// See the
        ///   <see cref="ErrorTypes"/>
        ///   for more details
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// ConnectionStringSettings is null
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// query is null
        /// </exception>
        /// <param name="query">
        /// The QueryBean containing the SDMX query 
        /// </param>
        /// <returns>
        /// The mapping set for the dataflow in <paramref name="query"/> 
        /// </returns>
        private MappingSetEntity Initialize(IDataQuery query)
        {
            Logger.Info(Resources.DataRetriever_RetrieveData_Start_Initializing_Data_Retriever);
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            // Get the dataflow from the query
            IDataflowObject dataFlow = DataRetrieverHelper.GetDataflowFromQuery(query);

            // get the mapping set and the keyfamilybean
            MappingSetEntity mappingSet = this.RetrieveMappingSet(dataFlow);

            // MAT-395
            if (mappingSet == null)
            {
                throw new DataRetrieverException(string.Format(CultureInfo.CurrentCulture, Resources.NoMappingForDataflowFormat1, dataFlow.Id),
                    SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.NoResultsFound));
                //ErrorTypes.NO_MAPPING_SET,
                //string.Format(CultureInfo.CurrentCulture, Resources.NoMappingForDataflowFormat1, dataFlow.Id));
            }

            mappingSet = FilterMappingSet(query, mappingSet);

            Logger.Info(Resources.DataRetriever_RetrieveData_End_Data_Retriever_initialization);
            return mappingSet;
        }
Пример #52
0
        /// <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 Cross Sectional writer 
        /// </param>
        /// <example>
        /// An example using this method in C# with <see cref="CrossSectionalWriter"/> 
        ///  <code source="ReUsingExamples\DataRetriever\ReUsingDataRetrieverCrossSectional.cs" lang="cs">
        /// </code>
        /// </example>
        public void GetData(IDataQuery dataQuery, ICrossSectionalWriterEngine 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 DataRetrievalInfoXS(mappingSet, dataQuery, this._connectionStringSettings, dataWriter)
                {
                    DefaultHeader = this._defaultHeader
                };
                ValidateMappingSet(info);
                this.WriteHeader(dataWriter, info);
                ICrossSectionalDataStructureObject crossDsd = dataQuery.DataStructure as ICrossSectionalDataStructureObject;

                //(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, crossDsd, header);

                this.GenerateSql(info, _sqlXsBuilder);

                // execute sql query.
                this.ExecuteSql(info, CrossSectionalQueryEngineManager.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);
                //ErrorTypes.DDB_CONNECTION_ERROR,
                //Resources.DataRetriever_ExecuteSqlQuery_Error_executing_generated_SQL_and_populating_SDMX_model,
                //ex);
            }
            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);
                //ErrorTypes.WRITING_OUTPUT_ERROR,
                //Resources.DataRetriever_ExecuteSqlQuery_Error_during_writing_responce,
                //ex);
            }
        }
Пример #53
0
        /// <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, IDsplDataWriterEngine 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, this._sdmxSchemaVersion)
                {
                    DefaultHeader = this._defaultHeader
                };
                ValidateMappingSet(info);

                //Pietro 27/01
                //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);

                //info.MappingSet.DataSet.Description.ToString()
                //info.MappingSet.Dataflow.Dsd.Id.ToString()
                dataWriter.SetDsdOrder(dataQuery.DataStructure);
                dataWriter.StartDataset(info.MappingSet.DataSet.Description.ToString(), dataQuery.Dataflow, dataQuery.DataStructure, header, null);

                // Generate sql query
                this.GenerateSql(info, _sqlBuilder);

                this.GenerateSql(info, SeriesDataSetSqlBuilder.Instance);

                this.GenerateSql(info, SeriesGroupSqlBuilder.Instance);                

                // execute sql query
                this.ExecuteSql(info, SeriesQueryEngineManager.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);
            }
        }
Пример #54
0
        /// <summary>
        /// This method generates the SQL SELECT statement for the dissemination database that will return the data for the incoming Query.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="query"/>
        ///   is null
        /// </exception>
        /// <exception cref="DataRetrieverException">
        /// <see cref="ErrorTypes"/>
        /// </exception>
        /// <param name="query">
        /// The <see cref="Estat.Sdmx.Model.Query.QueryBean"/> modeling an SDMX-ML Query 
        /// </param>
        /// <returns>
        /// The generated sql query. 
        /// </returns>
        /// <example>
        /// An example using this method in C#
        ///  <code source="ReUsingExamples\DataRetriever\ReUsingDataRetrieverManySteps.cs" lang="cs" />
        /// </example>
        public string GenerateSqlQuery(IDataQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            try
            {
                // Get mapping set
                MappingSetEntity mappingSet = this.Initialize(query);

                // build the data retrieval state
                var info = new DataRetrievalInfo(mappingSet, query, this._connectionStringSettings);

                // check if mapping set is complete. TODO Remove this when SRA-166 is implemented
                ValidateMappingSet(info);

                // Generate sql using Tabular SQL Builder and put the sql query into info.SqlString
                //this.GenerateSql(info, _sqlBuilderTabular);

                // return the sql query
                return info.SqlString;
            }
            catch (DataRetrieverException)
            {
                throw;
            }
            catch (SdmxException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new DataRetrieverException(ex,
                    SdmxErrorCode.GetFromEnum(SdmxErrorCodeEnumType.SemanticError),
                    Resources.DataRetriever_GenerateSqlQuery_Could_not_generate_sql_query);
            }
        }
Пример #55
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="tempFileName">
        /// The temporary file name
        /// </param>
        /// <exception cref="NsiClientException">
        /// Failute to execute query
        /// </exception>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            try
            {
                switch (operationName)
                {
                    case SDMXWSFunction.GetCompactData:
                        {
                            this.SendSdmxQuery(query, tempFileName);
                            using (var dataLocation = new FileReadableDataLocation(tempFileName))
                            {
                                var sdmxFooterMessage = SdmxMessageUtilExt.ParseSdmxFooterMessage(dataLocation);
                                if (sdmxFooterMessage!=null && (sdmxFooterMessage.Code.Equals("510") || sdmxFooterMessage.Code.Equals("130")))
                                {
                                    var sb = new StringBuilder();
                                    foreach (var footerText in sdmxFooterMessage.FooterText)
                                    {
                                        sb.Append(footerText.Value + " ");
                                    }
                                    string info = string.Format(CultureInfo.InvariantCulture, Resources.SdmxFooterMessage, sb, sdmxFooterMessage.Code, sdmxFooterMessage.Severity);
                                    Logger.ErrorFormat(CultureInfo.InvariantCulture, Resources.MaxObservations, info);
                                    throw new FooterMessageException(Resources.EnterMoreCriteria);
                                }
                            }
                            break;
                        }

                    case SDMXWSFunction.GetCrossSectionalData:
                        {
                            this._nsiClientWs.ExecuteQuery(query, operationName, tempFileName);
                            break;
                        }

                    default:
                        {
                            Logger.Error(Resources.ExceptionExecuteQuery);
                            throw new NsiClientException(Resources.ExceptionExecuteQuery);
                        }
                }
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (FooterMessageException e)
            {
                NsiClientHelper.TryToDelete(tempFileName);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
            }
        }
Пример #56
0
 public AccountNumberService(IDataQuery dataQuery)
 {
     this.dataQuery = dataQuery;
 }
Пример #57
0
 public IDataParameter ExecuteUpdate(IDataQuery dataQuery, string outputDataParameter)
 {
     try
     {
         using (var dbCommand = _databaseCommandFactory.CreateCommandFor(dataQuery))
         {
             using (_connectionHandler.GetHandler(dbCommand, _transactionWrapper))
             {
                 dbCommand.ExecuteNonQuery();
                 return (IDataParameter)dbCommand.Parameters[outputDataParameter];
             }
         }
     }
     catch (Exception)
     {
         _connectionHandler.RollbackTransactionAndCloseConnection();
         throw;
     }
 }
Пример #58
0
 public LoyaltyCardQueries(IDataQuery dataQuery)
 {
     this.dataQuery = dataQuery;
 }
Пример #59
0
 /// <summary>
 /// This method retrieves the <see cref="Estat.Sdmx.Model.Query.DataFlowBean"/> from a <see cref="Estat.Sdmx.Model.Query.QueryBean"/>
 /// </summary>
 /// <param name="query">
 /// The <see cref="Estat.Sdmx.Model.Query.QueryBean"/> conaining the <see cref="Estat.Sdmx.Model.Query.DataFlowBean"/> 
 /// </param>
 /// <exception cref="DataRetrieverException">
 /// See the
 ///   <see cref="ErrorTypes.QUERY_PARSING_ERROR"/>
 /// </exception>
 /// <returns>
 /// The <see cref="Estat.Sdmx.Model.Query.DataFlowBean"/> 
 /// </returns>
 public static IDataflowObject GetDataflowFromQuery(IDataQuery query)
 {
     return query.Dataflow;
 }
Пример #60
0
        /// <summary>
        /// Sends the SDMX Query Request
        /// </summary>
        /// <param name="query">
        /// The query
        /// </param>
        /// <param name="tempFileName">
        /// The output stream
        /// </param>
        private void SendSdmxQuery(IDataQuery query, string tempFileName)
        {
            IDataQueryFormat<string> structureQueryFormat= new RestQueryFormat();
            IDataQueryFactory dataQueryFactory = new DataQueryFactory();
            IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(dataQueryFactory);
            string request = dataQueryBuilderManager.BuildDataQuery(query, structureQueryFormat);

            this.SendRequest(request, tempFileName, RequestType.Data);
        }