Search in sources :

Example 1 with DialectModel

use of com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel in project solon by noear.

the class PaginationInnerInterceptor method beforeQuery.

@Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
    IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
    if (null == page) {
        return;
    }
    // 处理 orderBy 拼接
    boolean addOrdered = false;
    String buildSql = boundSql.getSql();
    List<OrderItem> orders = page.orders();
    if (CollectionUtils.isNotEmpty(orders)) {
        addOrdered = true;
        buildSql = this.concatOrderBy(buildSql, orders);
    }
    // size 小于 0 且不限制返回值则不构造分页sql
    Long _limit = page.maxLimit() != null ? page.maxLimit() : maxLimit;
    if (page.getSize() < 0 && null == _limit) {
        if (addOrdered) {
            PluginUtils.mpBoundSql(boundSql).sql(buildSql);
        }
        return;
    }
    handlerLimit(page, _limit);
    IDialect dialect = findIDialect(executor);
    final Configuration configuration = ms.getConfiguration();
    DialectModel model = dialect.buildPaginationSql(buildSql, page.offset(), page.getSize());
    PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);
    List<ParameterMapping> mappings = mpBoundSql.parameterMappings();
    Map<String, Object> additionalParameter = mpBoundSql.additionalParameters();
    model.consumers(mappings, configuration, additionalParameter);
    mpBoundSql.sql(model.getDialectSql());
    mpBoundSql.parameterMappings(mappings);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) IDialect(com.baomidou.mybatisplus.solon.plugins.pagination.dialects.IDialect) DialectModel(com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem)

Example 2 with DialectModel

use of com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel in project solon by noear.

the class DB2Dialect method buildPaginationSql.

@Override
public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
    long firstParam = offset + 1;
    long secondParam = offset + limit;
    String sql = "SELECT * FROM (SELECT TMP_PAGE.*,ROWNUMBER() OVER() AS ROW_ID FROM ( " + originalSql + " ) AS TMP_PAGE) TMP_PAGE WHERE ROW_ID BETWEEN " + FIRST_MARK + " AND " + SECOND_MARK;
    return new DialectModel(sql, firstParam, secondParam).setConsumerChain();
}
Also used : DialectModel(com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel)

Example 3 with DialectModel

use of com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel in project solon by noear.

the class SybaseDialect method buildPaginationSql.

@Override
public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
    String tempSql = originalSql.toUpperCase();
    int index = tempSql.indexOf(" FROM ");
    String sql = "select";
    if (hasTop) {
        sql += " top " + (offset + limit);
    }
    sql += " rownum=identity(12)," + originalSql.substring(6, index) + " into #t " + originalSql.substring(index);
    sql += " select * from #t where rownum > ? and rownum <= ? ";
    sql += "drop table #t ";
    return new DialectModel(sql, offset, offset + limit).setConsumerChain();
}
Also used : DialectModel(com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel)

Example 4 with DialectModel

use of com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel in project solon by noear.

the class OracleDialect method buildPaginationSql.

@Override
public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
    limit = (offset >= 1) ? (offset + limit) : limit;
    String sql = "SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( " + originalSql + " ) TMP WHERE ROWNUM <=" + FIRST_MARK + ") WHERE ROW_ID > " + SECOND_MARK;
    return new DialectModel(sql, limit, offset).setConsumerChain();
}
Also used : DialectModel(com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel)

Aggregations

DialectModel (com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel)4 OrderItem (com.baomidou.mybatisplus.core.metadata.OrderItem)1 IDialect (com.baomidou.mybatisplus.solon.plugins.pagination.dialects.IDialect)1 ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)1 Configuration (org.apache.ibatis.session.Configuration)1