Search in sources :

Example 1 with SQLParsedResult

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;
}
Also used : Context(com.codahale.metrics.Timer.Context) ConditionContext(com.dangdang.ddframe.rdb.sharding.parser.result.router.ConditionContext) RouteContext(com.dangdang.ddframe.rdb.sharding.parser.result.router.RouteContext) MetricsContext(com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext) SQLParsedResult(com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult)

Example 2 with SQLParsedResult

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;
}
Also used : SQLParsedResult(com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult) SQLBuilder(com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder) ConditionContext(com.dangdang.ddframe.rdb.sharding.parser.result.router.ConditionContext) IOException(java.io.IOException) RouteContext(com.dangdang.ddframe.rdb.sharding.parser.result.router.RouteContext)

Example 3 with SQLParsedResult

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;
}
Also used : SQLParsedResult(com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult) OrParser(com.dangdang.ddframe.rdb.sharding.parser.visitor.or.OrParser) SQLVisitor(com.dangdang.ddframe.rdb.sharding.parser.visitor.SQLVisitor)

Aggregations

SQLParsedResult (com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult)3 ConditionContext (com.dangdang.ddframe.rdb.sharding.parser.result.router.ConditionContext)2 RouteContext (com.dangdang.ddframe.rdb.sharding.parser.result.router.RouteContext)2 Context (com.codahale.metrics.Timer.Context)1 MetricsContext (com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext)1 SQLBuilder (com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder)1 SQLVisitor (com.dangdang.ddframe.rdb.sharding.parser.visitor.SQLVisitor)1 OrParser (com.dangdang.ddframe.rdb.sharding.parser.visitor.or.OrParser)1 IOException (java.io.IOException)1