protected virtual IDbExecuteContext Execute(MySqlCommand command, IDbTracing tracing) { if (command == null) { throw new ArgumentNullException(nameof(command)); } try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); command = ApplyConnection(command); var context = CreateExecuteContext(command.Connection, command.ExecuteReader(), tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
private IDbExecuteContext Execute(SQLiteCommand command, IDbTracing tracing) { try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); if (Connection.State == ConnectionState.Closed) { Connection.Open(); } command.Connection = Connection; if (Configuration.QueryExecutingTimeout.HasValue) { command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds; } var context = new SQLiteExecuteContext(command.ExecuteReader(), tracing, SyncRoot); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
/// <summary> /// 执行查询命令并返回执行上下文 /// </summary> /// <param name="command">查询命令</param> /// <param name="tracing">用于追踪查询过程的追踪器</param> /// <returns>查询执行上下文</returns> protected virtual IDbExecuteContext Execute(SqlCommand command, IDbTracing tracing = null) { try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); var connection = new SqlConnection(ConnectionString); connection.Open(); command.Connection = connection; if (Configuration.QueryExecutingTimeout.HasValue) { command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds; } var reader = command.ExecuteReader(); var context = new SqlDbExecuteContext(connection, reader, tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
protected virtual IDbExecuteContext Execute(MySqlCommand command, IDbTracing tracing) { if (command == null) { throw new ArgumentNullException(nameof(command)); } try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); var connection = CreateConnection(); command.Connection = connection; if (Configuration.QueryExecutingTimeout.HasValue) { command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds; } var context = CreateExecuteContext(connection, command.ExecuteReader(), tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
/// <summary> /// 尝试执行查询追踪器的一个追踪方法,此方法会自动判断追踪器是否存在以及对调用中出现的异常进行异常屏蔽。 /// </summary> /// <param name="tracing">查询追踪器,如果有的话</param> /// <param name="action">要执行的追踪操作</param> protected void TryExecuteTracing(IDbTracing tracing, Action <IDbTracing> action) { if (tracing == null) { return; } try { action(tracing); } catch { } }
/// <summary> /// 创建数据库查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="sync">用于同步的对象,如果有的话</param> /// protected DbExecuteContextBase(IDataReader dataReader, IDbTracing tracing = null, object sync = null) { DataReader = dataReader ?? throw new ArgumentNullException(nameof(dataReader)); SyncRoot = sync; Tracing = tracing; DataTableAdapter = new DataTableAdapter(); if (SyncRoot != null) { Monitor.Enter(SyncRoot); } }
protected override IDbExecuteContext Execute(MySqlCommand command, IDbTracing tracing) { TryExecuteTracing(tracing, t => t.OnExecuting(command)); command.Connection = _transaction.Connection; command.Transaction = _transaction.Transaction; if (Configuration.QueryExecutingTimeout.HasValue) { command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds; } var dataReader = command.ExecuteReader(); var context = new MySqlExecuteContext(_transaction, dataReader, tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); }
/// <summary> /// 创建数据库查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="connectionResource">销毁该上下文时,需要同时销毁的连接资源</param> /// <param name="sync">用于同步的对象,如果有的话</param> protected DbExecuteContextBase( IDataReader dataReader, IDbTracing tracing = null, IDisposable connectionResource = null, object sync = null ) { if ( dataReader == null ) throw new ArgumentNullException( "dataReader" ); SyncRoot = sync; DataReader = dataReader; ConnectionResource = connectionResource; Tracing = tracing; DataTableAdapter = new DataTableAdapter(); if ( SyncRoot != null ) Monitor.Enter( SyncRoot ); }
/// <summary> /// 执行查询命令并返回执行上下文 /// </summary> /// <param name="command">查询命令</param> /// <param name="tracing">用于追踪查询过程的追踪器</param> /// <returns>查询执行上下文</returns> protected sealed override IDbExecuteContext Execute(NpgsqlCommand command, IDbTracing tracing = null) { try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); command.Connection = TransactionContext.Connection; command.Transaction = TransactionContext.Transaction; var reader = command.ExecuteReader(); var context = new NpgsqlDbExecuteContext(TransactionContext, reader, tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
/// <summary> /// 创建数据库查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="connectionResource">销毁该上下文时,需要同时销毁的连接资源</param> /// <param name="sync">用于同步的对象,如果有的话</param> protected DbExecuteContextBase(IDataReader dataReader, IDbTracing tracing = null, IDisposable connectionResource = null, object sync = null) { if (dataReader == null) { throw new ArgumentNullException("dataReader"); } SyncRoot = sync; DataReader = dataReader; ConnectionResource = connectionResource; Tracing = tracing; DataTableAdapter = new DataTableAdapter(); if (SyncRoot != null) { Monitor.Enter(SyncRoot); } }
/// <summary> /// 创建数据库查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="disposeMethod">销毁上下文时要执行的方法</param> /// <param name="sync">用于同步的对象,如果有的话</param> protected DbExecuteContextBase(IDataReader dataReader, IDbTracing tracing = null, Action disposeMethod = null, object sync = null) { if (dataReader == null) { throw new ArgumentNullException("dataReader"); } SyncRoot = sync; this.disposeMethod = disposeMethod; DataReader = dataReader; Tracing = tracing; DataTableAdapter = new DataTableAdapter(); if (SyncRoot != null) { Monitor.Enter(SyncRoot); } }
/// <summary> /// 创建 MySqlExecuteContext 对象 /// </summary> /// <param name="transaction">MySql 数据库事务上下文</param> /// <param name="dataReader">MySql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public MySqlExecuteContext(MySqlDbTransaction transaction, MySqlDataReader dataReader, IDbTracing tracing) : base(dataReader, tracing) { TransactionContext = transaction; MySqlDataReader = dataReader; }
/// <summary> /// 创建 MySqlExecuteContext 对象 /// </summary> /// <param name="connection">MySql 数据库连接</param> /// <param name="dataReader">MySql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public MySqlExecuteContext( MySqlConnection connection, MySqlDataReader dataReader, IDbTracing tracing ) : base( dataReader, tracing, connection ) { MySqlDataReader = dataReader; }
/// <summary> /// 创建 MySqlExecuteContext 对象 /// </summary> /// <param name="connection">MySql 数据库连接</param> /// <param name="dataReader">MySql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public MySqlExecuteContext(MySqlConnection connection, MySqlDataReader dataReader, IDbTracing tracing) : base(dataReader, tracing) { MySqlDataReader = dataReader; RegisterDispose(connection); }
/// <summary> /// 异步执行查询命令并返回执行上下文 /// </summary> /// <param name="command">查询命令</param> /// <param name="token">取消指示</param> /// <param name="tracing">用于追踪查询过程的追踪器</param> /// <returns>查询执行上下文</returns> protected virtual async Task <IAsyncDbExecuteContext> ExecuteAsync(SqlCommand command, CancellationToken token, IDbTracing tracing = null) { try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); var connection = new SqlConnection(ConnectionString); await connection.OpenAsync(token); command.Connection = connection; if (Configuration.QueryExecutingTimeout.HasValue) { command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds; } var reader = await command.ExecuteReaderAsync(token); var context = new SqlDbExecuteContext(connection, reader, tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
/// <summary> /// 创建数据库异步查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="disposeMethod">当上下文销毁时要执行的方法</param> /// <param name="sync">用于同步的对象</param> protected AsyncDbExecuteContextBase(DbDataReader dataReader, IDbTracing tracing = null, Action disposeMethod = null, object sync = null) : base(dataReader, tracing, disposeMethod, sync) { DataReader = dataReader; }
/// <summary> /// 创建 SqlExecuteContext 对象 /// </summary> /// <param name="reader">数据读取器</param> /// <param name="tracing">用于记录此次查询过程的的查询追踪器</param> /// <param name="disposeMethod">当上下文销毁时要执行的方法</param> internal SqlDbExecuteContext(SqlDataReader reader, IDbTracing tracing, Action disposeMethod) : base(reader, tracing, disposeMethod) { SqlDataReader = reader; }
/// <summary> /// 创建 NpgsqlExecuteContext 对象 /// </summary> /// <param name="connection">PostgreSql 数据库连接</param> /// <param name="dataReader">PostgreSql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public NpgsqlDbExecuteContext( NpgsqlConnection connection, DbDataReader dataReader, IDbTracing tracing ) : base( dataReader, tracing, connection ) { this.NpgsqlDataReader = dataReader; }
/// <summary> /// 重写 ExecuteAsync 方法,在事务中异步执行查询 /// </summary> /// <param name="command">要执行的查询命令</param> /// <param name="token">取消指示</param> /// <param name="tracing">用于追踪的追踪器</param> /// <returns>查询执行上下文</returns> protected sealed override async Task <IAsyncDbExecuteContext> ExecuteAsync(NpgsqlCommand command, CancellationToken token, IDbTracing tracing = null) { try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); command.Connection = TransactionContext.Connection; command.Transaction = TransactionContext.Transaction; if (Configuration.QueryExecutingTimeout.HasValue) { command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds; } var reader = await command.ExecuteReaderAsync(token); var context = new NpgsqlDbExecuteContext(TransactionContext, reader, tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
/// <summary> /// 创建 SqlExecuteContext 对象 /// </summary> /// <param name="connection">数据库连接</param> /// <param name="reader">数据读取器</param> /// <param name="tracing">用于记录此次查询过程的的查询追踪器</param> internal SqlDbExecuteContext( SqlConnection connection, SqlDataReader reader, IDbTracing tracing ) : base( reader, tracing, connection ) { SqlDataReader = reader; }
/// <summary> /// 创建 NpgsqlExecuteContext 对象 /// </summary> /// <param name="transaction">PostgreSql 数据库事务上下文</param> /// <param name="dataReader">PostgreSql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public NpgsqlDbExecuteContext(NpgsqlDbTransactionContext transaction, DbDataReader dataReader, IDbTracing tracing) : base(dataReader, tracing, null) { this.TransactionContext = transaction; this.NpgsqlDataReader = dataReader; }
/// <summary> /// 创建数据库异步查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="sync">用于同步的对象</param> protected AsyncDbExecuteContextBase(DbDataReader dataReader, IDbTracing tracing = null, object sync = null) : base(dataReader, tracing, sync) { DataReader = dataReader; }
/// <summary> /// 创建 NpgsqlExecuteContext 对象 /// </summary> /// <param name="connection">PostgreSql 数据库连接</param> /// <param name="dataReader">PostgreSql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public NpgsqlDbExecuteContext(NpgsqlConnection connection, DbDataReader dataReader, IDbTracing tracing) : base(dataReader, tracing, connection) { this.NpgsqlDataReader = dataReader; }
/// <summary> /// 创建 SqlExecuteContext 对象 /// </summary> /// <param name="transaction">数据库事务</param> /// <param name="reader">数据读取器</param> /// <param name="tracing">用于记录此次查询过程的的查询追踪器</param> internal SqlDbExecuteContext( SqlDbTransactionContext transaction, SqlDataReader reader, IDbTracing tracing ) : base( reader, tracing, null ) { SqlDataReader = reader; }
/// <summary> /// 创建 MySqlExecuteContext 对象 /// </summary> /// <param name="transaction">MySql 数据库事务上下文</param> /// <param name="dataReader">MySql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public MySqlExecuteContext( MySqlDbTransactionContext transaction, MySqlDataReader dataReader, IDbTracing tracing ) : base( dataReader, tracing, null ) { TransactionContext = transaction; MySqlDataReader = dataReader; }
/// <summary> /// 创建数据库异步查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="connectionResource">销毁该上下文时,需要同时销毁的连接资源</param> protected AsyncDbExecuteContextBase( DbDataReader dataReader, IDbTracing tracing = null, IDisposable connectionResource = null ) : base( dataReader, tracing, connectionResource ) { DataReader = dataReader; }
protected abstract MySqlExecuteContext CreateExecuteContext(MySqlConnection connection, MySqlDataReader reader, IDbTracing tracing);
/// <summary> /// 执行查询命令并返回执行上下文 /// </summary> /// <param name="command">查询命令</param> /// <param name="tracing">用于追踪查询过程的追踪器</param> /// <returns>查询执行上下文</returns> protected sealed override IDbExecuteContext Execute(MySqlCommand command, IDbTracing tracing = null) { try { TryExecuteTracing(tracing, t => t.OnExecuting(command)); command.Connection = TransactionContext.Connection; command.Transaction = TransactionContext.Transaction; if (Configuration.QueryExecutingTimeout.HasValue) { command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds; } var reader = command.ExecuteReader(); var context = new SqlDbExecuteContext(TransactionContext, reader, tracing); TryExecuteTracing(tracing, t => t.OnLoadingData(context)); return(context); } catch (DbException exception) { TryExecuteTracing(tracing, t => t.OnException(exception)); throw; } }
protected override MySqlExecuteContext CreateExecuteContext(MySqlConnection connection, MySqlDataReader reader, IDbTracing tracing) { return(new MySqlExecuteContext(Transaction, reader, tracing)); }
public SQLiteExecuteContext( SQLiteDataReader dataReader, IDbTracing tracing, object sync ) : base( dataReader, tracing, sync: sync ) { DataReader = dataReader; }
/// <summary> /// 创建 SqlExecuteContext 对象 /// </summary> /// <param name="reader">数据读取器</param> /// <param name="tracing">用于记录此次查询过程的的查询追踪器</param> /// <param name="disposeMethod">当上下文销毁时要执行的方法</param> internal SqlDbExecuteContext(SqlDataReader reader, IDbTracing tracing) : base(reader, tracing) { SqlDataReader = reader; }
/// <summary> /// 创建 NpgsqlExecuteContext 对象 /// </summary> /// <param name="transaction">PostgreSql 数据库事务上下文</param> /// <param name="dataReader">PostgreSql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public NpgsqlDbExecuteContext( NpgsqlDbTransactionContext transaction, DbDataReader dataReader, IDbTracing tracing ) : base( dataReader, tracing, null ) { this.TransactionContext = transaction; this.NpgsqlDataReader = dataReader; }
/// <summary> /// 创建 MySqlExecuteContext 对象 /// </summary> /// <param name="connection">MySql 数据库连接</param> /// <param name="dataReader">MySql 数据读取器</param> /// <param name="tracing">用于当前查询的追踪器</param> public MySqlExecuteContext(MySqlConnection connection, MySqlDataReader dataReader, IDbTracing tracing) : base(dataReader, tracing, () => connection.Dispose()) { MySqlDataReader = dataReader; }
public SQLiteExecuteContext(SQLiteDataReader dataReader, IDbTracing tracing, object sync) : base(dataReader, tracing, sync: sync) { DataReader = dataReader; }
/// <summary> /// 创建 SqlExecuteContext 对象 /// </summary> /// <param name="transaction">数据库事务</param> /// <param name="reader">数据读取器</param> /// <param name="tracing">用于记录此次查询过程的的查询追踪器</param> internal SqlDbExecuteContext(SqlDbTransactionContext transaction, SqlDataReader reader, IDbTracing tracing) : base(reader, tracing, null) { SqlDataReader = reader; }
/// <summary> /// 创建 SqlExecuteContext 对象 /// </summary> /// <param name="connection">数据库连接</param> /// <param name="reader">数据读取器</param> /// <param name="tracing">用于记录此次查询过程的的查询追踪器</param> internal SqlDbExecuteContext(SqlConnection connection, SqlDataReader reader, IDbTracing tracing) : base(reader, tracing, connection) { SqlDataReader = reader; }
/// <summary> /// 创建数据库异步查询执行上下文 /// </summary> /// <param name="dataReader">用于读取数据的 IDataReader 对象</param> /// <param name="tracing">用于追踪此次查询过程的追踪器</param> /// <param name="connectionResource">销毁该上下文时,需要同时销毁的连接资源</param> protected AsyncDbExecuteContextBase(DbDataReader dataReader, IDbTracing tracing = null, IDisposable connectionResource = null) : base(dataReader, tracing, connectionResource) { DataReader = dataReader; }