示例#1
0
        /// <summary>
        /// <paramref name="cmd"/> 를 비동기 방식으로 실행하여, <see cref="Task{OdpNetDataReader}"/>를 반환받습니다.
        /// 받환받은 DataReader는 꼭 Dispose() 해 주어야 Connection이 닫힙니다.
        /// </summary>
        /// <param name="db">DAAB의 MySQL 용 Database</param>
        /// <param name="cmd">실행할 <see cref="OracleCommand"/> 인스턴스</param>
        /// <param name="parameters">Command Parameters</param>
        /// <returns><see cref="OracleDataReader"/>를 결과로 반환하는 <see cref="Task"/></returns>
        public static Task <OracleDataReader> ExecuteReaderAsync(this OdpNetDatabase db, OracleCommand cmd,
                                                                 params IAdoParameter[] parameters)
        {
            cmd.ShouldNotBeNull("cmd");

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

            if (parameters != null)
            {
                AdoTool.SetParameterValues(db, cmd, parameters);
            }

            db.PrepareCWRefCursor(cmd);

            var newConnectionCreated = false;

            if (cmd.Connection == null)
            {
                cmd.Connection = db.CreateOracleConnection(ref newConnectionCreated);
            }

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

            return(Task.Factory.StartNew(() => cmd.ExecuteReader(commandBehavior),
                                         TaskCreationOptions.PreferFairness));
        }
示例#2
0
        /// <summary>
        /// <paramref name="cmd"/> 를 비동기 방식으로 실행하여, Scalar 값을 반환하는 <see cref="Task{Object}"/>를 빌드합니다.
        /// </summary>
        /// <param name="db">DAAB의 MySQL 용 Database</param>
        /// <param name="cmd">실행할 OracleCommand 인스턴스</param>
        /// <param name="parameters">Command Parameters</param>
        /// <returns>Scalar 값을 결과로 가지는 Task의 인스턴스</returns>
        public static Task <object> ExecuteScalarAsync(this OdpNetDatabase db, OracleCommand cmd, params IAdoParameter[] parameters)
        {
            cmd.ShouldNotBeNull("cmd");

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

            var newConnectionCreated = false;

            if (cmd.Connection == null)
            {
                cmd.Connection = db.CreateOracleConnection(ref newConnectionCreated);
            }

            if (parameters != null)
            {
                AdoTool.SetParameterValues(db, cmd, parameters);
            }

            db.PrepareCWRefCursor(cmd);

            return
                (Task.Factory
                 .StartNew(() => cmd.ExecuteScalar(), TaskCreationOptions.PreferFairness)
                 .ContinueWith(task => {
                if (newConnectionCreated)
                {
                    AdoTool.ForceCloseConnection(cmd);
                }

                return task;
            },
                               TaskContinuationOptions.ExecuteSynchronously)
                 .Unwrap());
        }