Search in sources :

Example 1 with SQLBuilder

use of com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder in project sharding-jdbc by dangdangdotcom.

the class SQLRouteEngine method amendSQLAccordingToRouteResult.

private void amendSQLAccordingToRouteResult(final SQLParsedResult parsedResult, final List<Object> parameters, final SQLRouteResult result) {
    boolean isVarious = result.getExecutionUnits().size() > 1;
    Limit limit = result.getMergeContext().getLimit();
    SQLBuilder sqlBuilder = parsedResult.getRouteContext().getSqlBuilder();
    if (null != limit) {
        limit.replaceSQL(sqlBuilder, isVarious);
        limit.replaceParameters(parameters, isVarious);
    }
    if (!isVarious) {
        sqlBuilder.removeDerivedSQL();
    }
}
Also used : SQLBuilder(com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder) Limit(com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit)

Example 2 with SQLBuilder

use of com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder 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 SQLBuilder

use of com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder in project sharding-jdbc by dangdangdotcom.

the class SQLParsedResultTest method generateSqlBuilder.

private SQLBuilder generateSqlBuilder() throws IOException {
    SQLBuilder result = new SQLBuilder();
    result.append("SELECT * FROM ");
    result.appendToken("order");
    return result;
}
Also used : SQLBuilder(com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder)

Aggregations

SQLBuilder (com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder)3 SQLParsedResult (com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult)1 Limit (com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit)1 ConditionContext (com.dangdang.ddframe.rdb.sharding.parser.result.router.ConditionContext)1 RouteContext (com.dangdang.ddframe.rdb.sharding.parser.result.router.RouteContext)1 IOException (java.io.IOException)1