/// <summary> /// Builds a new <see cref="RequestScope"/> and the <see cref="IDbCommand"/> text to execute. /// </summary> /// <param name="mappedStatement">The <see cref="IMappedStatement"/>.</param> /// <param name="parameterObject">The parameter object (used by DynamicSql/SimpleDynamicSql). /// Use to complete the sql statement.</param> /// <param name="session">The current session</param> /// <returns>A new <see cref="RequestScope"/>.</returns> public RequestScope GetRequestScope(IMappedStatement mappedStatement, object parameterObject, ISession session) { RequestScope request = new RequestScope(dataExchangeFactory, session, statement); string sqlCommandText = statement.SqlSource.GetSql(mappedStatement, parameterObject); string newSqlCommandText = string.Empty; if (request.ParameterMap==null) { request.ParameterMap = inlineParemeterMapBuilder.BuildInlineParemeterMap(statement, sqlCommandText, out newSqlCommandText); } // Processes $substitutions$ after DynamicSql if (SimpleDynamicSql.IsSimpleDynamicSql(newSqlCommandText)) { newSqlCommandText = new SimpleDynamicSql( dataExchangeFactory, dbHelperParameterCache, newSqlCommandText, statement).GetSql(parameterObject); } request.PreparedStatement = BuildPreparedStatement(session, request, newSqlCommandText); return request; }
/// <summary> /// 完成动态SQL语句中子语句的拼接 和 参数信息的取出 /// </summary> /// <param name="request"></param> /// <param name="parameterObject"></param> /// <returns></returns> private string Process(RequestScope request, object parameterObject) { SqlTagContext ctx = new SqlTagContext(); IList<ISqlChild> localChildren = children; ProcessBodyChildren(request, ctx, parameterObject, localChildren); #region 所有参数对应的属性类的集合信息放入到ParameterMap中 // Builds a 'dynamic' ParameterMap ParameterMap parameterMap = new ParameterMap( statement.Id + "-InlineParameterMap", statement.ParameterClass.FullName, string.Empty, statement.ParameterClass, dataExchangeFactory.GetDataExchangeForClass(null), usePositionalParameters); // Adds 'dynamic' ParameterProperty IList parameters = ctx.GetParameterMappings(); int count = parameters.Count; for (int i = 0; i < count; i++) { parameterMap.AddParameterProperty((ParameterProperty)parameters[i]); } request.ParameterMap = parameterMap; #endregion #region 完整的SQL语句 string dynSql = ctx.BodyText; if (statement is Procedure) { dynSql = dynSql.Replace(MARK_TOKEN, string.Empty).Replace(COMMA_TOKEN, string.Empty).Trim(); } // Processes $substitutions$ after DynamicSql if (SimpleDynamicSql.IsSimpleDynamicSql(dynSql)) { dynSql = new SimpleDynamicSql( dataExchangeFactory, dbHelperParameterCache, dynSql, statement).GetSql(parameterObject); } #endregion return dynSql; }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <param name="parameterObject"></param> /// <returns></returns> private string Process(RequestScope request, object parameterObject) { SqlTagContext ctx = new SqlTagContext(); IList<ISqlChild> localChildren = children; ProcessBodyChildren(request, ctx, parameterObject, localChildren); // Builds a 'dynamic' ParameterMap ParameterMap parameterMap = new ParameterMap( statement.Id + "-InlineParameterMap", statement.ParameterClass.FullName, string.Empty, statement.ParameterClass, dataExchangeFactory.GetDataExchangeForClass(null), usePositionalParameters); // Adds 'dynamic' ParameterProperty var parameters = ctx.GetParameterMappings(); parameterMap.AddParameterProperties(parameters); request.ParameterMap = parameterMap; string dynSql = ctx.BodyText; if (statement is Procedure) { dynSql = dynSql.Replace(MARK_TOKEN, string.Empty).Replace(COMMA_TOKEN, string.Empty).Trim(); } // Processes $substitutions$ after DynamicSql if (SimpleDynamicSql.IsSimpleDynamicSql(dynSql)) { dynSql = new SimpleDynamicSql( dataExchangeFactory, dbHelperParameterCache, dynSql, statement).GetSql(parameterObject); } return dynSql; }