/// <summary>
        /// The execute database data reader.
        /// </summary>
        /// <param name="behavior">The behaviour.</param>
        /// <returns>the resulting <see cref="DbDataReader"/>.</returns>
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            if (_profiler == null || !_profiler.IsActive)
            {
                return(_command.ExecuteReader(behavior));
            }

            DbDataReader result = null;

            _profiler.ExecuteStart(this, SqlExecuteType.Reader);
            try
            {
                result = _command.ExecuteReader(behavior);
                result = new ProfiledDbDataReader(result, _connection, _profiler);
            }
            catch (Exception e)
            {
                _profiler.OnError(this, SqlExecuteType.Reader, e);
                throw;
            }
            finally
            {
                _profiler.ExecuteFinish(this, SqlExecuteType.Reader, result);
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// profile with results.
        /// </summary>
        /// <param name="type">The type of execution.</param>
        /// <param name="func">A function to execute against the profile result.</param>
        /// <typeparam name="TResult">the type of result to return.</typeparam>
        private TResult ProfileWith <TResult>(SqlExecuteType type, Func <TResult> func)
        {
            if (_profiler?.IsActive != true)
            {
                return(func());
            }

            TResult result;

            _profiler.ExecuteStart(this, type);
            try
            {
                result = func();
            }
            catch (Exception e)
            {
                _profiler.OnError(this, type, e);
                throw;
            }
            finally
            {
                _profiler.ExecuteFinish(this, type, null);
            }
            return(result);
        }
Example #3
0
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);

            ExecuteType executeType = GetExecuteType(methodMessage);

            if (executeType != ExecuteType.None)
            {
                profiler.ExecuteStart(instance, executeType);
            }

            object returnValue = methodMessage.MethodBase.Invoke(instance, methodMessage.Args);

            if (executeType == ExecuteType.Reader)
            {
                returnValue = new ProfiledDbDataReader((DbDataReader)returnValue, instance.Connection, profiler);
            }

            IMessage returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount,
                                                       methodMessage.LogicalCallContext, methodMessage);

            if (executeType == ExecuteType.Reader)
            {
                profiler.ExecuteFinish(instance, executeType, (DbDataReader)returnValue);
            }
            else if (executeType != ExecuteType.None)
            {
                profiler.ExecuteFinish(instance, executeType, null);
            }

            return(returnMessage);
        }
Example #4
0
    protected override void OnBeforePrepare(IDbCommand command)
    {
        base.OnBeforePrepare(command);

        ((OracleCommand)command).BindByName = true;

        IDbProfiler profiler = MiniProfiler.Current;

        if (profiler != null)
        {
            profiler.ExecuteStart((DbCommand)command, ExecuteType.None);
        }

        var detail = CallableParser.Parse(command.CommandText);

        if (!detail.IsCallable)
        {
            return;
        }

        command.CommandType = CommandType.StoredProcedure;
        command.CommandText = detail.FunctionName;

        var outCursor = command.CreateParameter();

        this.oracleDbType.SetValue(outCursor, this.oracleDbTypeRefCursor, null);

        outCursor.Direction = detail.HasReturn ? ParameterDirection.ReturnValue : ParameterDirection.Output;

        command.Parameters.Insert(0, outCursor);
    }
Example #5
0
        public void ExecuteStart(IDbCommand profiledDbCommand, SqlExecuteType executeType)
        {
            Count++;

            _wrapped?.ExecuteStart(profiledDbCommand, executeType);

            // This is subtle, avoid measure time gathering stack trace (that happens on execute start)
            _sw.Start();
        }
Example #6
0
        /// <summary>
        /// Adds or updates rows in the <see cref="T:System.Data.DataSet"/> to match those in the data source using the <see cref="T:System.Data.DataSet"/> name, and creates a <see cref="T:System.Data.DataTable"/> named "Table".
        /// </summary>
        /// <param name="dataSet">A <see cref="T:System.Data.DataSet"/> to fill with records and, if necessary, schema.</param>
        /// <returns>
        /// The number of rows successfully added to or refreshed in the <see cref="T:System.Data.DataSet"/>. This does not include rows affected by statements that do not return rows.
        /// </returns>
        public new int Fill(DataSet dataSet)
        {
            /*
             * The SqlDataAdapter type requires that you use a SqlDataCommand for the various adapter commands and will throw an
             * exception if you attempt to pass it a ProfiledDbCommand instead.  This method is a simple wrapper around the existing
             * Fill method and assumes that a single ExecuteReader method will eventually be called on the SelectCommand.  This is
             * somewhat of a hack but appears to be working to give rough timings.
             *
             * While I have not tested this with an oracle DataAdapter, I would guess that it works in much the same way as the
             * SqlDataAdapter type and would thus work fine with this workaround.
             */

            if (_profiler == null || !_profiler.IsActive || !(_selectCommand is DbCommand))
            {
                return(_adapter.Fill(dataSet));
            }

            int result;
            var cmd = (DbCommand)_selectCommand;

            _profiler.ExecuteStart(cmd, ExecuteType.Reader);
            try
            {
                result = _adapter.Fill(dataSet);
            }
            catch (Exception e)
            {
                _profiler.OnError(cmd, ExecuteType.Reader, e);
                throw;
            }
            finally
            {
                _profiler.ExecuteFinish(cmd, ExecuteType.Reader, TokenReader);
            }

            return(result);
        }
 public void ExecuteStart(IDbCommand profiledDbCommand, SqlExecuteType executeType)
 {
     _wrapped.ExecuteStart(profiledDbCommand, executeType);
 }