use of com.alibaba.cobar.parser.recognizer.mysql.MySQLFunctionManager in project cobar by alibaba.
the class RouteRuleInitializer method initRouteRule.
public static void initRouteRule(SchemaLoader loader) throws SQLSyntaxErrorException {
Map<String, RuleAlgorithm> functions = loader.getFunctions();
MySQLFunctionManager functionManager = new MySQLFunctionManager(true);
buildFuncManager(functionManager, functions);
for (RuleConfig conf : loader.listRuleConfig()) {
String algorithmString = conf.getAlgorithm();
MySQLLexer lexer = new MySQLLexer(algorithmString);
MySQLExprParser parser = new MySQLExprParser(lexer, functionManager, false, MySQLParser.DEFAULT_CHARSET);
Expression expression = parser.expression();
if (lexer.token() != MySQLToken.EOF) {
throw new ConfigException("route algorithm not end with EOF: " + algorithmString);
}
RuleAlgorithm algorithm;
if (expression instanceof RuleAlgorithm) {
algorithm = (RuleAlgorithm) expression;
} else {
algorithm = new ExpressionAdapter(expression);
}
conf.setRuleAlgorithm(algorithm);
}
}
Aggregations