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

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

Introduction

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

Prototype

int NO_ROW_LIMIT

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

Click Source Link

Usage

From source file:com.monee1988.core.mybatis.pageinterceptor.PageInterceptor.java

License:Open Source License

void processMybatisIntercept(final Object[] queryArgs, Invocation invocation) {
    MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX];
    Object parameter = queryArgs[PARAMETER_INDEX];

    Page<?> page = null;/*w  ww  .j ava  2s  .c  o  m*/

    if (parameter != null) {
        page = convertParameter(page, parameter);
    }

    if (dialect.supportsLimit() && page != null) {

        BoundSql boundSql = ms.getBoundSql(parameter);
        String sql = boundSql.getSql().trim();

        final RowBounds rowBounds = (RowBounds) queryArgs[ROWBOUNDS_INDEX];
        int offset = rowBounds.getOffset();
        int limit = rowBounds.getLimit();
        offset = page.getOffset();
        limit = page.getPageSize();

        CachingExecutor executor = (CachingExecutor) invocation.getTarget();

        Transaction transaction = executor.getTransaction();
        try {
            Connection connection = transaction.getConnection();
            /**
             * 
             */
            this.setTotalRecord(page, ms, connection, parameter);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (dialect.supportsLimitOffset()) {

            sql = dialect.getLimitString(sql, offset, limit);
            offset = RowBounds.NO_ROW_OFFSET;

        } else {

            sql = dialect.getLimitString(sql, 0, limit);

        }
        limit = RowBounds.NO_ROW_LIMIT;

        queryArgs[ROWBOUNDS_INDEX] = new RowBounds(offset, limit);

        BoundSql newBoundSql = copyFromBoundSql(ms, boundSql, sql);

        MappedStatement newMs = copyFromMappedStatement(ms, new BoundSqlSqlSource(newBoundSql));

        queryArgs[MAPPED_STATEMENT_INDEX] = newMs;

    }
}

From source file:com.mybatisX.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();
        }//  www .jav a 2s . com

        /* ? */
        IDialect dialect = getiDialect();

        /*
         * <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) {
            Pagination page = (Pagination) rowBounds;
            boolean orderBy = true;
            if (page.isSearchCount()) {
                /*
                 * COUNT  ORDER BY  SQL
                 */
                CountOptimize countOptimize = SqlUtils.getCountOptimize(originalSql, page.isOptimizeCount());
                orderBy = countOptimize.isOrderBy();
            }
            /*  SQL */
            String buildSql = SqlUtils.concatOrderBy(originalSql, page, orderBy);
            originalSql = dialect.buildPaginationSql(buildSql, page.getOffsetCurrent(), page.getSize());
        }

        /**
         *  SQL 
         */
        metaStatementHandler.setValue("delegate.boundSql.sql", originalSql);
    } else {
        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
        Object parameterObject = null;
        RowBounds rowBounds = null;
        if (invocation.getArgs().length > 1) {
            parameterObject = invocation.getArgs()[1];
            rowBounds = (RowBounds) invocation.getArgs()[2];
        }
        /* ??? */
        if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
            return invocation.proceed();
        }

        BoundSql boundSql = mappedStatement.getBoundSql(parameterObject);
        /*
         * <p> ? </p> <p> ???????
         * </p>
         */
        String originalSql = (String) boundSql.getSql();

        /**
         * <p>
         * 
         * </p>
         * <p>
         *  count
         * </p>
         */
        if (rowBounds instanceof Pagination) {
            Connection connection = null;
            try {
                connection = mappedStatement.getConfiguration().getEnvironment().getDataSource()
                        .getConnection();
                Pagination page = (Pagination) rowBounds;
                if (page.isSearchCount()) {
                    /*
                     * COUNT  ORDER BY  SQL
                     */
                    CountOptimize countOptimize = SqlUtils.getCountOptimize(originalSql,
                            page.isOptimizeCount());
                    page = this.count(countOptimize.getCountSQL(), connection, mappedStatement, boundSql, page);
                    /**  0  */
                    if (page.getTotal() <= 0) {
                        return invocation.proceed();
                    }
                }
            } finally {
                IOUtils.closeQuietly(connection);
            }
        }
    }

    return invocation.proceed();

}

From source file:com.saituo.talk.common.persistence.interceptor.PaginationInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {

    final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];

    // //?SQL//from ww w  .ja v  a  2s. c  o  m
    // // if (mappedStatement.getId().matches(_SQL_PATTERN)) {
    // if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(),
    // _SQL_PATTERN) != -1) {
    Object parameter = invocation.getArgs()[1];
    BoundSql boundSql = mappedStatement.getBoundSql(parameter);
    Object parameterObject = boundSql.getParameterObject();

    // ??
    Page<Object> page = null;
    if (parameterObject != null) {
        page = convertParameter(parameterObject, page);
    }

    // 
    if (page != null && page.getPageSize() != -1) {

        if (StringUtils.isBlank(boundSql.getSql())) {
            return null;
        }
        String originalSql = boundSql.getSql().trim();

        // 
        page.setCount(SQLHelper.getCount(originalSql, null, mappedStatement, parameterObject, boundSql, log));

        //   ??
        String pageSql = SQLHelper.generatePageSql(originalSql, page, DIALECT);
        // if (log.isDebugEnabled()) {
        // log.debug("PAGE SQL:" + StringUtils.replace(pageSql, "\n", ""));
        // }
        invocation.getArgs()[2] = 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()[0] = newMs;
    }
    // }
    return invocation.proceed();
}

From source file:com.springD.framework.persistence.interceptor.PaginationInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {

    final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];

    //        //?SQL
    //        if (mappedStatement.getId().matches(_SQL_PATTERN)) {
    //        if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(), _SQL_PATTERN) != -1) {
    Object parameter = invocation.getArgs()[1];
    BoundSql boundSql = mappedStatement.getBoundSql(parameter);
    Object parameterObject = boundSql.getParameterObject();

    //??/*from   w ww.j  av  a 2  s . c  o  m*/
    Page<Object> page = null;
    if (parameterObject != null) {
        page = convertParameter(parameterObject, page);
    }

    //
    if (page != null && page.getPageSize() != -1) {

        if (org.apache.commons.lang3.StringUtils.isBlank(boundSql.getSql())) {
            return null;
        }
        String originalSql = boundSql.getSql().trim();

        //
        page.setCount(SQLHelper.getCount(originalSql, null, mappedStatement, parameterObject, boundSql, log));

        //  ??
        String pageSql = SQLHelper.generatePageSql(originalSql, page, DIALECT);
        //                if (log.isDebugEnabled()) {
        //                    log.debug("PAGE SQL:" + StringUtils.replace(pageSql, "\n", ""));
        //                }
        invocation.getArgs()[2] = 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()[0] = newMs;
    }
    //        }
    return invocation.proceed();
}

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  w w 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.wsun.seap.dao.interceptor.PaginationInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    // ??/*from   ww  w. j a  va 2s .c  o  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 {/*ww  w  . j a  v a  2 s  .c o m*/
            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:core.plugin.mybatis.PageInterceptor.java

License:Apache License

@Override
public Object intercept(Invocation inv) throws Throwable {
    // prepare?Connection
    Connection connection = (Connection) inv.getArgs()[0];
    String dbType = connection.getMetaData().getDatabaseProductName();
    L.debug(dbType);// w ww  .jav  a  2  s  . com
    Dialect dialect = null;
    if (StringUtils.equalsIgnoreCase("ORACLE", dbType)) {
        dialect = new OracleDialect();
    } else if (StringUtils.equalsIgnoreCase("H2", dbType)) {
        dialect = new H2Dialect();
    } else {
        throw new AppRuntimeException("A404: Not Support ['" + dbType + "'] Pagination Yet!");
    }

    StatementHandler target = (StatementHandler) inv.getTarget();
    BoundSql boundSql = target.getBoundSql();
    String sql = boundSql.getSql();
    if (StringUtils.isBlank(sql)) {
        return inv.proceed();
    }
    // ?select??
    if (sql.matches(SQL_SELECT_REGEX) && !Pattern.matches(SQL_COUNT_REGEX, sql)) {
        Object obj = FieldUtils.readField(target, "delegate", true);
        // ??? RowBounds 
        RowBounds rowBounds = (RowBounds) FieldUtils.readField(obj, "rowBounds", true);
        // ??SQL
        if (rowBounds != null && rowBounds != RowBounds.DEFAULT) {
            FieldUtils.writeField(boundSql, "sql", dialect.getSqlWithPagination(sql, rowBounds), true);
            // ???(?)
            FieldUtils.writeField(rowBounds, "offset", RowBounds.NO_ROW_OFFSET, true);
            FieldUtils.writeField(rowBounds, "limit", RowBounds.NO_ROW_LIMIT, true);
        }
    }
    return inv.proceed();
}

From source file:org.alfresco.repo.domain.activities.ibatis.ActivityFeedDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from w w  w .j  a  v a2s  .c  o  m*/
public List<ActivityFeedEntity> selectUserFeedEntries(String feedUserId, String siteId, boolean excludeThisUser,
        boolean excludeOtherUsers, long minFeedId, int maxFeedSize) throws SQLException {
    ActivityFeedQueryEntity params = new ActivityFeedQueryEntity();
    params.setFeedUserId(feedUserId);

    if (minFeedId > -1) {
        params.setMinId(minFeedId);
    }

    int rowLimit = maxFeedSize < 0 ? RowBounds.NO_ROW_LIMIT : maxFeedSize;
    RowBounds rowBounds = new RowBounds(RowBounds.NO_ROW_OFFSET, rowLimit);

    if (siteId != null) {
        // given site
        params.setSiteNetwork(siteId);

        if (excludeThisUser && excludeOtherUsers) {
            // effectively NOOP - return empty feed
            return new ArrayList<ActivityFeedEntity>(0);
        }
        if ((!excludeThisUser) && (!excludeOtherUsers)) {
            // no excludes => everyone => where feed user is me
            return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser_and_site",
                    params, rowBounds);
        } else if ((excludeThisUser) && (!excludeOtherUsers)) {
            // exclude feed user => others => where feed user is me and post user is not me
            return template.selectList(
                    "alfresco.activities.select.select_activity_feed_for_feeduser_others_and_site", params,
                    rowBounds);
        } else if ((excludeOtherUsers) && (!excludeThisUser)) {
            // exclude others => me => where feed user is me and post user is me
            return template.selectList(
                    "alfresco.activities.select.select_activity_feed_for_feeduser_me_and_site", params,
                    rowBounds);
        }
    } else {
        // all sites

        if (excludeThisUser && excludeOtherUsers) {
            // effectively NOOP - return empty feed
            return new ArrayList<ActivityFeedEntity>(0);
        }
        if (!excludeThisUser && !excludeOtherUsers) {
            // no excludes => everyone => where feed user is me
            return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser", params,
                    rowBounds);
        } else if (excludeThisUser) {
            // exclude feed user => others => where feed user is me and post user is not me
            return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser_others",
                    params, rowBounds);
        } else if (excludeOtherUsers) {
            // exclude others => me => where feed user is me and post user is me
            return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser_me",
                    params, rowBounds);
        }
    }

    // belts-and-braces
    throw new AlfrescoRuntimeException("Unexpected: invalid arguments");
}

From source file:org.alfresco.repo.domain.activities.ibatis.ActivityFeedDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  w w w .  ja  v a2s. c  o  m
public List<ActivityFeedEntity> selectSiteFeedEntries(String siteId, int maxFeedSize) throws SQLException {
    ActivityFeedQueryEntity params = new ActivityFeedQueryEntity();
    params.setSiteNetwork(siteId);

    int rowLimit = maxFeedSize < 0 ? RowBounds.NO_ROW_LIMIT : maxFeedSize;
    RowBounds rowBounds = new RowBounds(RowBounds.NO_ROW_OFFSET, rowLimit);

    // for given site
    return template.selectList("alfresco.activities.select.select_activity_feed_for_site", params, rowBounds);
}