private void InitRequest(AbstractRequestContext requestContext) { if (!String.IsNullOrEmpty(requestContext.RealSql)) { requestContext.IsStatementSql = false; } SqlMap sqlMap = null; if (!String.IsNullOrEmpty(requestContext.Scope)) { sqlMap = _smartSqlConfig.GetSqlMap(requestContext.Scope); } if (requestContext.IsStatementSql) { InitByStatement(requestContext, sqlMap); } else { InitByMap(requestContext, sqlMap); } if (requestContext.AutoConverter == null) { requestContext.AutoConverter = NoneAutoConverter.INSTANCE; } }
private void InitRequest(AbstractRequestContext requestContext) { if (!String.IsNullOrEmpty(requestContext.RealSql)) { requestContext.IsStatementSql = false; } if (!String.IsNullOrEmpty(requestContext.Scope)) { var sqlMap = _smartSqlConfig.GetSqlMap(requestContext.Scope); if (requestContext.IsStatementSql) { InitByStatement(requestContext, sqlMap); } else { InitByMap(requestContext, sqlMap); } } }
private StatementAttribute PreStatement(Type interfaceType, string scope, MethodInfo methodInfo, Type returnType, bool isTaskReturnType, SmartSqlConfig smartSqlConfig) { returnType = isTaskReturnType ? returnType.GetGenericArguments().FirstOrDefault() : returnType; var statementAttr = methodInfo.GetCustomAttribute <StatementAttribute>(); var methodName = _sqlIdNamingConvert == null ? methodInfo.Name : _sqlIdNamingConvert.Invoke(interfaceType, methodInfo); if (isTaskReturnType && methodInfo.Name.EndsWith("Async") && _sqlIdNamingConvert == null) { methodName = methodName.Substring(0, methodName.Length - 5); } if (statementAttr != null) { statementAttr.Id = !String.IsNullOrEmpty(statementAttr.Id) ? statementAttr.Id : methodName; statementAttr.Scope = !String.IsNullOrEmpty(statementAttr.Scope) ? statementAttr.Scope : scope; } else { statementAttr = new StatementAttribute { Scope = scope, Id = methodName }; } if (returnType == typeof(DataTable)) { statementAttr.Execute = ExecuteBehavior.GetDataTable; return(statementAttr); } if (returnType == typeof(DataSet)) { statementAttr.Execute = ExecuteBehavior.GetDataSet; return(statementAttr); } if (statementAttr.Execute == ExecuteBehavior.Auto) { Configuration.StatementType statementType = Configuration.StatementType.Unknown; if (String.IsNullOrEmpty(statementAttr.Sql)) { var sqlStatement = smartSqlConfig.GetSqlMap(statementAttr.Scope).GetStatement($"{statementAttr.Scope}.{statementAttr.Id}"); statementType = sqlStatement.StatementType; } else { statementType = _statementAnalyzer.Analyse(statementAttr.Sql); } if (CommonType.IsValueTuple(returnType)) { statementAttr.Execute = ExecuteBehavior.QuerySingle; } else if (returnType == CommonType.Int32 || returnType == CommonType.Void || returnType == null) { statementAttr.Execute = ExecuteBehavior.Execute; if (returnType == CommonType.Int32) { if (statementType.HasFlag(Configuration.StatementType.Select)) { statementAttr.Execute = ExecuteBehavior.ExecuteScalar; } } } else if (returnType.IsValueType || returnType == CommonType.String) { statementAttr.Execute = ExecuteBehavior.ExecuteScalar; if (!statementType.HasFlag(Configuration.StatementType.Select)) { statementAttr.Execute = ExecuteBehavior.Execute; } } else { var isQueryEnumerable = typeof(IEnumerable).IsAssignableFrom(returnType); statementAttr.Execute = isQueryEnumerable ? ExecuteBehavior.Query : ExecuteBehavior.QuerySingle; } } return(statementAttr); }