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:cn.myblog.uitl.MybatisPageHelper.PageHelper.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (localPage.get() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else {//from ww w. jav a2 s . com //RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; BoundSql boundSql = ms.getBoundSql(parameterObject); //? Page page = localPage.get(); //?? localPage.remove(); if (page == null) { if (offsetAsPageNum) { page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount ? Page.SQL_COUNT : Page.NO_SQL_COUNT); } else { page = new Page(rowBounds, rowBoundsWithCount ? Page.SQL_COUNT : Page.NO_SQL_COUNT); } } MappedStatement qs = newMappedStatement(ms, new BoundSqlSqlSource(boundSql)); //?MappedStatement?qs? args[0] = qs; MetaObject msObject = SystemMetaObject.forObject(qs); String sql = (String) msObject.getValue("sqlSource.boundSql.sql"); //?total??count if (page.getTotal() > Page.NO_SQL_COUNT) { //count - ?sql msObject.setValue("sqlSource.boundSql.sql", getCountSql(sql)); // Object result = invocation.proceed(); int totalCount = (Integer) ((List) result).get(0); page.setTotal(totalCount); int totalPage = totalCount / page.getPageSize() + ((totalCount % page.getPageSize() == 0) ? 0 : 1); page.setPages(totalPage); //sql - ?sql msObject.setValue("sqlSource.boundSql.sql", getPageSql(sql, page)); //?? msObject.setValue("resultMaps", ms.getResultMaps()); // result = invocation.proceed(); //? page.addAll((List) result); // return page; } else { //sql - ?sql msObject.setValue("sqlSource.boundSql.sql", getPageSql(sql, page)); //?? msObject.setValue("resultMaps", ms.getResultMaps()); // Object result = invocation.proceed(); //? page.addAll((List) result); // return page; } } }
From source file:cn.org.awcp.core.mybatis.page.PageHelper.java
License:Open Source License
/** * Mybatis/*from w ww .j ava2 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 (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(ms, parameterObject, boundSql, page); // Object result = invocation.proceed(); //? page.addAll((List) result); } // return page; } }
From source file:com.appleframework.orm.mybatis.pagehelper.SqlUtil.java
License:Open Source License
/** * ??// ww w . jav a 2s . co m * * @param args * @return Page */ public Page getPage(Object[] args) { Page page = getLocalPage(); if (page == null) { 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; } } setLocalPage(page); } //?? if (page.getReasonable() == null) { page.setReasonable(reasonable); } //truepagesize0RowBoundslimit=0? if (page.getPageSizeZero() == null) { page.setPageSizeZero(pageSizeZero); } return page; }
From source file:com.appleframework.orm.mybatis.pagehelper.SqlUtil.java
License:Open Source License
/** * Mybatis/*from www .ja v a 2 s. c o m*/ * * @param invocation ? * @return * @throws Throwable */ private Object _processPage(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); 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.appleframework.orm.mybatis.pagehelper.SqlUtil.java
License:Open Source License
/** * Mybatis// w w w . jav a 2 s . co m * * @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); 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.autonavi.tsp.workbackend.util.page.PageHelper.java
License:Open Source License
/** * Mybatis// ww w. 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 { //?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 = 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.badminton.interceptors.mySqlHelper.pagehelper.util.SqlUtil.java
License:Open Source License
/** * //from w w w . j a v a 2 s.c o m * * @param invocation * @return * @throws Throwable */ public Object doIntercept(Invocation invocation) throws Throwable { //?? Object[] args = invocation.getArgs(); MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; RowBounds rowBounds = (RowBounds) args[2]; List resultList; if (autoDialect) { lock.lock(); try { if (autoDialect) { autoDialect = false; this.dialect = getDialect(ms); } } finally { lock.unlock(); } } Dialect runtimeDialect = dialect; if (autoRuntimeDialect) { runtimeDialect = getDialect(ms); } //???? if (!runtimeDialect.skip(ms, parameterObject, rowBounds)) { ResultHandler resultHandler = (ResultHandler) args[3]; //? Executor executor = (Executor) invocation.getTarget(); BoundSql boundSql = ms.getBoundSql(parameterObject); //????? Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField .get(boundSql); //?? count if (runtimeDialect.beforeCount(ms, parameterObject, rowBounds)) { // count key CacheKey countKey = executor.createCacheKey(ms, parameterObject, RowBounds.DEFAULT, boundSql); countKey.update("_Count"); MappedStatement countMs = msCountMap.get(countKey); if (countMs == null) { //?? ms Long ms countMs = MSUtils.newCountMappedStatement(ms); msCountMap.put(countKey, countMs); } //? count sql String countSql = runtimeDialect.getCountSql(ms, boundSql, parameterObject, rowBounds, countKey); BoundSql countBoundSql = new BoundSql(ms.getConfiguration(), countSql, boundSql.getParameterMappings(), parameterObject); //? SQL ???? BoundSql for (String key : additionalParameters.keySet()) { countBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); } // count Object countResultList = executor.query(countMs, parameterObject, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql); Long count = (Long) ((List) countResultList).get(0); //? runtimeDialect.afterCount(count, parameterObject, rowBounds); if (count == 0L) { // 0 return runtimeDialect.afterPage(new ArrayList(), parameterObject, rowBounds); } } //?? if (runtimeDialect.beforePage(ms, parameterObject, rowBounds)) { //? key CacheKey pageKey = executor.createCacheKey(ms, parameterObject, rowBounds, boundSql); //?? parameterObject = runtimeDialect.processParameterObject(ms, parameterObject, boundSql, pageKey); //? sql String pageSql = runtimeDialect.getPageSql(ms, boundSql, parameterObject, rowBounds, pageKey); BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameterObject); //?? for (String key : additionalParameters.keySet()) { pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); } // resultList = executor.query(ms, parameterObject, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql); } else { resultList = new ArrayList(); } } else { args[2] = RowBounds.DEFAULT; resultList = (List) invocation.proceed(); } // return runtimeDialect.afterPage(resultList, parameterObject, rowBounds); }
From source file:com.baidu.dpop.ctp.common.mybatis.page.PageHelper.java
License:Open Source License
/** * Mybatis//from ww w . ja va2 s . com * * @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 ((page.getPageSizeZero() != null && page.getPageSizeZero()) && 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.baidu.oped.apm.plugin.mybatis.SqlSessionTestBase.java
License:Apache License
protected final void testAndVerifySelect() throws Exception { // Given/*from w ww .j av a2 s . co m*/ final String selectId = "selectId"; SqlSession sqlSession = getSqlSession(); // When sqlSession.select(selectId, new DefaultResultHandler()); sqlSession.select(selectId, new Object(), new DefaultResultHandler()); sqlSession.select(selectId, new Object(), RowBounds.DEFAULT, new DefaultResultHandler()); // Then PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); Method select1 = sqlSession.getClass().getDeclaredMethod("select", String.class, ResultHandler.class); verifier.verifyTrace(event("MYBATIS", select1, Expectations.cachedArgs(selectId))); Method select2 = sqlSession.getClass().getDeclaredMethod("select", String.class, Object.class, ResultHandler.class); verifier.verifyTrace(event("MYBATIS", select2, Expectations.cachedArgs(selectId))); Method select3 = sqlSession.getClass().getDeclaredMethod("select", String.class, Object.class, RowBounds.class, ResultHandler.class); verifier.verifyTrace(event("MYBATIS", select3, Expectations.cachedArgs(selectId))); }
From source file:com.baidu.oped.apm.plugin.mybatis.SqlSessionTestBase.java
License:Apache License
protected final void testAndVerifySelectList() throws Exception { // Given//from www .ja v a 2 s .c o m final String selectListId = "selectListId"; SqlSession sqlSession = getSqlSession(); // When sqlSession.selectList(selectListId); sqlSession.selectList(selectListId, new Object()); sqlSession.selectList(selectListId, new Object(), RowBounds.DEFAULT); // Then PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); Method selectList1 = sqlSession.getClass().getDeclaredMethod("selectList", String.class); Method selectList2 = sqlSession.getClass().getDeclaredMethod("selectList", String.class, Object.class); Method selectList3 = sqlSession.getClass().getDeclaredMethod("selectList", String.class, Object.class, RowBounds.class); verifier.verifyTrace(event("MYBATIS", selectList1, Expectations.cachedArgs(selectListId))); verifier.verifyTrace(event("MYBATIS", selectList2, Expectations.cachedArgs(selectListId))); verifier.verifyTrace(event("MYBATIS", selectList3, Expectations.cachedArgs(selectListId))); }