public int Update(string statementName, object parameterObject)
        {
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;
            int            num          = 0;

            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                num = this.GetMappedStatement(statementName).ExecuteUpdate(localSession, parameterObject);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
            return(num);
        }
        public T QueryForObject <T>(string statementName, object parameterObject, T instanceObject)
        {
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;
            T local = default(T);

            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                local = this.GetMappedStatement(statementName).ExecuteQueryForObject <T>(localSession, parameterObject, instanceObject);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
            return(local);
        }
        public IList <T> QueryWithRowDelegate <T>(string statementName, object parameterObject, RowDelegate <T> rowDelegate)
        {
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;
            IList <T>      list         = null;

            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                list = this.GetMappedStatement(statementName).ExecuteQueryForRowDelegate <T>(localSession, parameterObject, rowDelegate);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
            return(list);
        }
        public object QueryForObject(string statementName, object parameterObject, object resultObject)
        {
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;
            object         obj2         = null;

            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                obj2 = this.GetMappedStatement(statementName).ExecuteQueryForObject(localSession, parameterObject, resultObject);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
            return(obj2);
        }
        public IDictionary QueryForMapWithRowDelegate(string statementName, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
        {
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;
            IDictionary    dictionary   = null;

            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                dictionary = this.GetMappedStatement(statementName).ExecuteQueryForMapWithRowDelegate(localSession, parameterObject, keyProperty, valueProperty, rowDelegate);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
            return(dictionary);
        }
        public IList QueryForList(string statementName, object parameterObject, int skipResults, int maxResults)
        {
            IList          list;
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;

            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                list = this.GetMappedStatement(statementName).ExecuteQueryForList(localSession, parameterObject, skipResults, maxResults);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
            return(list);
        }
        public void QueryForList(string statementName, object parameterObject, IList resultObject)
        {
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;

            if (resultObject == null)
            {
                throw new DataMapperException("resultObject parameter must be instantiated before being passed to SqlMapper.QueryForList");
            }
            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                this.GetMappedStatement(statementName).ExecuteQueryForList(localSession, parameterObject, resultObject);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
        }
Пример #8
0
        public string GetRunString <T>(string methodName, object parameters)
        {
            Type           type           = typeof(T);
            var            statementName  = type.FullName + "." + methodName;
            string         commandText    = string.Empty;
            var            isSessionLocal = false;
            ISqlMapSession session        = this._context.Writer.LocalSession;

            if (session == null)
            {
                session        = this._context.Writer.CreateSqlMapSession();
                isSessionLocal = true;
            }
            try
            {
                var statement = this._context.Writer.GetMappedStatement(statementName);
                var scope     = statement.Statement.Sql.GetRequestScope(statement, parameters, session);
                statement.PreparedCommand.Create(scope, session, statement.Statement, parameters);
                commandText = scope.IDbCommand.CommandText;
                foreach (DbParameter pt in scope.IDbCommand.Parameters)
                {
                    Regex regex = new Regex(pt.ParameterName + @"\D");
                    commandText = regex.Replace(commandText, GetDbParameterValue(pt));
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (isSessionLocal)
                {
                    session.CloseConnection();
                }
            }
            return(commandText);
        }
Пример #9
0
        public object Execute(object[] Arguments)
        {
            object value     = null;
            var    parameter = WarpParameter(Arguments);

            switch (this._dataAccessType)
            {
            case DataAccessType.Insert:
                if (this._intercept != null)
                {
                    this._intercept.BeforeExecute(this._method.Name, parameter);
                }
                value = this._context.Writer.Insert(this._statementName, parameter);
                if (this._intercept != null)
                {
                    this._intercept.EndExecute(this._method.Name, parameter, value);
                }
                break;

            case DataAccessType.Delete:
                if (this._intercept != null)
                {
                    this._intercept.BeforeExecute(this._method.Name, parameter);
                }
                value = this._context.Writer.Delete(this._statementName, parameter);
                if (this._intercept != null)
                {
                    this._intercept.EndExecute(this._method.Name, parameter, value);
                }
                break;

            case DataAccessType.Update:
                if (this._intercept != null)
                {
                    this._intercept.BeforeExecute(this._method.Name, parameter);
                }
                value = this._context.Writer.Update(this._statementName, parameter);
                if (this._intercept != null)
                {
                    this._intercept.EndExecute(this._method.Name, parameter, value);
                }
                break;

            case DataAccessType.SelectReadOnly:
            case DataAccessType.SelectReadWrite:
                if (this._intercept != null)
                {
                    this._intercept.BeforeExecute(this._method.Name, parameter);
                }
                if (this._isIPagedList)
                {
                    if (this._context.HasDataAccessTypeContext)
                    {
                        value = QueryPageList(this._context.ContextMapper, parameter);
                    }
                    else if (this._dataAccessType == DataAccessType.SelectReadOnly)
                    {
                        value = QueryPageList(this._context.Reader, parameter);
                    }
                    else
                    {
                        value = QueryPageList(this._context.Writer, parameter);
                    }
                }
                else if (this._isSelectList)
                {
                    if (this._context.HasDataAccessTypeContext)
                    {
                        value = this._context.ContextMapper.QueryForList(this._statementName, parameter);
                    }
                    else if (this._dataAccessType == DataAccessType.SelectReadOnly)
                    {
                        value = this._context.Reader.QueryForList(this._statementName, parameter);
                    }
                    else
                    {
                        value = this._context.Writer.QueryForList(this._statementName, parameter);
                    }
                }
                else
                {
                    if (this._context.HasDataAccessTypeContext)
                    {
                        value = this._context.ContextMapper.QueryForObject(this._statementName, parameter);
                    }
                    else if (this._dataAccessType == DataAccessType.SelectReadOnly)
                    {
                        value = this._context.Reader.QueryForObject(this._statementName, parameter);
                    }
                    else
                    {
                        value = this._context.Writer.QueryForObject(this._statementName, parameter);
                    }
                    if (value == null && this._isNotCanNullReturnValue)
                    {
                        throw new DataAccessException("返回值是一个不可空的对象,但是返回值为空,请使用可空对象定义返回值");
                    }
                }
                if (this._intercept != null)
                {
                    this._intercept.EndExecute(this._method.Name, parameter, value);
                }
                break;
            }
            if (this._outTypeConfig != null)
            {
                bool isOut = false;
                if (this._outTypeConfig.IgnoreEnvironment)
                {
                    isOut = true;
                }
                else if (!AppInfo.DeployEnvInfo.IsFormal)
                {
                    isOut = true;
                }
                if (isOut)
                {
                    string         commandText    = string.Empty;
                    var            isSessionLocal = false;
                    ISqlMapSession session        = this._context.Writer.LocalSession;
                    if (session == null)
                    {
                        session        = this._context.Writer.CreateSqlMapSession();
                        isSessionLocal = true;
                    }

                    try
                    {
                        var statement = this._context.Writer.GetMappedStatement(this._statementName);
                        var scope     = statement.Statement.Sql.GetRequestScope(statement, parameter, session);
                        statement.PreparedCommand.Create(scope, session, statement.Statement, parameter);
                        commandText = scope.IDbCommand.CommandText;
                        foreach (DbParameter pt in scope.IDbCommand.Parameters)
                        {
                            Regex regex = new Regex(pt.ParameterName + @"\D");
                            commandText = regex.Replace(commandText, GetDbParameterValue(pt));
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (isSessionLocal)
                        {
                            session.CloseConnection();
                        }
                    }
                    if (!string.IsNullOrEmpty(commandText))
                    {
                        if (this._outTypeConfig.OutType == OutSqlTextType.AutoLog)
                        {
                            _logger.Info(commandText);
                        }
                        else
                        {
                            Debug.WriteLine(commandText);
                            Console.WriteLine(commandText);
                        }
                    }
                }
            }
            return(value);
        }