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); }
/// <summary> /// Initialises a new instance of the <see cref="ProfiledDbDataAdapter"/> class. /// </summary> /// <param name="wrappedAdapter">The wrapped adapter.</param> /// <param name="profiler">The profiler.</param> /// <exception cref="ArgumentNullException">Throws when the <paramref name="wrappedAdapter"/> is <c>null</c>.</exception> public ProfiledDbDataAdapter(IDbDataAdapter wrappedAdapter, IDbProfiler profiler = null) { InternalAdapter = wrappedAdapter ?? throw new ArgumentNullException(nameof(wrappedAdapter)); _profiler = profiler ?? MiniProfiler.Current; InitCommands(wrappedAdapter); }
/// <summary> /// Creates a simple profiled connection instance. /// </summary> /// <param name="connection">The database connection to wrap</param> /// <param name="profiler">The profiler to use</param> public SimpleProfiledConnection(IDbConnection connection, IDbProfiler profiler) { _connection = connection; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initializes a new instance of the <see cref="ExecuteErrorEventArgs"/> class. /// </summary> /// <param name="profiler"> /// The database profiler. /// </param> /// <param name="exception"> /// The exception. /// </param> /// <exception cref="ArgumentNullException"> /// The <paramref name="exception"/> cannot be null. /// </exception> public ExecuteErrorEventArgs([NotNull] IDbProfiler profiler, [NotNull] Exception exception) { Contract.Requires(profiler != null); Contract.Requires(exception != null); this.Profiler = profiler; this.Exception = exception ?? throw new ArgumentNullException(nameof(exception)); }
/// <summary> /// Creates a ProfiledDbConnection instance and opens it /// </summary> public static DbConnection New(IDbConnectionFactory connectionFactory, IDbProfiler dbProfiler) { var connection = new ProfiledDbConnection(connectionFactory.CreateConnection(), dbProfiler); connection.Open(); return(connection); }
/// <summary> /// Initialises a new instance of the <see cref="SimpleProfiledConnection"/> class. /// Creates a simple profiled connection instance. /// </summary> /// <param name="connection"> /// The database connection to wrap /// </param> /// <param name="profiler"> /// The profiler to use /// </param> public SimpleProfiledConnection(IDbConnection connection, IDbProfiler profiler) { _connection = connection; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// dispose the command / connection and profiler. /// </summary> /// <param name="disposing">false if the dispose is called from a <c>finalizer</c></param> private void Dispose(bool disposing) { if (disposing && _connection != null && _connection.State != ConnectionState.Closed) { _connection.Dispose(); } _connection = null; _profiler = null; }
/// <summary> /// Initializes a new instance of the <see cref="ProfiledDbDataReader"/> class. /// </summary> /// <param name="reader">The reader.</param> /// <param name="profiler">The profiler.</param> public ProfiledDbDataReader(DbDataReader reader, IDbProfiler profiler) { WrappedReader = reader; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initialises a new instance of the <see cref="ProfiledDbDataReader"/> class. /// </summary> /// <param name="reader">The reader.</param> /// <param name="connection">The connection.</param> /// <param name="profiler">The profiler.</param> public ProfiledDbDataReader(DbDataReader reader, DbConnection connection, IDbProfiler profiler) { _reader = reader; if (profiler != null) { _profiler = profiler; } }
public ProfiledDbCommand(DbCommand command, DbConnection connection, IDbProfiler profiler) { if (command == null) throw new ArgumentNullException("command"); InternalCommand = command; _connection = connection; _profiler = profiler; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleProfiledDataReader"/> class. /// </summary> /// <param name="reader">The reader.</param> /// <param name="profiler">The profiler.</param> /// <exception cref="ArgumentNullException">Throws when the <paramref name="reader"/> is <c>null</c>.</exception> public SimpleProfiledDataReader(IDataReader reader, IDbProfiler profiler) { _reader = reader ?? throw new ArgumentNullException(nameof(reader)); if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initialises a new instance of the <see cref="ProfiledDbDataAdapter"/> class. /// </summary> /// <param name="wrappedAdapter">The wrapped adapter.</param> /// <param name="profiler">The profiler.</param> public ProfiledDbDataAdapter(IDbDataAdapter wrappedAdapter, IDbProfiler profiler = null) { if (wrappedAdapter == null) { throw new ArgumentNullException("wrappedAdapter"); } _adapter = wrappedAdapter; _profiler = profiler ?? MiniProfiler.Current; }
public ProfiledDbDataReader(DbDataReader reader, DbConnection connection, IDbProfiler profiler) { this.reader = reader; db = connection; if (profiler != null) { this.profiler = profiler; } }
/// <summary> /// Initializes a new instance of the <see cref="SimpleProfiledCommand"/> class, creating a new wrapped command. /// </summary> /// <param name="command">The wrapped command.</param> /// <param name="connection">The wrapped connection the command is attached to.</param> /// <param name="profiler">The profiler to use.</param> /// <exception cref="ArgumentNullException">Throws then the <paramref name="command"/> is <c>null</c>.</exception> public SimpleProfiledCommand(IDbCommand command, IDbConnection connection, IDbProfiler profiler) { _command = command ?? throw new ArgumentNullException(nameof(command)); _connection = connection; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initializes a new instance of the <see cref="ProfiledCommand"/> class. /// </summary> /// <param name="cmd">The command.</param> /// <param name="conn">The connection.</param> /// <param name="profiler">The profiler.</param> /// <exception cref="System.ArgumentNullException">cmd</exception> public ProfiledCommand(DbCommand cmd, DbConnection conn, IDbProfiler profiler) { this.cmd = cmd ?? throw new ArgumentNullException(nameof(cmd)); this.conn = conn; if (profiler != null) { DbProfiler = profiler; } }
public DatabaseManager(Func <DbContext> databaseFactory, ITransactionManager transactionManager = null, IDbProfiler dbProfiler = null, IQueryBuilder queryBuilder = null, Action <IDbConnection> afterCreatedAction = null) : base(transactionManager) { _databaseFactory = databaseFactory; _dbProfiler = dbProfiler; _queryBuilder = queryBuilder; _afterCreatedAction = afterCreatedAction; }
public ProfiledDbTransaction(DbTransaction transaction, ProfiledDbConnection connection, IDbProfiler profiler) { if (transaction == null) throw new ArgumentNullException("transaction"); if (connection == null) throw new ArgumentNullException("connection"); InnerTransaction = transaction; _connection = connection; _profiler = profiler; _connectionId = UniqueIdExtensions<DbConnection>.GetUniqueId(connection.InnerConnection).ToInt(); _profiler.TransactionBegan(connection.InnerConnection, NHProfilerContextProvider.GetLoggedDbConnection(this, _connectionId)); }
/// <summary> /// Initializes a new instance of the <see cref="ProfiledDbConnection"/> class. /// Returns a new <see cref="ProfiledDbConnection"/> that wraps <paramref name="connection"/>, /// providing query execution profiling. If profiler is null, no profiling will occur. /// </summary> /// <param name="connection"><c>Your provider-specific flavour of connection, e.g. SqlConnection, OracleConnection</c></param> /// <param name="profiler">The currently started <see cref="MiniProfiler"/> or null.</param> /// <exception cref="ArgumentNullException">Throws when <paramref name="connection"/> is <c>null</c>.</exception> public ProfiledDbConnection(DbConnection connection, IDbProfiler profiler) { _connection = connection ?? throw new ArgumentNullException(nameof(connection)); _connection.StateChange += StateChangeHandler; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initialises a new instance of the <see cref="SimpleProfiledDataReader"/> class. /// </summary> /// <param name="reader">The reader.</param> /// <param name="profiler">The profiler.</param> public SimpleProfiledDataReader(IDataReader reader, IDbProfiler profiler) { if (reader == null) throw new ArgumentNullException("reader"); _reader = reader; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initializes the specified connection. /// </summary> /// <param name="connection">The connection.</param> /// <param name="profiler">The profiler.</param> /// <param name="autoDisposeConnection">if set to <c>true</c> [automatic dispose connection].</param> /// <exception cref="System.ArgumentNullException">connection</exception> private void Init(DbConnection connection, IDbProfiler profiler, bool autoDisposeConnection) { AutoDisposeConnection = autoDisposeConnection; _conn = connection ?? throw new ArgumentNullException(nameof(connection)); _conn.StateChange += StateChangeHandler; if (profiler != null) { _profiler = profiler; } }
public ProfiledDbConnection(IDbConnection connection, IDbProfiler profiler) { var hasConn = connection as IHasDbConnection; if (hasConn != null) connection = hasConn.DbConnection; var dbConn = connection as DbConnection; if (dbConn == null) throw new ArgumentException(connection.GetType().Name + " does not inherit DbConnection"); Init(dbConn, profiler); }
/// <summary> /// dispose the command / connection and profiler. /// </summary> /// <param name="disposing">false if the dispose is called from a <c>finalizer</c></param> protected virtual void Dispose(bool disposing) { if (disposing && _command != null) { _command.Dispose(); } _command = null; _connection = null; _profiler = null; }
protected override void Dispose(bool disposing) { if (disposing && _conn != null) { _conn.StateChange -= StateChangeHandler; _conn.Dispose(); } _conn = null; _profiler = null; base.Dispose(disposing); }
public ProfiledDbConnection(IDbConnection connection, IDbProfiler profiler, bool autoDisposeConnection=true) { var hasConn = connection as IHasDbConnection; if (hasConn != null) connection = hasConn.DbConnection; var dbConn = connection as DbConnection; if (dbConn == null) throw new ArgumentException(connection.GetType().GetOperationName() + " does not inherit DbConnection"); Init(dbConn, profiler, autoDisposeConnection); }
/// <summary> /// Initialises a new instance of the <see cref="ProfiledDbCommand"/> class. /// </summary> /// <param name="command">The command.</param> /// <param name="connection">The connection.</param> /// <param name="profiler">The profiler.</param> public ProfiledDbCommand(DbCommand command, DbConnection connection) { if (command == null) { throw new ArgumentNullException("command"); } _command = command; _connection = connection; _profiler = MiniProfiler.Current; }
public ProfiledDbCommand(DbCommand cmd, DbConnection conn, IDbProfiler profiler) { if (cmd == null) throw new ArgumentNullException("cmd"); _cmd = cmd; _conn = conn; if (profiler != null) { _profiler = profiler; } }
public SqlConnectionManager(string connectionString, IConnectionProvider connectionProvider = null, ITransactionManager transactionManager = null, IDbProfiler dbProfiler = null, IQueryBuilder queryBuilder = null, Action <IDbConnection> afterCreatedAction = null) : base(transactionManager) { _connectionProvider = connectionProvider ?? new SqlConnectionProvider(); _connectionString = connectionString; _dbProfiler = dbProfiler; _queryBuilder = queryBuilder ?? new SqlServerQueryBuilder(); _afterCreatedAction = afterCreatedAction ?? (_ => { }); }
/// <summary> /// Returns a new <see cref="ProfiledDbConnection"/> that wraps <paramref name="connection"/>, /// providing query execution profiling. If profiler is null, no profiling will occur. /// </summary> /// <param name="connection">Your provider-specific flavor of connection, e.g. SqlConnection, OracleConnection</param> /// <param name="profiler">The currently started <see cref="MiniProfiler"/> or null.</param> public ProfiledDbConnection(DbConnection connection, IDbProfiler profiler) { if (connection == null) throw new ArgumentNullException("connection"); _conn = connection; _conn.StateChange += StateChangeHandler; if (profiler != null) { _profiler = profiler; } }
public ProfiledDbCommand(DbCommand command, DbConnection connection, IDbProfiler profiler) { if (command == null) { throw new ArgumentNullException("command"); } InternalCommand = command; _connection = connection; _profiler = profiler; }
private void Init(DbConnection connection, IDbProfiler profiler, bool autoDisposeConnection) { if (connection == null) throw new ArgumentNullException("connection"); this.autoDisposeConnection = autoDisposeConnection; _conn = connection; _conn.StateChange += StateChangeHandler; if (profiler != null) { _profiler = profiler; } }
public ProfiledConnection(IDbConnection connection, IDbProfiler profiler, bool autoDisposeConnection = true) { if (connection is IHasDbConnection hasConn) { connection = hasConn.DbConnection; } if (!(connection is DbConnection dbConn)) { throw new ArgumentException($"{connection.GetType().FullName} does not inherit DbConnection"); } Init(dbConn, profiler, autoDisposeConnection); }
/// <summary> /// Initialises a new instance of the <see cref="SimpleProfiledDataReader"/> class. /// </summary> /// <param name="reader">The reader.</param> /// <param name="profiler">The profiler.</param> public SimpleProfiledDataReader(IDataReader reader, IDbProfiler profiler) { if (reader == null) { throw new ArgumentNullException("reader"); } _reader = reader; if (profiler != null) { _profiler = profiler; } }
public ProfiledDbCommand(DbCommand cmd, DbConnection conn, IDbProfiler profiler) { if (cmd == null) { throw new ArgumentNullException("cmd"); } _cmd = cmd; _conn = conn; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initializes a <see cref="ProfiledDbDataReader"/>. /// </summary> /// <param name="dataReader">The <see cref="DbDataReader"/> to be profiled.</param> /// <param name="dbProfiler"> /// The <see cref="IDbProfiler"/> which profiles the <see cref="DbDataReader"/> /// </param> public ProfiledDbDataReader(DbDataReader dataReader, IDbProfiler dbProfiler) { if (dataReader == null) { throw new ArgumentNullException("dataReader"); } if (dbProfiler == null) { throw new ArgumentNullException("dbProfiler"); } _dataReader = dataReader; _dbProfiler = dbProfiler; }
/// <summary> /// Initializes a <see cref="ProfiledDbProviderFactory"/>. /// </summary> /// <param name="dbProviderFactory">The <see cref="DbProviderFactory"/> to be profiled.</param> /// <param name="dbProfiler">The <see cref="IDbProfiler"/>.</param> public ProfiledDbProviderFactory(DbProviderFactory dbProviderFactory, IDbProfiler dbProfiler) { if (dbProviderFactory == null) { throw new ArgumentNullException("dbProviderFactory"); } if (dbProfiler == null) { throw new ArgumentNullException("dbProfiler"); } _dbProviderFactory = dbProviderFactory; _dbProfiler = dbProfiler; }
/// <summary> /// Initialises a new instance of the <see cref="SimpleProfiledCommand"/> class. /// Creates a new wrapped command /// </summary> /// <param name="command">The wrapped command</param> /// <param name="connection">The wrapped connection the command is attached to</param> /// <param name="profiler">The profiler to use</param> public SimpleProfiledCommand(IDbCommand command, IDbConnection connection, IDbProfiler profiler) { if (command == null) { throw new ArgumentNullException("command"); } _command = command; _connection = connection; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Returns a new <see cref="ProfiledDbConnection"/> that wraps <paramref name="connection"/>, /// providing query execution profiling. If profiler is null, no profiling will occur. /// </summary> /// <param name="connection">Your provider-specific flavor of connection, e.g. SqlConnection, OracleConnection</param> /// <param name="profiler">The currently started <see cref="MiniProfiler"/> or null.</param> public ProfiledDbConnection(DbConnection connection, IDbProfiler profiler) { if (connection == null) { throw new ArgumentNullException("connection"); } _conn = connection; _conn.StateChange += StateChangeHandler; if (profiler != null) { _profiler = profiler; } }
public ProfiledSqlClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) : base(connectionManager, interceptor) { this.batchSize = Factory.Settings.AdoBatchSize; this.defaultTimeout = PropertiesHelper.GetInt32(global::NHibernate.Cfg.Environment.CommandTimeout, global::NHibernate.Cfg.Environment.Properties, -1); this.currentBatch = this.CreateConfiguredBatch(); // we always create this, because we need to deal with a scenario in which // the user change the logging configuration at runtime. Trying to put this // behind an if(log.IsDebugEnabled) will cause a null reference exception // at that point. this.currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); this.profiler = StackExchange.Profiling.MiniProfiler.Current as IDbProfiler; }
private void Init(DbConnection connection, IDbProfiler profiler, bool autoDisposeConnection) { if (connection == null) { throw new ArgumentNullException("connection"); } this.autoDisposeConnection = autoDisposeConnection; _conn = connection; _conn.StateChange += StateChangeHandler; if (profiler != null) { _profiler = profiler; } }
/// <summary> /// Initializes a <see cref="ProfiledDbDataReader"/>. /// </summary> /// <param name="dataReader">The <see cref="IDataReader"/> to be profiled.</param> /// <param name="dbProfiler"> /// The <see cref="IDbProfiler"/> which profiles the <see cref="IDataReader"/> /// </param> public ProfiledDbDataReader(IDataReader dataReader, IDbProfiler dbProfiler) { if (dataReader == null) { throw new ArgumentNullException("dataReader"); } if (dbProfiler == null) { throw new ArgumentNullException("dbProfiler"); } _dataReader = dataReader; _dbDataReader = dataReader as DbDataReader; _dbProfiler = dbProfiler; }
/// <summary> /// Initializes a <see cref="ProfiledDbConnection"/>. /// </summary> /// <param name="connection">The <see cref="IDbConnection"/> to be profiled.</param> /// <param name="dbProfiler">The <see cref="IDbProfiler"/>.</param> public ProfiledDbConnection(IDbConnection connection, IDbProfiler dbProfiler) { if (connection == null) { throw new ArgumentNullException("connection"); } if (dbProfiler == null) { throw new ArgumentNullException("dbProfiler"); } _connection = connection; _dbConnection = connection as DbConnection; if (_dbConnection != null) { _dbConnection.StateChange += StateChangeHandler; } _dbProfiler = dbProfiler; }
/// <summary> /// Initializes a <see cref="ProfiledDbCommand"/>. /// </summary> /// <param name="command">The <see cref="IDbCommand"/> to be profiled.</param> /// <param name="dbProfiler">The <see cref="IDbProfiler"/>.</param> /// <param name="tags">The tags of the <see cref="DbTiming"/> which will be created internally.</param> public ProfiledDbCommand(IDbCommand command, IDbProfiler dbProfiler, IEnumerable<string> tags = null) { if (command == null) { throw new ArgumentNullException("command"); } if (dbProfiler == null) { throw new ArgumentNullException("dbProfiler"); } _command = command; _dbCommand = command as DbCommand; _dbProfiler = dbProfiler; if (tags != null) { _tags = new List<string>(tags); } }
public ProfiledDbCommand(DbCommand cmd, DbConnection conn, IDbProfiler profiler) : base(cmd, conn, profiler) { }
/// <summary> /// Returns a new <see cref="ProfiledDbConnection"/> that wraps <paramref name="connection"/>, /// providing query execution profiling. /// </summary> /// <param name="connection">Your provider-specific flavor of connection, e.g. SqlConnection, OracleConnection</param> /// <param name="profiler">The currently started <see cref="MiniProfiler"/> or null.</param> public static DbConnection Get(DbConnection connection, IDbProfiler profiler) { return new ProfiledDbConnection(connection, profiler); }
/// <summary> /// Initialises a new instance of the <see cref="CountingConnection"/> class. /// </summary> /// <param name="connection"> /// The connection. /// </param> /// <param name="profiler"> /// The profiler. /// </param> public CountingConnection(DbConnection connection, IDbProfiler profiler) : base(connection, profiler) { CountingProfiler = (CountingDbProfiler)profiler; }
public ProfiledDbConnection(IDbConnection connection, IDbProfiler profiler, bool autoDisposeConnection=true) : base(connection, profiler, autoDisposeConnection) { }
/// <summary> /// proxy /// </summary> /// <param name="profiler"></param> /// <param name="tail"></param> public ProfiledDbProviderFactory(IDbProfiler profiler, DbProviderFactory tail) { this.profiler = profiler; this.tail = tail; }
private DbCommandProxy(DbCommand instance) : base(typeof (DbCommand)) { this.instance = instance; profiler = MiniProfiler.Current; }
public DatabaseInterceptor(IDbProfiler profiler) { _profiler = profiler; }
/// <summary> /// Returns a new <see cref="ProfiledDbConnection"/> that wraps <paramref name="connection"/>, /// providing query execution profiling. If profiler is null, no profiling will occur. /// </summary> /// <param name="connection">Your provider-specific flavor of connection, e.g. SqlConnection, OracleConnection</param> /// <param name="profiler">The currently started <see cref="MiniProfiler.Profiler"/> or null.</param> /// <param name="autoDisposeConnection">Determines whether the ProfiledDbConnection will dispose the underlying connection.</param> public ProfiledDbConnection(DbConnection connection, IDbProfiler profiler, bool autoDisposeConnection = true) { Init(connection, profiler, autoDisposeConnection); }
public ProfiledSqlCommand(DbCommand command, IDbProfiler profiler) : base(command, null, profiler) { _sqlCommand = (SqlCommand)command; }
/// <summary> /// Returns a new <see cref="ProfiledDbConnection"/> that wraps <paramref name="connection"/>, /// providing query execution profiling. If profiler is null, no profiling will occur. /// </summary> /// <param name="connection">Your provider-specific flavor of connection, e.g. SqlConnection, OracleConnection</param> /// <param name="profiler">The currently started <see cref="MiniProfiler.Profiler"/> or null.</param> public ProfiledDbConnection(DbConnection connection, IDbProfiler profiler) { Init(connection, profiler); }
private void Dispose(bool disposing) { if (disposing && _connection != null && _connection.State != ConnectionState.Closed) { _connection.Dispose(); } _connection = null; _profiler = null; }
private readonly string _category; // future use for multiples public LightweightProfiler(IDbProfiler wrapped, string category) { _category = category; _wrapped = wrapped; }