List of usage examples for org.apache.ibatis.executor Executor createCacheKey
CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql);
From source file:com.badminton.interceptors.mySqlHelper.pagehelper.util.SqlUtil.java
License:Open Source License
/** * /*from w ww. j a va 2s. co 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.github.ibole.infrastructure.persistence.db.mybatis.pagination.PaginationInterceptor.java
License:Apache License
private Integer getCount(String sql, Executor executor, MappedStatement ms, RowBounds rowBounds, BoundSql boundSql, Object parameter, Dialect dialect) throws SQLException { Integer count = 0;//from w ww.j a v a 2 s .c o m Cache cache = ms.getCache(); if (cache != null && ms.isUseCache() && ms.getConfiguration().isCacheEnabled()) { CacheKey cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql); count = (Integer) cache.getObject(cacheKey); if (count == null) { count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect); cache.putObject(cacheKey, count); } } else { count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect); } return count; }
From source file:com.github.pagehelper.PageInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { try {//from ww w . java2s .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.QueryInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { Object[] args = invocation.getArgs(); MappedStatement ms = (MappedStatement) args[0]; Object parameter = args[1];//from w w w. ja v a2 s. c o m 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]; } //TODO ???? //????count page ? return executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql); }
From source file:com.github.pagehelper.util.ExecutorUtil.java
License:Open Source License
/** * count ???//from w w w . j a v a 2 s . c om * * @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 /* w w w . j av 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.sinotopia.mybatis.pagehelper.PageInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { try {/*from w ww . j a v a2 s . c o m*/ 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 2s . c om * * @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 //from www . j av a 2 s. 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; }