상속: MessageObjectBase
예제 #1
0
        /// <summary>
        /// Command를 수행하고, 결과를 XML 문자열로 반환합니다.
        /// </summary>
        /// <param name="repository">Repository</param>
        /// <param name="requestItem">요청 정보</param>
        /// <returns>Data 처리 결과의 XML 문자열</returns>
        public override string Execute(IAdoRepository repository, RequestItem requestItem) {
            Repository = repository;

            var method = requestItem.Method;
            var requestParameters = requestItem.Parameters;

            if(IsDebugEnabled)
                log.Debug("{0}를 수행합니다... method=[{1}], requestParameters=[{2}]",
                          GetType().FullName, method, requestParameters.CollectionToString());

            var query = repository.QueryProvider.GetQuery(method).AsText(method);
            string result;

            using(var cmd = repository.GetCommand(query, true)) {
                repository.ExecuteNonQuery(cmd, GetParameters(requestParameters));
                var outputs = AdoTool.GetOutputParameters(repository.Db, cmd);

                result = JsonTool.SerializeAsText(outputs);
            }

            if(IsDebugEnabled)
                log.Debug("{0}를 완료했습니다. method=[{1}], requestParameters=[{2}]",
                          GetType().FullName, method, requestParameters.CollectionToString());

            return result;
        }
예제 #2
0
        /// <summary>
        /// Command를 수행하고, 결과를 XML 문자열로 반환합니다.
        /// </summary>
        /// <param name="repository">Repository</param>
        /// <param name="requestItem">요청 정보</param>
        /// <returns>Data 처리 결과의 XML 문자열</returns>
        public override string Execute(IAdoRepository repository, RequestItem requestItem) {
            Repository = repository;

            var method = requestItem.Method;
            var requestParameters = requestItem.Parameters;

            if(IsDebugEnabled)
                log.Debug("{0}를 수행합니다. method=[{1}], parameters=[{2}]",
                          GetType().FullName, method, requestParameters.CollectionToString());


            var query = repository.QueryProvider.GetQuery(method).AsText(method);
            string result;

            using(var cmd = repository.GetCommand(query, GetParameters(requestParameters))) {
                var reader = repository.ExecuteReader(cmd);
                var records = BuildResponse(reader);
                result = JsonTool.SerializeAsText(records);
            }

            if(IsDebugEnabled)
                log.Debug("{0}를 완료했습니다. method=[{1}], requestParameters=[{2}]", GetType().FullName, method,
                          requestParameters.CollectionToString());

            return result;
        }
예제 #3
0
        public RequestMessage GetRequestMessage()
        {
            var request = new RequestMessage();

            for (int i = 0; i < RequestItemCount; i++)
            {
                var item = new RequestItem
                {
                    Method         = "Request Body " + i,
                    RequestMethod  = RequestMethodKind.Method,
                    ResponseFormat = ResponseFormatKind.ResultSet
                };

                Enumerable
                .Range(0, 5)
                .RunEach(p => {
                    var parameter = new RequestParameter("PARAM_" + p, p);
                    item.Parameters.Add(parameter);

                    item.PrepareStatements.Add("Prepare Statements " + p);
                    item.PostscriptStatements.Add("Postscript Statements " + p);
                });

                request.Items.Add(item);
            }

            request.PrepareStatements.Add("Request Prepare");
            request.PostscriptStatements.Add("Request Postscript");

            return(request);
        }
예제 #4
0
        public void OpenProcedureNoParams([Values("TenMostExpensiveProduct")] string method) {
            var requestMsg = CreateRequestMessage();

            var item = new RequestItem(method, ResponseFormatKind.ResultSet);

            requestMsg.Items.Add(item);

            var responseMsg = RunDataService(requestMsg);

            responseMsg.HasError.Should().Be.False();
        }
예제 #5
0
        public void OpenProcedure([Values(SP_CUSTOMER_ORDER_HISTORY)] string method,
                                  [Values("ANATR", "BOTTM", "DRACD")] string customerId) {
            var requestMsg = CreateRequestMessage();

            var item = new RequestItem(method, ResponseFormatKind.ResultSet);
            item.Parameters.Add(new RequestParameter("CustomerId", customerId));

            requestMsg.Items.Add(item);

            var responseMsg = RunDataService(requestMsg);

            AssertResponseMessage(responseMsg);
        }
예제 #6
0
        public RequestItem AddItem(string method, ResponseFormatKind responseForm, int?firstResult, int?maxResults)
        {
            var requestItem = new RequestItem
            {
                Method         = method,
                ResponseFormat = responseForm,
                FirstResult    = firstResult,
                MaxResults     = maxResults,
            };

            Items.Add(requestItem);
            return(requestItem);
        }
예제 #7
0
        public void ExecuteNonQuery([Values("Order, UpdateOrderFreight")] string method,
                                    [Values(0.1, -0.1)] decimal freightDelta) {
            // UPDATE Orders SET Freight = Freight + @FreightDelta

            var requestMsg = CreateRequestMessage();

            var item = new RequestItem(method, ResponseFormatKind.None);
            item.Parameters.Add(new RequestParameter("FreightDelta", freightDelta));

            requestMsg.Items.Add(item);

            var responseMsg = RunDataService(requestMsg);

            responseMsg.HasError.Should().Be.False();
        }
예제 #8
0
        protected override ResponseItem DoProcessRequestItem(RequestItem requestItem) {
            if(log.IsDebugEnabled)
                log.Debug("요청 Id=[{0}], Method=[{1}], Query=[{2}]에 대한 작업 처리를 시작합니다.",
                          requestItem.Id, requestItem.Method, requestItem.Query);

            var responseItem = new ResponseItem(requestItem);

            if(requestItem.Query.IsWhiteSpace())
                return responseItem;

            if(IsDebugEnabled)
                log.Debug("요청정보를 처리합니다. 메소드=[{0}], 인자=[{1}]",
                          requestItem.Method, requestItem.Parameters.CollectionToString());
            try {
                var command = DataCommandTool.GetCommand(requestItem.Method);

                Guard.Assert(command != null, "해당하는 메소드에 정의된 Command 가 없습니다. method=[{0}]", requestItem.Method);

                ExecuteQueries(requestItem.PreQueries);

                responseItem.ResultValue = command.Execute(AdoRepository, requestItem);

                if(IsDebugEnabled)
                    log.Debug("메소드를 실행했습니다. method=[{0}], resultValue=[{1}]", requestItem.Method, responseItem.ResultValue);

                ExecuteQueries(requestItem.PostQueries);
            }
            catch(Exception ex) {
                if(log.IsErrorEnabled)
                    log.ErrorException("쿼리문 수행에 실패했습니다. Query=" + requestItem.Query, ex);

                responseItem.Errors.Add(new ErrorMessage(ex));
            }

            if(log.IsDebugEnabled)
                log.Debug("요청 Id=[{0}], Method=[{1}], Query=[{2}]에 대한 작업 처리를 완료했습니다!!!",
                          requestItem.Id, requestItem.Method, requestItem.Query);

            return responseItem;
        }
예제 #9
0
        /// <summary>
        /// 요청 쿼리 문을 수행하는데, 
        /// <see cref="IAdoRepository.ExecuteNonQuery(string,IAdoParameter[])" /> 나 
        /// <see cref="IAdoRepository.ExecuteScalar(string,IAdoParameter[])"/> 를 실행합니다.
        /// </summary>
        /// <param name="requestItem"></param>
        /// <param name="responseItem"></param>
        /// <param name="adoParameters"></param>
        protected virtual void ExecuteQuery(RequestItem requestItem, ResponseItem responseItem, IAdoParameter[] adoParameters) {
            // Scalar 값 구하기
            if(requestItem.ResponseFormat == ResponseFormatKind.Scalar) {
                if(IsDebugEnabled)
                    log.Debug("ExecuteNonScalar 를 수행하여, ResultValue 값을 설정합니다...");

                responseItem.ResultValue = AdoRepository.ExecuteScalar(requestItem.Query, adoParameters);
                return;
            }

            // 쿼리문이라면, 실행
            var query = requestItem.Query;
            if(AdoTool.IsSqlString(query)) {
                if(IsDebugEnabled)
                    log.Debug("ExecuteNonQuery 를 수행하고, 영향받은 행의 수를 ResultValue에 설정합니다...");

                responseItem.ResultValue = AdoRepository.ExecuteNonQuery(requestItem.Query, adoParameters);
                return;
            }


            if(IsDebugEnabled)
                log.Debug("ExecuteProcedure를 수행하고, Parameter 정보들을 ResultSet에 설정합니다.");

            //  Procedure 라면, Output Parameter 등을 ResultSet으로 반환함.
            //! 단 Procedure가 ResultSet을 반환해야 하는 경우는 OpenQuery를 수행할 수 있도록 ResponseFormat 을 ResponseFormatKind.ResultSet 으로 할 것
            //
            var parameters = AdoRepository.ExecuteProcedure(query, adoParameters);

            if(parameters != null) {
                responseItem.ResultValue = parameters.GetReturnValue();

                var row = new ResultRow(parameters.ToDictionary(p => p.Name, p => p.Value));
                responseItem.ResultSet.Add(row);
            }
        }
예제 #10
0
        /// <summary>
        /// 요청 쿼리 문을 수행하여, <see cref="ResultSet"/> 으로 빌드하여, 응답 결과를 적용합니다.
        /// </summary>
        protected virtual void OpenQuery(RequestItem requestItem, ResponseItem responseItem, IAdoParameter[] adoParameters) {
            if(IsDebugEnabled)
                log.Debug("쿼리문을 수행하여 결과셋을 설정합니다...");

            using(var cmd = AdoRepository.GetCommand(requestItem.Query)) {
                var reader = AdoRepository.ExecuteReader(cmd, adoParameters);
                var resultSet = reader.CreateResultSet(NameMapper,
                                                       requestItem.FirstResult.GetValueOrDefault(),
                                                       requestItem.MaxResults.GetValueOrDefault(int.MaxValue));

                responseItem.ResultSet = resultSet;
            }
        }
예제 #11
0
        protected virtual ResponseItem DoProcessRequestItem(RequestItem requestItem) {
            if(log.IsDebugEnabled)
                log.Debug("요청 Id=[{0}], Method=[{1}], Query=[{2}]에 대한 작업 처리를 시작합니다.",
                          requestItem.Id, requestItem.Method, requestItem.Query);

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var responseItem = new ResponseItem(requestItem);

            if(requestItem.Query.IsWhiteSpace())
                return responseItem;

            try {
                ExecuteQueries(requestItem.PreQueries);

                var adoParams = requestItem.BuildAdoParameters().ToArray();

                if(requestItem.ResponseFormat == ResponseFormatKind.ResultSet)
                    OpenQuery(requestItem, responseItem, adoParams);
                else
                    ExecuteQuery(requestItem, responseItem, adoParams);

                ExecuteQueries(requestItem.PostQueries);
            }
            catch(Exception ex) {
                if(log.IsErrorEnabled)
                    log.ErrorException("쿼리문 수행에 실패했습니다. Query=" + requestItem.Query, ex);

                responseItem.Errors.Add(new ErrorMessage(ex));
            }

            stopwatch.Stop();
            responseItem.ExecutionTime = stopwatch.Elapsed;

            if(log.IsDebugEnabled)
                log.Debug("요청 Id=[{0}], Method=[{1}], Query=[{2}]에 대한 작업 처리를 완료했습니다!!! 수행시간=[{3}]",
                          requestItem.Id, requestItem.Method, requestItem.Query, responseItem.ExecutionTime);

            return responseItem;
        }
예제 #12
0
 public ResponseItem(RequestItem requestItem) : this()
 {
     RequestItem = requestItem;
 }
예제 #13
0
 /// <summary>
 /// Command를 수행하고, 결과를 XML 문자열로 반환합니다.
 /// </summary>
 /// <param name="repository">Repository</param>
 /// <param name="requestItem">요청 정보</param>
 /// <returns>Data 처리 결과의 XML 문자열</returns>
 public abstract string Execute(IAdoRepository repository, RequestItem requestItem);
예제 #14
0
 public ResponseItem(RequestItem requestItem) : this() {
     RequestItem = requestItem;
 }
예제 #15
0
        public RequestItem AddItem(string method, ResponseFormatKind responseForm, int? firstResult, int? maxResults) {
            var requestItem = new RequestItem
                              {
                                  Method = method,
                                  ResponseFormat = responseForm,
                                  FirstResult = firstResult,
                                  MaxResults = maxResults,
                              };

            Items.Add(requestItem);
            return requestItem;
        }