/// <exception cref="System.SqlSyntaxErrorException" /> public static void InitRouteRule(ISchemaLoader loader) { var functions = loader.Functions; var functionManager = new MySqlFunctionManager(true); BuildFuncManager(functionManager, functions); foreach (var conf in loader.RuleConfigList) { var algorithmString = conf.Algorithm; var lexer = new MySqlLexer(algorithmString); var parser = new MySqlExprParser(lexer, functionManager, false, MySqlParser.DefaultCharset); var expression = parser.Expression(); if (lexer.Token() != MySqlToken.Eof) { throw new ConfigException("route algorithm not end with EOF: " + algorithmString); } IRuleAlgorithm algorithm; if (expression is IRuleAlgorithm) { algorithm = (IRuleAlgorithm)expression; } else { algorithm = new ExpressionAdapter(expression); } conf.RuleAlgorithm = algorithm; } }
private static void BuildFuncManager(MySqlFunctionManager functionManager, IDictionary <string, IRuleAlgorithm> functions) { var extFuncPrototypeMap = new Dictionary <string, FunctionExpression>(functions.Count); foreach (var en in functions) { extFuncPrototypeMap[en.Key] = (FunctionExpression)en.Value; } functionManager.AddExtendFunction(extFuncPrototypeMap); }
public MySqlExprParser(MySqlLexer lexer, MySqlFunctionManager functionManager, bool cacheEvalRst, string charset) : base(lexer, cacheEvalRst) { this.functionManager = functionManager; this.charset = charset ?? DefaultCharset; }