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:com.sino.ssi.mybatis.plugin.SqlUtil.java
License:Open Source License
/** * Mybatis/*from w w w .j a v a 2 s .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 ShowSQL.proceed(invocation); } else { //?ms MappedStatement ms = (MappedStatement) args[0]; //RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; //? Page page = getPage(rowBounds); //pageSizeZero if ((page.getPageSizeZero() != null && page.getPageSizeZero()) && page.getPageSize() == 0) { //? Object result = ShowSQL.proceed(invocation); //? page.addAll((List) result); // page.setPageNum(1); //?pageSize=total page.setPageSize(page.size()); //??total page.setTotal(page.size()); //?Page - ??? return page; } SqlSource sqlSource = ((MappedStatement) args[0]).getSqlSource(); //?total??count if (page.isCount()) { //?MappedStatement?qs processCountMappedStatement(ms, sqlSource, args); // Object result = ShowSQL.proceed(invocation); // 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 processPageMappedStatement(ms, sqlSource, page, args); // Object result = ShowSQL.proceed(invocation); //? page.addAll((List) result); } // return page; } }
From source file:com.sinotopia.mybatis.mapper.mapperhelper.SelectKeyGenerator.java
License:Apache License
private void processGeneratedKeys(Executor executor, MappedStatement ms, Object parameter) { try {//w ww.j a va 2s . c o m if (parameter != null && keyStatement != null && keyStatement.getKeyProperties() != null) { String[] keyProperties = keyStatement.getKeyProperties(); final Configuration configuration = ms.getConfiguration(); final MetaObject metaParam = configuration.newMetaObject(parameter); if (keyProperties != null) { // Do not close keyExecutor. // The transaction will be closed by parent executor. Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE); List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER); if (values.size() == 0) { throw new ExecutorException("SelectKey returned no data."); } else if (values.size() > 1) { throw new ExecutorException("SelectKey returned more than one value."); } else { MetaObject metaResult = configuration.newMetaObject(values.get(0)); if (keyProperties.length == 1) { if (metaResult.hasGetter(keyProperties[0])) { setValue(metaParam, keyProperties[0], metaResult.getValue(keyProperties[0])); } else { // no getter for the property - maybe just a single value object // so try that setValue(metaParam, keyProperties[0], values.get(0)); } } else { handleMultipleProperties(keyProperties, metaParam, metaResult); } } } } } catch (ExecutorException e) { throw e; } catch (Exception e) { throw new ExecutorException("Error selecting key or setting result to parameter object. Cause: " + e, e); } }
From source file:com.sinotopia.mybatis.pagehelper.page.PageParams.java
License:Open Source License
/** * ??//from ww w. j a v a 2 s .co m * * @param parameterObject * @param rowBounds * @return */ public Page getPage(Object parameterObject, RowBounds rowBounds) { Page page = PageHelper.getLocalPage(); if (page == null) { if (rowBounds != RowBounds.DEFAULT) { if (offsetAsPageNum) { page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount); } else { page = new Page(new int[] { rowBounds.getOffset(), rowBounds.getLimit() }, rowBoundsWithCount); //offsetAsPageNum=falsePageNum?reasonablefalse page.setReasonable(false); } } else if (supportMethodsArguments) { try { page = PageObjectUtil.getPageFromObject(parameterObject, false); } catch (Exception e) { return null; } } if (page == null) { return null; } PageHelper.setLocalPage(page); } //?? if (page.getReasonable() == null) { page.setReasonable(reasonable); } //truepagesize0RowBoundslimit=0? if (page.getPageSizeZero() == null) { page.setPageSizeZero(pageSizeZero); } return page; }
From source file:com.sinotopia.mybatis.pagehelper.PageInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { try {/*from w w w.j av a 2 s . com*/ Object[] args = invocation.getArgs(); MappedStatement ms = (MappedStatement) args[0]; Object parameter = args[1]; RowBounds rowBounds = (RowBounds) args[2]; ResultHandler resultHandler = (ResultHandler) args[3]; Executor executor = (Executor) invocation.getTarget(); CacheKey cacheKey; BoundSql boundSql; //? if (args.length == 4) { //4 ? boundSql = ms.getBoundSql(parameter); cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql); } else { //6 ? cacheKey = (CacheKey) args[4]; boundSql = (BoundSql) args[5]; } List resultList; //???? if (!dialect.skip(ms, parameter, rowBounds)) { //????? String msId = ms.getId(); Configuration configuration = ms.getConfiguration(); Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField .get(boundSql); //?? count if (dialect.beforeCount(ms, parameter, rowBounds)) { String countMsId = msId + countSuffix; Long count; //? count MappedStatement countMs = getExistedMappedStatement(configuration, countMsId); if (countMs != null) { count = executeManualCount(executor, countMs, parameter, boundSql, resultHandler); } else { countMs = msCountMap.get(countMsId); // if (countMs == null) { //?? ms Long ms countMs = MSUtils.newCountMappedStatement(ms, countMsId); msCountMap.put(countMsId, countMs); } count = executeAutoCount(executor, countMs, parameter, boundSql, rowBounds, resultHandler); } //? // true false if (!dialect.afterCount(count, parameter, rowBounds)) { // 0 return dialect.afterPage(new ArrayList(), parameter, rowBounds); } } //?? if (dialect.beforePage(ms, parameter, rowBounds)) { //? key CacheKey pageKey = cacheKey; //?? parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey); //? sql String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey); BoundSql pageBoundSql = new BoundSql(configuration, pageSql, boundSql.getParameterMappings(), parameter); //?? for (String key : additionalParameters.keySet()) { pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); } // resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql); } else { //?? resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, cacheKey, boundSql); } } else { //rowBounds?????? resultList = executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql); } return dialect.afterPage(resultList, parameter, rowBounds); } finally { dialect.afterAll(); } }
From source file:com.sinotopia.mybatis.pagehelper.PageInterceptor.java
License:Open Source License
/** * count ???/*from w w w. j av a 2 s.c o m*/ * * @param executor * @param countMs * @param parameter * @param boundSql * @param resultHandler * @return * @throws IllegalAccessException * @throws SQLException */ private Long executeManualCount(Executor executor, MappedStatement countMs, Object parameter, BoundSql boundSql, ResultHandler resultHandler) throws IllegalAccessException, SQLException { CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql); BoundSql countBoundSql = countMs.getBoundSql(parameter); Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql); Long count = ((Number) ((List) countResultList).get(0)).longValue(); return count; }
From source file:com.sinotopia.mybatis.pagehelper.PageInterceptor.java
License:Open Source License
/** * ? count //w w w .j a v a 2s. c o m * * @param executor * @param countMs * @param parameter * @param boundSql * @param rowBounds * @param resultHandler * @return * @throws IllegalAccessException * @throws SQLException */ private Long executeAutoCount(Executor executor, MappedStatement countMs, Object parameter, BoundSql boundSql, RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException { Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField.get(boundSql); // count key CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql); //? count sql String countSql = dialect.getCountSql(countMs, boundSql, parameter, rowBounds, countKey); //countKey.update(countSql); BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(), parameter); //? SQL ???? BoundSql for (String key : additionalParameters.keySet()) { countBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); } // count Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql); Long count = (Long) ((List) countResultList).get(0); return count; }
From source file:com.swifts.frame.common.pagehelper.SqlUtil.java
License:Open Source License
/** * ??/*from w ww . j av a 2 s . c o m*/ * * @param args * @return Page */ public com.swifts.frame.common.pagehelper.Page getPage(Object[] args) { com.swifts.frame.common.pagehelper.Page page = getLocalPage(); if (page == null || page.isOrderByOnly()) { com.swifts.frame.common.pagehelper.Page oldPage = page; //?,page.isOrderByOnly()true?? if ((args[2] == null || args[2] == RowBounds.DEFAULT) && page != null) { return oldPage; } if (args[2] instanceof RowBounds && args[2] != RowBounds.DEFAULT) { RowBounds rowBounds = (RowBounds) args[2]; if (offsetAsPageNum) { page = new com.swifts.frame.common.pagehelper.Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount); } else { page = new com.swifts.frame.common.pagehelper.Page( new int[] { rowBounds.getOffset(), rowBounds.getLimit() }, rowBoundsWithCount); //offsetAsPageNum=falsePageNum?reasonablefalse page.setReasonable(false); } } else { try { page = getPageFromObject(args[1]); } catch (Exception e) { return null; } } if (oldPage != null) { page.setOrderBy(oldPage.getOrderBy()); } setLocalPage(page); } //?? if (page.getReasonable() == null) { page.setReasonable(reasonable); } //truepagesize0RowBoundslimit=0? if (page.getPageSizeZero() == null) { page.setPageSizeZero(pageSizeZero); } return page; }
From source file:com.swifts.frame.common.pagehelper.SqlUtil.java
License:Open Source License
/** * Mybatis//from w w w . ja v a2s . c o m * * @param invocation ? * @return * @throws Throwable */ private Object _processPage(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); com.swifts.frame.common.pagehelper.Page 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.swifts.frame.common.pagehelper.SqlUtil.java
License:Open Source License
/** * Mybatis// w w w. j av a 2 s . co m * * @param invocation ? * @return * @throws Throwable */ private com.swifts.frame.common.pagehelper.Page doProcessPage(Invocation invocation, Page 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); //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); } // return page; }
From source file:com.tiamaes.mybatis.SqlUtil.java
License:Open Source License
/** * ??// ww w . j a va 2s . c o m * * @param args * @return Page */ public Pagination getPage(Object[] args) { Pagination page = getLocalPage(); if (page == null || page.isOrderByOnly()) { Pagination oldPage = page; //?,page.isOrderByOnly()true?? if ((args[2] == null || args[2] == RowBounds.DEFAULT) && page != null) { return oldPage; } if (args[2] instanceof RowBounds && args[2] != RowBounds.DEFAULT) { RowBounds rowBounds = (RowBounds) args[2]; if (offsetAsPageNum) { page = new Pagination(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount); } else { page = new Pagination(new int[] { rowBounds.getOffset(), rowBounds.getLimit() }, rowBoundsWithCount); //offsetAsPageNum=falsePageNum?reasonablefalse page.setReasonable(false); } } else { try { page = getPageFromObject(args[1]); } catch (Exception e) { return null; } } if (oldPage != null) { page.setOrderBy(oldPage.getOrderBy()); } setLocalPage(page); } //?? if (page.getReasonable() == null) { page.setReasonable(reasonable); } //truepagesize0RowBoundslimit=0? if (page.getPageSizeZero() == null) { page.setPageSizeZero(pageSizeZero); } return page; }