public virtual IDataReader ExecuteStoredProcedureWithResultSet(bool skipLog, string readerParamName) { DateTime startTime = DateTime.Now; IDbTransaction trans = DriverCommand.Transaction; IDbConnection conn = DriverCommand.Connection; IDataReader reader = null; try { var platformDatabaseServices = ExecutionService.DatabaseServices as IPlatformDatabaseServices; if (platformDatabaseServices == null) { throw new InvalidOperationException("ExecuteStoredProcedureWithResultSet is only available for platform database providers"); } TransformParametersSyntax(); Func <IDataReader> executeStoredProcedureWithResultSet = () => { return(platformDatabaseServices.ExecutionService.ExecuteStoredProcedureWithResultSet(DriverCommand, readerParamName)); }; reader = new DataReader(ExecutionService, this, DatabaseBehaviours.ExecuteWithoutRequestTimeout(executeStoredProcedureWithResultSet)); } catch (DbException e) { HandleDatabaseException(e, reader, conn, trans); throw; } if (!skipLog) { LogSlowQuery(startTime, null, false); } return(reader); }
public virtual IDataReader ExecuteReader(string description, bool isApplication, bool applyTransformationsToParameters, bool skipLog) { DateTime startTime = DateTime.Now; IDbTransaction trans = DriverCommand.Transaction; IDbConnection conn = DriverCommand.Connection; IDataReader reader = null; try { if (applyTransformationsToParameters) { TransformParametersSyntax(); } Func <IDataReader> executeReader = () => { return(ExecutionService.ExecuteReader(DriverCommand)); }; reader = new DataReader(ExecutionService, this, DatabaseBehaviours.ExecuteWithoutRequestTimeout(executeReader)); } catch (DbException e) { HandleDatabaseException(e, reader, conn, trans); throw; } if (!skipLog) { LogSlowQuery(startTime, description, isApplication); } return(reader); }
public int ExecuteNonQuery(string description, bool isApplication, bool skipLog, bool applyTransformationsToParameters) { DateTime startTime = DateTime.Now; IDbTransaction trans = DriverCommand.Transaction; IDbConnection conn = DriverCommand.Connection; int result; try { if (applyTransformationsToParameters) { TransformParametersSyntax(); } Func <int> executeNonQuery = () => { return(ExecutionService.ExecuteNonQuery(DriverCommand)); }; result = DatabaseBehaviours.ExecuteWithoutRequestTimeout(executeNonQuery); IEnumerable parameters = DriverCommand.Parameters; foreach (IDbDataParameter parameter in parameters) { if (IsOutputParameter(parameter.Direction)) { parameter.Value = ExecutionService.TransformDatabaseToRuntimeValue(parameter.Value); } } } catch (DbException e) { HandleDatabaseException(e, null, conn, trans); throw; } if (!skipLog) { LogSlowQuery(startTime, description, isApplication); } return(result); }
public override IDataReader ExecuteReader(string description, bool isApplication, bool transformParameters, bool skipLog) { DateTime startTime = DateTime.Now; IDbTransaction trans = DriverCommand.Transaction; IDbConnection conn = DriverCommand.Connection; IDataReader reader = null; try { if (transformParameters) { TransformParametersSyntax(); } Func <IDataReader> executeReader = () => { return(ExecutionService.ExecuteReader(DriverCommand)); }; reader = new DataReader(ExecutionService, this, DatabaseBehaviours.ExecuteWithoutRequestTimeout(executeReader)); // The transaction manager will release the data reader automatically in the future. Manager.AssociateReader(DriverCommand.Transaction, reader); } catch (DbException e) { HandleDatabaseException(e, reader, conn, trans); throw; } if (!skipLog) { LogSlowQuery(startTime, description, isApplication); } return(reader); }
public void LogSlowQuery(DateTime startTime, string description, bool isApplication) { if (DatabaseBehaviours.SkipSlowQueries) { return; } double duration = DateTime.Now.Subtract(startTime).TotalMilliseconds; if (duration > DatabaseBehaviours.SlowQueryThreshold) { if (description == null) { description = GetCallerName(); } if (!isApplication) { description = "OS: " + description; } description += " took " + Convert.ToInt32(duration) + " ms"; DatabaseBehaviours.LogSlowQuery(startTime, description, isApplication); } }
public object ExecuteScalar(string description, bool isApplication, bool skipLog, bool applyTransformationsToParameters) { DateTime startTime = DateTime.Now; IDbTransaction trans = DriverCommand.Transaction; IDbConnection conn = DriverCommand.Connection; object result; try { if (applyTransformationsToParameters) { TransformParametersSyntax(); } Func <object> transformDatabaseToRuntimeValue = () => { return(ExecutionService.TransformDatabaseToRuntimeValue(ExecutionService.ExecuteScalar(DriverCommand))); }; result = DatabaseBehaviours.ExecuteWithoutRequestTimeout(transformDatabaseToRuntimeValue); } catch (DbException e) { HandleDatabaseException(e, null, conn, trans); throw; } if (!skipLog) { LogSlowQuery(startTime, description, isApplication); } return(result); }