use of com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult in project sharding-jdbc by dangdangdotcom.
the class SQLRouteEngine method parseSQL.
SQLParsedResult parseSQL(final String logicSql, final List<Object> parameters) {
if (HintManagerHolder.isDatabaseShardingOnly()) {
return buildHintParsedResult(logicSql);
}
Context context = MetricsContext.start("Parse SQL");
SQLParsedResult result = SQLParserFactory.create(databaseType, logicSql, parameters, shardingRule).parse();
MetricsContext.stop(context);
return result;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult in project sharding-jdbc by dangdangdotcom.
the class SQLRouteEngine method buildHintParsedResult.
private SQLParsedResult buildHintParsedResult(final String logicSql) {
SQLParsedResult result = new SQLParsedResult();
RouteContext routeContext = result.getRouteContext();
routeContext.setSqlStatementType(SQLUtil.getTypeByStart(logicSql));
log.trace("Get {} SQL Statement", routeContext.getSqlStatementType());
SQLBuilder sqlBuilder = new SQLBuilder();
try {
sqlBuilder.append(logicSql);
} catch (final IOException ignored) {
}
routeContext.setSqlBuilder(sqlBuilder);
result.getConditionContexts().add(new ConditionContext());
return result;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult in project sharding-jdbc by dangdangdotcom.
the class SQLParseEngine method parse.
/**
* 解析SQL.
*
* @return SQL解析结果
*/
public SQLParsedResult parse() {
Preconditions.checkArgument(visitor instanceof SQLVisitor);
SQLVisitor sqlVisitor = (SQLVisitor) visitor;
visitor.setParameters(parameters);
sqlVisitor.getParseContext().setShardingRule(shardingRule);
sqlStatement.accept(visitor);
SQLParsedResult result = sqlVisitor.getParseContext().getParsedResult();
if (sqlVisitor.getParseContext().isHasOrCondition()) {
new OrParser(sqlStatement, visitor).fillConditionContext(result);
}
sqlVisitor.getParseContext().mergeCurrentConditionContext();
log.debug("Parsed SQL result: {}", result);
log.debug("Parsed SQL: {}", sqlVisitor.getSQLBuilder());
result.getRouteContext().setSqlBuilder(sqlVisitor.getSQLBuilder());
result.getRouteContext().setSqlStatementType(getType());
return result;
}
Aggregations