예제 #1
0
파일: SumAll.cs 프로젝트: aTiKhan/RepoDb
        /// <summary>
        /// Computes the sum value of the target field.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="request">The actual <see cref="SumAllRequest"/> 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>The sum value of the target field.</returns>
        internal static TResult SumAllInternalBase <TResult>(this IDbConnection connection,
                                                             SumAllRequest request,
                                                             object param,
                                                             int?commandTimeout         = null,
                                                             IDbTransaction transaction = null,
                                                             ITrace trace = null)
        {
            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetSumAllText(request);
            var sessionId   = Guid.Empty;

            // Before Execution
            if (trace != null)
            {
                sessionId = Guid.NewGuid();
                var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null);
                trace.BeforeSumAll(cancellableTraceLog);
                if (cancellableTraceLog.IsCancelled)
                {
                    if (cancellableTraceLog.IsThrowException)
                    {
                        throw new CancelledExecutionException(commandText);
                    }
                    return(default);
예제 #2
0
파일: SumAll.cs 프로젝트: aTiKhan/RepoDb
        /// <summary>
        /// Computes the sum value of the target field in an asynchronous way.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="field">The field to be summarized.</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>The sum value of the target field.</returns>
        internal static Task <TResult> SumAllAsyncInternal <TEntity, TResult>(this IDbConnection connection,
                                                                              Field field,
                                                                              string hints                        = null,
                                                                              int?commandTimeout                  = null,
                                                                              IDbTransaction transaction          = null,
                                                                              ITrace trace                        = null,
                                                                              IStatementBuilder statementBuilder  = null,
                                                                              CancellationToken cancellationToken = default)
            where TEntity : class
        {
            // Variables
            var request = new SumAllRequest(typeof(TEntity),
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);
            var param = (object)null;

            // Return the result
            return(SumAllAsyncInternalBase <TResult>(connection: connection,
                                                     request: request,
                                                     param: param,
                                                     commandTimeout: commandTimeout,
                                                     transaction: transaction,
                                                     trace: trace,
                                                     cancellationToken: cancellationToken));
        }
예제 #3
0
파일: SumAll.cs 프로젝트: aTiKhan/RepoDb
        /// <summary>
        /// Computes the sum value of the target field in an asynchronous way.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <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="field">The field to be summarized.</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>The sum value of the target field.</returns>
        internal static Task <TResult> SumAllAsyncInternal <TResult>(this IDbConnection connection,
                                                                     string tableName,
                                                                     Field field,
                                                                     string hints                        = null,
                                                                     int?commandTimeout                  = null,
                                                                     IDbTransaction transaction          = null,
                                                                     ITrace trace                        = null,
                                                                     IStatementBuilder statementBuilder  = null,
                                                                     CancellationToken cancellationToken = default)
        {
            // Variables
            var request = new SumAllRequest(tableName,
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);

            // Return the result
            return(SumAllAsyncInternalBase <TResult>(connection: connection,
                                                     request: request,
                                                     param: null,
                                                     commandTimeout: commandTimeout,
                                                     transaction: transaction,
                                                     trace: trace,
                                                     cancellationToken: cancellationToken));
        }
예제 #4
0
        /// <summary>
        /// Computes the sum value of the target field.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity.</typeparam>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="field">The field to be summarized.</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>
        /// <returns>The sum value of the target field.</returns>
        internal static object SumAllInternal <TEntity>(this IDbConnection connection,
                                                        Field field,
                                                        string hints                       = null,
                                                        int?commandTimeout                 = null,
                                                        IDbTransaction transaction         = null,
                                                        ITrace trace                       = null,
                                                        IStatementBuilder statementBuilder = null)
            where TEntity : class
        {
            // Variables
            var request = new SumAllRequest(typeof(TEntity),
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);
            var param = (object)null;

            // Return the result
            return(SumAllInternalBase(connection: connection,
                                      request: request,
                                      param: param,
                                      commandTimeout: commandTimeout,
                                      transaction: transaction,
                                      trace: trace));
        }
예제 #5
0
        /// <summary>
        /// Computes the sum value of the target field 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="field">The field to be summarized.</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>
        /// <returns>The sum value of the target field.</returns>
        internal static Task <object> SumAllAsyncInternal(this IDbConnection connection,
                                                          string tableName,
                                                          Field field,
                                                          string hints                       = null,
                                                          int?commandTimeout                 = null,
                                                          IDbTransaction transaction         = null,
                                                          ITrace trace                       = null,
                                                          IStatementBuilder statementBuilder = null)
        {
            // Variables
            var request = new SumAllRequest(tableName,
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);
            var param = (object)null;

            // Return the result
            return(SumAllInternalAsyncBase(connection: connection,
                                           request: request,
                                           param: param,
                                           commandTimeout: commandTimeout,
                                           transaction: transaction,
                                           trace: trace));
        }
예제 #6
0
        /// <summary>
        /// Computes the sum value of the target field in an asynchronous way.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="request">The actual <see cref="SumAllRequest"/> 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>The sum value of the target field.</returns>
        internal static async Task <TResult> SumAllAsyncInternalBase <TResult>(this IDbConnection connection,
                                                                               SumAllRequest request,
                                                                               object param,
                                                                               int?commandTimeout         = null,
                                                                               IDbTransaction transaction = null,
                                                                               ITrace trace = null,
                                                                               CancellationToken cancellationToken = default)
        {
            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetSumAllText(request);
            var sessionId   = Guid.Empty;

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

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

            // Actual Execution
            var result = await ExecuteScalarAsyncInternal <TResult>(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.AfterSumAll(new TraceLog(sessionId, commandText, param, result,
                                               DateTime.UtcNow.Subtract(beforeExecutionTime)));
            }

            // Result
            return(result);
        }
예제 #7
0
        /// <summary>
        /// Computes the sum value of the target field.
        /// </summary>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="request">The actual <see cref="SumAllRequest"/> 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>The sum value of the target field.</returns>
        internal static object SumAllInternalBase(this IDbConnection connection,
                                                  SumAllRequest request,
                                                  object param,
                                                  int?commandTimeout         = null,
                                                  IDbTransaction transaction = null,
                                                  ITrace trace = null)
        {
            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetSumAllText(request);
            var sessionId   = Guid.Empty;

            // Before Execution
            if (trace != null)
            {
                sessionId = Guid.NewGuid();
                var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null);
                trace.BeforeSumAll(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 = ExecuteScalarInternal <object>(connection: connection,
                                                        commandText: commandText,
                                                        param: param,
                                                        commandType: commandType,
                                                        commandTimeout: commandTimeout,
                                                        transaction: transaction,
                                                        skipCommandArrayParametersCheck: true);

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

            // Result
            return(result);
        }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 internal static string GetSumAllText(SumAllRequest request)
 {
     if (cache.TryGetValue(request, out var commandText) == false)
     {
         var statementBuilder = EnsureStatementBuilder(request.Connection, request.StatementBuilder);
         commandText = statementBuilder.CreateSumAll(new QueryBuilder(),
                                                     request.Name,
                                                     request.Field,
                                                     request.Hints);
         cache.TryAdd(request, commandText);
     }
     return(commandText);
 }