Search in sources :

Example 1 with IDialect

use of com.baomidou.mybatisplus.solon.plugins.pagination.dialects.IDialect 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)

Aggregations

OrderItem (com.baomidou.mybatisplus.core.metadata.OrderItem)1 DialectModel (com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel)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