Ejemplo n.º 1
0
        /// <summary>
        /// Multi-ResultSet일 경우에 DataTable 컬렉션으로 반환합니다.
        /// </summary>
        public static Task <IList <DataTable> > ExecuteDataTableAsListAsync(this SqlDatabase sqlDatabase,
                                                                            SqlCommand sqlCommand,
                                                                            int firstResult,
                                                                            int maxResults,
                                                                            params IAdoParameter[] parameters)
        {
            sqlCommand.ShouldNotBeNull("sqlCommand");
            firstResult.ShouldBePositiveOrZero("firstResult");
            maxResults.ShouldBePositiveOrZero("maxResults");

            if (IsDebugEnabled)
            {
                log.Debug("비동기 방식으로 ExecuteDataTableAsListAsync을 실행합니다.. " +
                          "CommandText=[{0}], firstResult=[{1}], maxResults=[{2}], Parameters=[{3}]",
                          sqlCommand.CommandText, firstResult, maxResults, parameters.CollectionToString());
            }

            return
                (ExecuteReaderAsync(sqlDatabase, sqlCommand, parameters)
                 .ContinueWith(task => {
                IList <DataTable> tables = new List <DataTable>();

                var reader = task.Result;
                var adapter = new AdoDataAdapter(sqlDatabase.GetDataAdapter());

                var resultCount = 0;
                do
                {
                    var dataTable = new DataTable {
                        Locale = CultureInfo.InvariantCulture
                    };
                    adapter.Fill(new[] { dataTable }, reader, firstResult, maxResults);

                    if (IsDebugEnabled)
                    {
                        log.Debug("비동기 방식으로 DataReader를 가져와 DataTable에 Load 했습니다!!! resultCount=[{0}]",
                                  ++resultCount);
                    }

                    tables.Add(dataTable);
                } while(reader.IsClosed == false && reader.NextResult());

                With.TryAction(reader.Dispose);
                With.TryAction(adapter.Dispose);

                return tables;
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Multi-ResultSet일 경우에 DataTable 컬렉션으로 반환합니다.
        /// NOTE: Oracle에서는 Multi-ResultSet 작업을 위해서 SQL 문이 상당히 복잡합니다. 차라리 ExecuteDataTableAsync를 여러개 호출하세요.
        /// </summary>
        public static Task <IList <OracleDataTable> > ExecuteDataTableAsListAsync(this EnterpriseLibrary.OracleDatabase oraDatabase,
                                                                                  OracleCommand oraCommand,
                                                                                  int?firstResult,
                                                                                  int?maxResults,
                                                                                  params IAdoParameter[] parameters)
        {
            oraCommand.ShouldNotBeNull("oraCommand");

            if (IsDebugEnabled)
            {
                log.Debug(
                    "비동기 방식으로 ExecuteDataTable을 실행합니다... CommandText=[{0}], firstResult=[{1}], maxResults=[{2}], Parameters=[{3}]",
                    oraCommand.CommandText, firstResult, maxResults, parameters.CollectionToString());
            }

            return
                (ExecuteReaderAsync(oraDatabase, oraCommand, parameters)
                 .ContinueWith(task => {
                IList <OracleDataTable> tables = new List <OracleDataTable>();

                if (IsDebugEnabled)
                {
                    log.Debug("비동기방식으로 OracleDataReader를 가져와, OracleDataTable로 빌드합니다...");
                }

                using (var reader = task.Result)
                    using (var adapter = new AdoDataAdapter(oraDatabase.GetDataAdapter())) {
                        do
                        {
                            var dataTable = new OracleDataTable {
                                Locale = CultureInfo.InvariantCulture
                            };
                            adapter.Fill(new[] { dataTable }, reader, firstResult ?? 0, maxResults ?? 0);

                            tables.Add(dataTable);
                        } while(reader.IsClosed == false && reader.NextResult());
                    }

                if (IsDebugEnabled)
                {
                    log.Debug("OracleDataReader로부터 OracleDataTable [{0}] 개를 빌드했습니다.", tables.Count);
                }

                return tables;
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Multi-ResultSet일 경우에 DataTable 컬렉션으로 반환합니다.
        /// </summary>
        public static Task <IList <DataTable> > ExecuteDataTableAsListAsync(this OdpNetDatabase db,
                                                                            OracleCommand cmd,
                                                                            int firstResult,
                                                                            int maxResults,
                                                                            params IAdoParameter[] parameters)
        {
            cmd.ShouldNotBeNull("cmd");
            firstResult.ShouldBePositiveOrZero("firstResult");
            maxResults.ShouldBePositiveOrZero("maxResults");

            if (IsDebugEnabled)
            {
                log.Debug(
                    "비동기 방식으로 ExecuteDataTableAsListAsync을 실행합니다... CommandText=[{0}], firstResult=[{1}], maxResults=[{2}], Parameters=[{3}]",
                    cmd.CommandText, firstResult, maxResults, parameters.CollectionToString());
            }

            return
                (ExecuteReaderAsync(db, cmd, parameters)
                 .ContinueWith(task => {
                IList <DataTable> tables = new List <DataTable>();

                using (var reader = task.Result)
                    using (var adapter = new AdoDataAdapter(db.GetDataAdapter())) {
                        do
                        {
                            var dataTable = new DataTable {
                                Locale = CultureInfo.InvariantCulture
                            };
                            adapter.Fill(new[] { dataTable }, reader, firstResult, maxResults);

                            if (IsDebugEnabled)
                            {
                                log.Debug("비동기 방식으로 DataReader를 가져와 DataTable에 Load 했습니다!!!");
                            }

                            tables.Add(dataTable);
                        } while(reader.IsClosed == false && reader.NextResult());
                    }

                return tables;
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }