Ejemplo n.º 1
0
        /// <summary>
        /// Maximizes the target field from all data of the database table.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity object.</typeparam>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="field">The field to be maximumd.</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 maximum value.</returns>
        internal static object MaxAllInternal <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 MaxAllRequest(typeof(TEntity),
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);
            var param = (object)null;

            // Return the result
            return(MaxAllInternalBase(connection: connection,
                                      request: request,
                                      param: param,
                                      commandTimeout: commandTimeout,
                                      transaction: transaction,
                                      trace: trace));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Computes the max 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="tableName">The name of the target table to be used.</param>
        /// <param name="field">The field to be maximized.</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 max value of the target field.</returns>
        internal static TResult MaxAllInternal <TResult>(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 MaxAllRequest(tableName,
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);

            // Return the result
            return(MaxAllInternalBase <TResult>(connection: connection,
                                                request: request,
                                                param: null,
                                                commandTimeout: commandTimeout,
                                                transaction: transaction,
                                                trace: trace));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Maximizes the target field from all data of the database 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="field">The field to be maximumd.</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 maximum value.</returns>
        internal static Task <object> MaxAllAsyncInternal(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 MaxAllRequest(tableName,
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);
            var param = (object)null;

            // Return the result
            return(MaxAllInternalAsyncBase(connection: connection,
                                           request: request,
                                           param: param,
                                           commandTimeout: commandTimeout,
                                           transaction: transaction,
                                           trace: trace));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Computes the max 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 maximized.</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 max value of the target field.</returns>
        internal static Task <TResult> MaxAllAsyncInternal <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 MaxAllRequest(typeof(TEntity),
                                            connection,
                                            transaction,
                                            field,
                                            hints,
                                            statementBuilder);
            var param = (object)null;

            // Return the result
            return(MaxAllAsyncInternalBase <TResult>(connection: connection,
                                                     request: request,
                                                     param: param,
                                                     commandTimeout: commandTimeout,
                                                     transaction: transaction,
                                                     trace: trace,
                                                     cancellationToken: cancellationToken));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Computes the max 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="MaxAllRequest"/> 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 max value of the target field.</returns>
        internal static TResult MaxAllInternalBase <TResult>(this IDbConnection connection,
                                                             MaxAllRequest request,
                                                             object param,
                                                             int?commandTimeout         = null,
                                                             IDbTransaction transaction = null,
                                                             ITrace trace = null)
        {
            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetMaxAllText(request);
            var sessionId   = Guid.Empty;

            // Before Execution
            if (trace != null)
            {
                sessionId = Guid.NewGuid();
                var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null);
                trace.BeforeMaxAll(cancellableTraceLog);
                if (cancellableTraceLog.IsCancelled)
                {
                    if (cancellableTraceLog.IsThrowException)
                    {
                        throw new CancelledExecutionException(commandText);
                    }
                    return(default);
Ejemplo n.º 6
0
        /// <summary>
        /// Computes the max 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="MaxAllRequest"/> 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 max value of the target field.</returns>
        internal static async Task <TResult> MaxAllAsyncInternalBase <TResult>(this IDbConnection connection,
                                                                               MaxAllRequest request,
                                                                               object param,
                                                                               int?commandTimeout         = null,
                                                                               IDbTransaction transaction = null,
                                                                               ITrace trace = null,
                                                                               CancellationToken cancellationToken = default)
        {
            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetMaxAllText(request);
            var sessionId   = Guid.Empty;

            // Before Execution
            if (trace != null)
            {
                sessionId = Guid.NewGuid();
                var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null);
                trace.BeforeMaxAll(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.AfterMaxAll(new TraceLog(sessionId, commandText, param, result,
                                               DateTime.UtcNow.Subtract(beforeExecutionTime)));
            }

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

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

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

            // Result
            return(result);
        }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 internal static string GetMaxAllText(MaxAllRequest request)
 {
     if (cache.TryGetValue(request, out var commandText) == false)
     {
         var statementBuilder = EnsureStatementBuilder(request.Connection, request.StatementBuilder);
         commandText = statementBuilder.CreateMaxAll(new QueryBuilder(),
                                                     request.Name,
                                                     request.Field,
                                                     request.Hints);
         cache.TryAdd(request, commandText);
     }
     return(commandText);
 }