示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
        }