예제 #1
0
        /// <summary>
        /// <paramref name="oraCommand"/> 를 이용하여, <see cref="Task{OracleDataReader}"/>를 반환받습니다.
        /// 받환받은 DataReader는 꼭 Dispose() 해 주어야 Connection이 닫힙니다.
        /// </summary>
        /// <param name="oraDatabase">Devart dotConnector for Oracle을 이용하여 생성한 OracleProvider</param>
        /// <param name="oraCommand">실행할 OracleCommand 인스턴스</param>
        /// <param name="parameters">Command Parameters</param>
        /// <returns>OracleDataReader를 결과로 반환하는 Task</returns>
        public static Task <OracleDataReader> ExecuteReaderAsync(this EnterpriseLibrary.OracleDatabase oraDatabase,
                                                                 OracleCommand oraCommand, params IAdoParameter[] parameters)
        {
            oraCommand.ShouldNotBeNull("oraCommand");

            if (IsDebugEnabled)
            {
                log.Debug("OracleCommand.ExecuteReader를 비동기 방식으로 실행합니다. CommandText=[{0}], Parameters=[{1}]",
                          oraCommand.CommandText, parameters.CollectionToString());
            }

            var newConnectionCreated = false;

            if (oraCommand.Connection == null)
            {
                oraCommand.Connection = oraDatabase.CreateOracleConnection(ref newConnectionCreated);
            }

            if (parameters != null)
            {
                AdoTool.SetParameterValues(oraDatabase, oraCommand, parameters);
            }

            var commandBehavior = newConnectionCreated ? CommandBehavior.CloseConnection : CommandBehavior.Default;

            // NOTE: FromAsync를 사용하지 못한 이유가 OracleCommand.BeginExecuteReader() 의 overloading이 많아서, 모호한 함수 호출 때문이다.
            //
            var ar = oraCommand.BeginExecuteReader(commandBehavior);

            return
                (Task <OracleDataReader> .Factory.StartNew(state => oraCommand.EndExecuteReader((IAsyncResult)state),
                                                           ar,
                                                           TaskCreationOptions.PreferFairness));
        }