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.github.pagehelper.PageHelper.java
License:Open Source License
/** * Mybatis//from w ww . j av a 2s . 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 { //?ms MappedStatement ms = (MappedStatement) args[0]; //RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; //? 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; } SqlSource sqlSource = ((MappedStatement) args[0]).getSqlSource(); //?total??count if (page.isCount()) { //?MappedStatement?qs SQLUTIL.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 SQLUTIL.processPageMappedStatement(ms, sqlSource, page, args); // Object result = invocation.proceed(); //? page.addAll((List) result); } // return page; } }
From source file:com.github.pagehelper.PageInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { try {// w ww . j a v a2 s .c om 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)) { //????? Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField .get(boundSql); //?? count if (dialect.beforeCount(ms, parameter, rowBounds)) { // count key CacheKey countKey = executor.createCacheKey(ms, parameter, RowBounds.DEFAULT, boundSql); countKey.update(MSUtils.COUNT); MappedStatement countMs = msCountMap.get(countKey); if (countMs == null) { //?? ms Long ms countMs = MSUtils.newCountMappedStatement(ms); msCountMap.put(countKey, countMs); } //? count sql String countSql = dialect.getCountSql(ms, boundSql, parameter, rowBounds, countKey); BoundSql countBoundSql = new BoundSql(ms.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); //? // 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(ms.getConfiguration(), 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.github.pagehelper.util.ExecutorUtil.java
License:Open Source License
/** * count ???//from w w w . ja v a2 s. com * * @param executor * @param countMs * @param parameter * @param boundSql * @param resultHandler * @return * @throws SQLException */ public static Long executeManualCount(Executor executor, MappedStatement countMs, Object parameter, BoundSql boundSql, ResultHandler resultHandler) throws 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.github.pagehelper.util.ExecutorUtil.java
License:Open Source License
/** * ? count /* ww w .j a v a2 s.c o m*/ * * @param dialect * @param executor * @param countMs * @param parameter * @param boundSql * @param rowBounds * @param resultHandler * @return * @throws SQLException */ public static Long executeAutoCount(Dialect dialect, Executor executor, MappedStatement countMs, Object parameter, BoundSql boundSql, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException { Map<String, Object> additionalParameters = getAdditionalParameter(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.github.pagehelper.util.ExecutorUtil.java
License:Open Source License
/** * /*from w w w .j ava 2 s. c om*/ * * @param dialect * @param executor * @param ms * @param parameter * @param rowBounds * @param resultHandler * @param boundSql * @param cacheKey * @param <E> * @return * @throws SQLException */ public static <E> List<E> pageQuery(Dialect dialect, Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql, CacheKey cacheKey) throws SQLException { //?? 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(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameter); Map<String, Object> additionalParameters = getAdditionalParameter(boundSql); //?? for (String key : additionalParameters.keySet()) { pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); } // return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql); } else { //?? return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, cacheKey, boundSql); } }
From source file:com.gochinatv.accelarator.framework.web.base.pagination.SqlUtil.java
License:Open Source License
/** * ??// w ww . j a v a 2 s . c om * * @param args * @return Page */ public Page getPage(Object[] args) { Page page = getLocalPage(); if (page == null || page.isOrderByOnly()) { 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 Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount); } else { page = new 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.gochinatv.accelarator.framework.web.base.pagination.SqlUtil.java
License:Open Source License
/** * Mybatis// www .jav a 2s.c om * * @param invocation ? * @return * @throws Throwable */ private 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.hotpot.commons.pagination.PageHelper.java
License:Open Source License
/** * Mybatis./*from w ww. j a va 2s . c om*/ * * @param invocation the invocation * @return the object * @throws Throwable the throwable */ @SuppressWarnings("unchecked") @Override 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]; BoundSql boundSql = ms.getBoundSql(parameterObject); //? Page page = getPage(rowBounds); //MappedStatement MappedStatement qs = newMappedStatement(ms, new BoundSqlSqlSource(boundSql)); //?MappedStatement?qs? args[0] = qs; MetaObject msObject = forObject(qs); String sql = (String) msObject.getValue(BOUND_SQL); //?total??count if (page.isCount()) { //count - ?sql msObject.setValue(BOUND_SQL, getCountSql(sql)); // Object result = invocation.proceed(); // page.setTotal((Integer) ((List) result).get(0)); } //?sql - ?sql sql = getSortSql(sql, page); //sql - ?sql msObject.setValue(BOUND_SQL, getPageSql(sql, page)); //?? msObject.setValue("resultMaps", ms.getResultMaps()); // Object result = invocation.proceed(); //? page.addAll((List) result); // return page; // return new PageInfo(page); } }
From source file:com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.java
License:Apache License
public Object queryForObject(final String id, final Object parameterObject) throws SQLException { return transactionManager.doInTransaction(new TransactionScope() { public Object execute(Transaction transaction) throws SQLException { MappedStatement ms = configuration.getMappedStatement(id); Executor executor = transaction.getExecutor(); List list = executor.query(ms, wrapCollection(parameterObject), RowBounds.DEFAULT, null); if (list.size() == 1) { return list.get(0); } else if (list.size() > 1) { throw new SQLException("queryForObject() returned more than one row."); } else { return null; }//from w ww.ja va 2 s. c om } }); }
From source file:com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.java
License:Apache License
public void queryWithRowHandler(final String id, final Object parameterObject, final RowHandler rowHandler) throws SQLException { transactionManager.doInTransaction(new TransactionScope() { public Object execute(Transaction transaction) throws SQLException { MappedStatement ms = configuration.getMappedStatement(id); Executor executor = transaction.getExecutor(); return executor.query(ms, wrapCollection(parameterObject), RowBounds.DEFAULT, new ResultHandler() { public void handleResult(ResultContext context) { rowHandler.handleRow(context.getResultObject()); }// w w w . ja va 2s . c om }); } }); }