Example usage for org.apache.ibatis.session RowBounds DEFAULT

List of usage examples for org.apache.ibatis.session RowBounds DEFAULT

Introduction

In this page you can find the example usage for org.apache.ibatis.session RowBounds DEFAULT.

Prototype

RowBounds DEFAULT

To view the source code for org.apache.ibatis.session RowBounds DEFAULT.

Click Source Link

Usage

From source file:com.tiamaes.mybatis.SqlUtil.java

License:Open Source License

/**
 * Mybatis//ww w .java 2  s.  co  m
 *
 * @param invocation ?
 * @return 
 * @throws Throwable 
 */
private Object _processPage(Invocation invocation) throws Throwable {
    final Object[] args = invocation.getArgs();
    Pagination page = null;
    //????Page
    if (supportMethodsArguments) {
        page = getPage(args);
    }
    //?
    RowBounds rowBounds = (RowBounds) args[2];
    //??page == null???
    if ((supportMethodsArguments && page == null)
            //???LocalPageRowBounds??
            || (!supportMethodsArguments && SqlUtil.getLocalPage() == null && rowBounds == RowBounds.DEFAULT)) {
        return invocation.proceed();
    } else {
        //???page==null??
        if (!supportMethodsArguments && page == null) {
            page = getPage(args);
        }
        return doProcessPage(invocation, page, args);
    }
}

From source file:com.tiamaes.mybatis.SqlUtil.java

License:Open Source License

/**
 * Mybatis//from  ww  w  . j  a v  a2  s  .  com
 *
 * @param invocation ?
 * @return 
 * @throws Throwable 
 */
private Pagination doProcessPage(Invocation invocation, Pagination page, Object[] args) throws Throwable {
    //?RowBounds?
    RowBounds rowBounds = (RowBounds) args[2];
    //?ms
    MappedStatement ms = (MappedStatement) args[0];
    //?PageSqlSource
    if (!isPageSqlSource(ms)) {
        processMappedStatement(ms);
    }
    //?parser????setThreadLocal???
    ((PageSqlSource) ms.getSqlSource()).setParser(parser);
    try {
        //RowBounds-?Mybatis
        args[2] = RowBounds.DEFAULT;
        //??  pageSizeZero
        if (isQueryOnly(page)) {
            return doQueryOnly(page, invocation);
        }

        //?total??count
        if (page.isCount()) {
            page.setCountSignal(Boolean.TRUE);
            //?MS
            args[0] = msCountMap.get(ms.getId());
            //
            Object result = invocation.proceed();
            //ms
            args[0] = ms;
            //
            page.setTotal((Integer) ((List) result).get(0));
            if (page.getTotal() == 0) {
                return page;
            }
        } else {
            page.setTotal(-1l);
        }
        //pageSize>0pageSize<=0???count
        if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0)
                || rowBounds != RowBounds.DEFAULT)) {
            //?MappedStatement?qs
            page.setCountSignal(null);
            BoundSql boundSql = ms.getBoundSql(args[1]);
            args[1] = parser.setPageParameter(ms, args[1], boundSql, page);
            page.setCountSignal(Boolean.FALSE);
            //
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
        }
    } finally {
        ((PageSqlSource) ms.getSqlSource()).removeParser();
    }

    //
    return page;
}

From source file:com.tj.mybatisplus.plugins.PaginationInterceptor.java

License:Apache License

public Object intercept(Invocation invocation) throws Throwable {
    Object target = invocation.getTarget();
    if (target instanceof StatementHandler) {
        StatementHandler statementHandler = (StatementHandler) target;
        MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
        RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");

        /* ??? */
        if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
            return invocation.proceed();
        }/*from  ww w .  j  a  v  a2s  .c  o  m*/

        /* ? */
        IDialect dialect = null;
        if (dialectType != null && !"".equals(dialectType)) {
            dialect = DialectFactory.getDialectByDbtype(dialectType);
        } else {
            if (dialectClazz != null && !"".equals(dialectClazz)) {
                try {
                    Class<?> clazz = Class.forName(dialectClazz);
                    if (IDialect.class.isAssignableFrom(clazz)) {
                        dialect = (IDialect) clazz.newInstance();
                    }
                } catch (ClassNotFoundException e) {
                    throw new MybatisPlusException("Class :" + dialectClazz + " is not found");
                }
            }
        }

        /* ? */
        if (dialect == null) {
            throw new MybatisPlusException(
                    "The value of the dialect property in mybatis configuration.xml is not defined.");
        }

        /*
         * <p>
         * ?
         * </p>
         * <p>
         * ???????
         * </p>
         */
        BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
        String originalSql = (String) boundSql.getSql();
        metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
        metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);

        /**
         * <p>
         * 
         * </p>
         * <p>
         *  count
         * </p>
         */
        if (rowBounds instanceof Pagination) {
            MappedStatement mappedStatement = (MappedStatement) metaStatementHandler
                    .getValue("delegate.mappedStatement");
            Connection connection = (Connection) invocation.getArgs()[0];
            Pagination page = (Pagination) rowBounds;
            if (page.isSearchCount()) {
                page = this.count(originalSql, connection, mappedStatement, boundSql, page);
            }
            originalSql = dialect.buildPaginationSql(originalSql, page.getOffsetCurrent(), page.getSize());
        }

        /**
         *  SQL 
         */
        metaStatementHandler.setValue("delegate.boundSql.sql", originalSql);
    }

    return invocation.proceed();
}

From source file:com.web.util.bootstraptable.PageHelper.java

License:Open Source License

/**
 * Mybatis/*from w ww.  ja va  2 s. c  o m*/
 *
 * @param invocation ?
 * @return 
 * @throws Throwable 
 */
public Object intercept(Invocation invocation) throws Throwable {
    final Object[] args = invocation.getArgs();
    RowBounds rowBounds = (RowBounds) args[2];
    if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) {
        return invocation.proceed();
    } else {
        //RowBounds-?Mybatis
        args[2] = RowBounds.DEFAULT;
        MappedStatement ms = (MappedStatement) args[0];
        Object parameterObject = args[1];
        //?
        Page page = getPage(rowBounds);
        //pageSizeZero
        if (pageSizeZero && page.getPageSize() == 0) {
            //?
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
            //
            page.setPageNum(1);
            //?pageSize=total
            page.setPageSize(page.size());
            //??total
            page.setTotal(page.size());
            //?Page - ???
            return page;
        }
        //?total??count
        if (page.isCount()) {
            BoundSql boundSql = null;
            //???sql??boundSql
            if (!SQLUTIL.isDynamic(ms)) {
                boundSql = ms.getBoundSql(parameterObject);
            }
            //?MappedStatement?qs
            args[0] = SQLUTIL.getCountMappedStatement(ms, boundSql);
            //
            Object result = invocation.proceed();
            //
            page.setTotal((Integer) ((List) result).get(0));
            if (page.getTotal() == 0) {
                return page;
            }
        }
        //pageSize>0pageSize<=0???count
        if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0)
                || rowBounds != RowBounds.DEFAULT)) {
            BoundSql boundSql = null;
            //???sql??boundSql
            if (!SQLUTIL.isDynamic(ms)) {
                boundSql = ms.getBoundSql(parameterObject);
            }
            //?MappedStatement?qs
            args[0] = SQLUTIL.getPageMappedStatement(ms, boundSql);
            //?sqlboundSqlms?
            if (boundSql == null) {
                boundSql = ((MappedStatement) args[0]).getBoundSql(parameterObject);
            }
            //parameterObject?
            args[1] = SQLUTIL.setPageParameter(parameterObject, boundSql, page);
            //
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
        }
        //
        return page;
    }
}

From source file:com.wsun.seap.dao.interceptor.PaginationInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    // ??// ww  w . j av a2 s  . co m
    final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX];
    // ?SQL
    // ??
    Object parameterObj = invocation.getArgs()[PARAMETER_INDEX];
    // ??QueryParam
    Object parameter;
    if (parameterObj instanceof QueryParam) {
        // ?QueryParam,??Map
        parameter = ((QueryParam) parameterObj).getAllParam();
        invocation.getArgs()[PARAMETER_INDEX] = parameter;
    } else {
        parameter = parameterObj;
    }

    BoundSql boundSql = mappedStatement.getBoundSql(parameter);
    if (StringUtils.isBlank(boundSql.getSql())) {
        return null;
    }
    // ??RowBounds
    RowBounds rowBounds = (RowBounds) invocation.getArgs()[ROWBOUNDS_INDEX];
    // 
    if (rowBounds != null && rowBounds != RowBounds.DEFAULT) {
        String originalSql = boundSql.getSql().trim();
        // ??sql
        String pageSql = dialect.getLimitString(originalSql, rowBounds.getOffset(), rowBounds.getLimit());
        invocation.getArgs()[ROWBOUNDS_INDEX] = new RowBounds(RowBounds.NO_ROW_OFFSET, RowBounds.NO_ROW_LIMIT);
        BoundSql newBoundSql = new BoundSql(mappedStatement.getConfiguration(), pageSql,
                boundSql.getParameterMappings(), boundSql.getParameterObject());
        MappedStatement newMs = copyFromMappedStatement(mappedStatement, new BoundSqlSqlSource(newBoundSql));
        invocation.getArgs()[MAPPED_STATEMENT_INDEX] = newMs;
    }
    return invocation.proceed();
}

From source file:com.yimidida.shards.plugin.PaginationInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    final MappedStatement mappedStatement = this.getMappedStatement(invocation);
    final Object parameter = this.getParameter(invocation);
    final RowBounds rowBounds = this.getRowBounds(invocation);

    final int offset = rowBounds.getOffset();
    final int limit = rowBounds.getLimit();

    if (dialect.supportLimit() && (offset != RowBounds.NO_ROW_OFFSET || limit != RowBounds.NO_ROW_LIMIT)) {
        BoundSql boundSql = mappedStatement.getBoundSql(parameter);
        String sql = boundSql.getSql().trim();

        if (dialect.supportOffsetLimit()) {
            sql = dialect.getLimitString(sql, offset, limit);
        } else {/*  w  w w  . j  a  va 2 s. c om*/
            sql = dialect.getLimitString(sql, RowBounds.NO_ROW_OFFSET, limit);
        }

        this.setMappedStatement(invocation, this.buildMappedStatement(mappedStatement, boundSql, sql));
        this.setRowBounds(invocation, RowBounds.DEFAULT);
    }

    return invocation.proceed();
}

From source file:com.yimidida.shards.session.impl.ShardedSqlSessionImpl.java

License:Open Source License

private <T> T applyGetOperation(ShardOperation<T> shardOp, ShardResolutionStrategyData srsd) {
    List<ShardId> shardIds = selectShardIdsFromShardResolutionStrategyData(srsd);
    return shardStrategy.getShardAccessStrategy()
            .<T>apply(this.shardIdListToShardList(shardIds), shardOp, new FirstNonNullResultExitStrategy<T>(),
                    new ExitOperationsSelectCollector(new AdHocSelectFactoryImpl(srsd.getStatement(),
                            srsd.getParameter(), null, RowBounds.DEFAULT),
                            shardStrategy.getShardReduceStrategy()));
}

From source file:com.yimidida.shards.session.impl.ShardedSqlSessionImpl.java

License:Open Source License

@Override
public <E> List<E> selectList(String statement, Object parameter) {
    return this.<E>selectList(statement, parameter, RowBounds.DEFAULT);
}

From source file:com.yimidida.shards.session.impl.ShardedSqlSessionImpl.java

License:Open Source License

@Override
public <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey) {
    return this.<K, V>selectMap(statement, parameter, mapKey, RowBounds.DEFAULT);
}

From source file:com.yimidida.shards.strategy.exit.impl.ExitOperationsSelectCollector.java

License:Open Source License

@Override
public List<Object> apply(List<Object> values) {

    if (!values.isEmpty()) {
        //reduce/*from  www.j  av  a2  s .  c  o m*/
        List<Object> results = shardReduceStrategy.reduce(statement, parameter, rowBounds, values);

        values = (results != null) ? results : Collections.emptyList(); //null

        if (rowBounds != null && rowBounds != RowBounds.DEFAULT) {
            values = new RowBoundsExitOperation(rowBounds).apply(values);
        }

    }

    return values;
}