コード例 #1
0
        /// <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;
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public MySqlExprParser(MySqlLexer lexer, MySqlFunctionManager functionManager, bool cacheEvalRst, string charset)
     : base(lexer, cacheEvalRst)
 {
     this.functionManager = functionManager;
     this.charset = charset ?? DefaultCharset;
 }