List of usage examples for org.apache.ibatis.session RowBounds DEFAULT
RowBounds DEFAULT
To view the source code for org.apache.ibatis.session RowBounds DEFAULT.
Click Source Link
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 w w.ja v a2 s.co m 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:jp.co.ctc_g.jfw.core.jdbc.JxSqlSession.java
License:Apache License
/** * ????//from w ww. jav a 2s . c om * @param <E> ?? * @param statement ?SQL?ID * @param parameter ?????? * @return ? */ public <E> List<E> selectList(String statement, Object parameter) { return selectList(statement, parameter, RowBounds.DEFAULT); }
From source file:jp.co.ctc_g.jfw.core.jdbc.JxSqlSession.java
License:Apache License
/** * ????/*from www . j av a 2s. co m*/ * ???SQL?ID?{@link PaginationEnableMatcher}?? * ?????? * {@link #selectListWithPaginating(String, Paginatable)}??? * {@link #selectListWithPaginating(String, Object, RowBounds)}????? * ?? {@link RowBounds} ?? * paramter? {@link Paginatable} ???????? * @param <E> ?? * @param statement ?SQL?ID * @param parameter ?????? * @param rowBounds * @return ? */ public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) { if (paginationEnableMatcher.match(statement, parameter)) { if (parameter instanceof Paginatable && RowBounds.DEFAULT.equals(rowBounds)) { return selectListWithPaginating(statement, (Paginatable) parameter); } else { return selectListWithPaginating(statement, parameter, rowBounds); } } return delegate.selectList(statement, parameter, rowBounds); }
From source file:org.apache.playframework.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"); Configuration configuration = (Configuration) metaStatementHandler.getValue("delegate.configuration"); BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql"); String originalSql = (String) boundSql.getSql(); /* ?? *//*from w ww . j a v a 2 s . c om*/ if (rowBounds != null && rowBounds != RowBounds.DEFAULT) { /* ? */ IDialect dialect = getiDialect(); /* * <p> ? </p> <p> ??????? * </p> */ 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, optimizeType, dialectType, 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", buildSql(originalSql, configuration)); } 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, optimizeType, dialectType, 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:org.fire.platform.common.page.SqlUtil.java
License:Open Source License
/** * Mybatis/* www . j a va2s .c o m*/ * * @param invocation ? * @return * @throws Throwable */ private Object _processPage(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (SqlUtil.getLocalPage() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else { //RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; //? Page page = getPage(rowBounds); //pageSizeZero if ((page.getPageSizeZero() != null && page.getPageSizeZero()) && page.getPageSize() == 0) { //? Object result = invocation.proceed(); //? page.getResults().addAll((List) result); //added by wang page.addAll((List) result); // page.setPageNum(1); //?pageSize=total page.setPageSize(page.size()); //??total page.setTotal(page.size()); //?Page - ??? return page; } //?ms MappedStatement ms = (MappedStatement) args[0]; SqlSource sqlSource = ms.getSqlSource(); //?total??count if (page.isCount()) { //?MappedStatement?qs msUtils.processCountMappedStatement(ms, sqlSource, args); // 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)) { //?MappedStatement?qs msUtils.processPageMappedStatement(ms, sqlSource, page, args); // Object result = invocation.proceed(); //? page.getResults().addAll((List) result); //added by wang page.addAll((List) result); } // return page; } }
From source file:org.nebula.service.dao.PaginationInterceptor.java
License:Apache License
public Object intercept(Invocation inv) throws Throwable { StatementHandler target = (StatementHandler) inv.getTarget(); BoundSql boundSql = target.getBoundSql(); String sql = boundSql.getSql(); if (StringUtils.isBlank(sql)) { return inv.proceed(); }/*from ww w . j a v a 2 s .c om*/ logger.debug("origin sql>>>>>" + sql.replaceAll("\n", "")); // ?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", newSql(sql, rowBounds), true); logger.debug("new sql>>>>>" + boundSql.getSql().replaceAll("\n", "")); // ???(?) 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.smqk.framework.pagehelper.PageHelper.java
License:Open Source License
/** * Mybatis/* w w w .jav a 2 s .c om*/ * * @param invocation ? * @return * @throws Throwable */ public Object intercept(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (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; } }