コード例 #1
0
ファイル: CountAll.cs プロジェクト: wanglin2019/RepoDB
        /// <summary>
        /// Count the number of rows from the table in an asynchronous way.
        /// </summary>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="tableName">The name of the target table to be used.</param>
        /// <param name="hints">The table hints to be used.</param>
        /// <param name="commandTimeout">The command timeout in seconds to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="trace">The trace object to be used.</param>
        /// <param name="statementBuilder">The statement builder object to be used.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param>
        /// <returns>An integer value that holds the number of rows from the table.</returns>
        internal static Task <long> CountAllAsyncInternal(this IDbConnection connection,
                                                          string tableName,
                                                          string hints                        = null,
                                                          int?commandTimeout                  = null,
                                                          IDbTransaction transaction          = null,
                                                          ITrace trace                        = null,
                                                          IStatementBuilder statementBuilder  = null,
                                                          CancellationToken cancellationToken = default)
        {
            // Variables
            var request = new CountAllRequest(tableName,
                                              connection,
                                              transaction,
                                              hints,
                                              statementBuilder);
            var param = (object)null;

            // Return the result
            return(CountAllAsyncInternalBase(connection: connection,
                                             request: request,
                                             param: param,
                                             commandTimeout: commandTimeout,
                                             transaction: transaction,
                                             trace: trace,
                                             cancellationToken: cancellationToken));
        }
コード例 #2
0
ファイル: CountAll.cs プロジェクト: bank2u/RepoDb
        /// <summary>
        /// CountAlls the number of table data from the database in an asynchronous way.
        /// </summary>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="tableName">The name of the target table to be used.</param>
        /// <param name="hints">The table hints to be used. See <see cref="SqlServerTableHints"/> class.</param>
        /// <param name="commandTimeout">The command timeout in seconds to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="trace">The trace object to be used.</param>
        /// <param name="statementBuilder">The statement builder object to be used.</param>
        /// <returns>An integer value that holds the number of data from the database.</returns>
        internal static Task <long> CountAllAsyncInternal(this IDbConnection connection,
                                                          string tableName,
                                                          string hints                       = null,
                                                          int?commandTimeout                 = null,
                                                          IDbTransaction transaction         = null,
                                                          ITrace trace                       = null,
                                                          IStatementBuilder statementBuilder = null)
        {
            // Variables
            var request = new CountAllRequest(tableName,
                                              connection,
                                              transaction,
                                              hints,
                                              statementBuilder);
            var commandText = CommandTextCache.GetCountAllText(request);
            var param       = (object)null;

            // Return the result
            return(CountAllInternalAsyncBase(connection: connection,
                                             request: request,
                                             param: param,
                                             commandTimeout: commandTimeout,
                                             transaction: transaction,
                                             trace: trace));
        }
コード例 #3
0
ファイル: CountAll.cs プロジェクト: wanglin2019/RepoDB
        /// <summary>
        /// Count the number of rows from the table in an asynchronous way.
        /// </summary>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="request">The actual <see cref="CountAllRequest"/> object.</param>
        /// <param name="param">The mapped object parameters.</param>
        /// <param name="commandTimeout">The command timeout in seconds to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="trace">The trace object to be used.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param>
        /// <returns>An integer value that holds the number of rows from the table.</returns>
        internal static async Task <long> CountAllAsyncInternalBase(this IDbConnection connection,
                                                                    CountAllRequest request,
                                                                    object param,
                                                                    int?commandTimeout         = null,
                                                                    IDbTransaction transaction = null,
                                                                    ITrace trace = null,
                                                                    CancellationToken cancellationToken = default)
        {
            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetCountAllText(request);
            var sessionId   = Guid.Empty;

            // Before Execution
            if (trace != null)
            {
                sessionId = Guid.NewGuid();
                var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null);
                trace.BeforeCountAll(cancellableTraceLog);
                if (cancellableTraceLog.IsCancelled)
                {
                    if (cancellableTraceLog.IsThrowException)
                    {
                        throw new CancelledExecutionException(commandText);
                    }
                    return(default(int));
                }
                commandText = (cancellableTraceLog.Statement ?? commandText);
                param       = (cancellableTraceLog.Parameter ?? param);
            }

            // Before Execution Time
            var beforeExecutionTime = DateTime.UtcNow;

            // Actual Execution
            var result = await ExecuteScalarAsyncInternal <long>(connection : connection,
                                                                 commandText : commandText,
                                                                 param : param,
                                                                 commandType : commandType,
                                                                 cacheKey : null,
                                                                 cacheItemExpiration : null,
                                                                 commandTimeout : commandTimeout,
                                                                 transaction : transaction,
                                                                 cache : null,
                                                                 cancellationToken : cancellationToken,
                                                                 entityType : request.Type,
                                                                 dbFields : await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken),
                                                                 skipCommandArrayParametersCheck : true);

            // After Execution
            if (trace != null)
            {
                trace.AfterCountAll(new TraceLog(sessionId, commandText, param, result,
                                                 DateTime.UtcNow.Subtract(beforeExecutionTime)));
            }

            // Result
            return(result);
        }
コード例 #4
0
ファイル: CountAll.cs プロジェクト: bank2u/RepoDb
        /// <summary>
        /// CountAlls the number of table data from the database in an asynchronous way.
        /// </summary>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="request">The actual <see cref="CountAllRequest"/> object.</param>
        /// <param name="param">The mapped object parameters.</param>
        /// <param name="commandTimeout">The command timeout in seconds to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="trace">The trace object to be used.</param>
        /// <returns>An integer value that holds the number of data from the database.</returns>
        internal static async Task <long> CountAllInternalAsyncBase(this IDbConnection connection,
                                                                    CountAllRequest request,
                                                                    object param,
                                                                    int?commandTimeout         = null,
                                                                    IDbTransaction transaction = null,
                                                                    ITrace trace = null)
        {
            // Validate
            InvokeValidatorValidateCountAllAsync(connection);

            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetCountAllText(request);

            // Before Execution
            if (trace != null)
            {
                var cancellableTraceLog = new CancellableTraceLog(commandText, param, null);
                trace.BeforeCountAll(cancellableTraceLog);
                if (cancellableTraceLog.IsCancelled)
                {
                    if (cancellableTraceLog.IsThrowException)
                    {
                        throw new CancelledExecutionException(commandText);
                    }
                    return(default(int));
                }
                commandText = (cancellableTraceLog.Statement ?? commandText);
                param       = (cancellableTraceLog.Parameter ?? param);
            }

            // Before Execution Time
            var beforeExecutionTime = DateTime.UtcNow;

            // Actual Execution
            var result = await ExecuteScalarAsyncInternal <long>(connection : connection,
                                                                 commandText : commandText,
                                                                 param : param,
                                                                 commandType : commandType,
                                                                 commandTimeout : commandTimeout,
                                                                 transaction : transaction,
                                                                 skipCommandArrayParametersCheck : true);

            // After Execution
            if (trace != null)
            {
                trace.AfterCountAll(new TraceLog(commandText, param, result,
                                                 DateTime.UtcNow.Subtract(beforeExecutionTime)));
            }

            // Result
            return(result);
        }
コード例 #5
0
ファイル: CommandTextCache.cs プロジェクト: orthoxerox/RepoDB
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 internal static string GetCountAllText(CountAllRequest request)
 {
     if (cache.TryGetValue(request, out var commandText) == false)
     {
         var statementBuilder = EnsureStatementBuilder(request.Connection, request.StatementBuilder);
         commandText = statementBuilder.CreateCountAll(new QueryBuilder(),
                                                       request.Name,
                                                       request.Hints);
         cache.TryAdd(request, commandText);
     }
     return(commandText);
 }
コード例 #6
0
ファイル: CountAll.cs プロジェクト: crazyants/RepoDb
        /// <summary>
        /// Counts all the table data from the database.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity object.</typeparam>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="hints">The table hints to be used. See <see cref="SqlTableHints"/> class.</param>
        /// <param name="commandTimeout">The command timeout in seconds to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="trace">The trace object to be used.</param>
        /// <param name="statementBuilder">The statement builder object to be used.</param>
        /// <returns>An integer value that holds the number of data from the database.</returns>
        internal static long CountAllInternal <TEntity>(this IDbConnection connection,
                                                        string hints                       = null,
                                                        int?commandTimeout                 = null,
                                                        IDbTransaction transaction         = null,
                                                        ITrace trace                       = null,
                                                        IStatementBuilder statementBuilder = null)
            where TEntity : class
        {
            // Variables
            var request = new CountAllRequest(typeof(TEntity),
                                              connection,
                                              hints,
                                              statementBuilder);
            var param = (object)null;

            // Return the result
            return(CountAllInternalBase(connection: connection,
                                        request: request,
                                        param: param,
                                        commandTimeout: commandTimeout,
                                        transaction: transaction,
                                        trace: trace));
        }