예제 #1
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 override 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 (_auditor == null || !(_selectCommand is DbCommand))
            {
                return(_adapter.Fill(dataSet));
            }

            int result;
            var cmd = (DbCommand)_selectCommand;

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

            return(result);
        }
예제 #2
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            if (_auditor == null)
            {
                return(_command.ExecuteReader(behavior));
            }

            DbDataReader result = null;

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

            return(result);
        }