org.apache.ibatis.cache.CacheKey Java Examples
The following examples show how to use
org.apache.ibatis.cache.CacheKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: sqlhelper Author: fangjinuo File: ExecutorInvocation.java License: GNU Lesser General Public License v3.0 | 6 votes |
/** * lazy parse bound sql */ private BoundSql parseBoundSql() { if (Objects.isNull(boundSql)) { Object[] args = invocation.getArgs(); if (this.methodName.equals("query")) { if (args.length > 4) { this.cacheKey = (CacheKey) args[4]; this.boundSql = (BoundSql) args[5]; } } if (Objects.isNull(this.boundSql)) { this.boundSql = this.mappedStatement.getBoundSql(parameter); } if (this.methodName.equals("query")) { if (Objects.isNull(cacheKey)) { this.cacheKey = this.executor.createCacheKey(mappedStatement, parameter, rowBounds, boundSql); } } } return this.boundSql; }
Example #2
Source Project: Mybatis-PageHelper Author: pagehelper File: HerdDBRowBoundsDialect.java License: MIT License | 6 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14); sqlBuilder.append(sql); if (rowBounds.getOffset() == 0) { sqlBuilder.append(" LIMIT "); sqlBuilder.append(rowBounds.getLimit()); } else { sqlBuilder.append(" LIMIT "); sqlBuilder.append(rowBounds.getOffset()); sqlBuilder.append(","); sqlBuilder.append(rowBounds.getLimit()); pageKey.update(rowBounds.getOffset()); } pageKey.update(rowBounds.getLimit()); return sqlBuilder.toString(); }
Example #3
Source Project: azeroth Author: warlock-china File: PaginationHandler.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") private Long executeQueryCount(Executor executor, MappedStatement countMs, Object parameter, BoundSql boundSql, RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException { CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql); String orignSql = boundSql.getSql().replaceAll(";$", ""); // count sql String countSql = PageSqlUtils.getCountSql(orignSql); BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(), parameter); // 执行 count 查询 Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql); Long count = (Long) ((List) countResultList).get(0); return count; }
Example #4
Source Project: jeesuite-libs Author: vakinge File: PaginationHandler.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") private Long executeQueryCount(Executor executor, MappedStatement countMs, Object parameter, BoundSql boundSql, RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException { CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql); String orignSql = StringUtils.replace(boundSql.getSql(), ";$", StringUtils.EMPTY); // count sql String countSql = PageSqlUtils.getCountSql(orignSql); BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(), parameter); // for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) { // String propertyName = parameterMapping.getProperty(); // if(boundSql.hasAdditionalParameter(propertyName)){ // countBoundSql.setAdditionalParameter(propertyName, boundSql.getAdditionalParameter(propertyName)); // } // } // 执行 count 查询 Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql); Long count = (Long) ((List) countResultList).get(0); return count; }
Example #5
Source Project: jeesuite-libs Author: vakinge File: PaginationHandler.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") private List executeQuery(Executor executor, MappedStatement ms, Object parameter, BoundSql boundSql, RowBounds rowBounds, ResultHandler resultHandler,PageParams pageParams) throws IllegalAccessException, SQLException { CacheKey countKey = executor.createCacheKey(ms, parameter, RowBounds.DEFAULT, boundSql); String orignSql = StringUtils.replace(boundSql.getSql(), ";$", StringUtils.EMPTY); String pageSql = PageSqlUtils.getLimitSQL(dbType,orignSql,pageParams); BoundSql countBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameter); List<?> resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql); return resultList; }
Example #6
Source Project: mybaties Author: shurun19851206 File: BaseExecutor.java License: Apache License 2.0 | 6 votes |
private void handleLocallyCachedOutputParameters(MappedStatement ms, CacheKey key, Object parameter, BoundSql boundSql) { //处理存储过程的OUT参数 if (ms.getStatementType() == StatementType.CALLABLE) { final Object cachedParameter = localOutputParameterCache.getObject(key); if (cachedParameter != null && parameter != null) { final MetaObject metaCachedParameter = configuration.newMetaObject(cachedParameter); final MetaObject metaParameter = configuration.newMetaObject(parameter); for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) { if (parameterMapping.getMode() != ParameterMode.IN) { final String parameterName = parameterMapping.getProperty(); final Object cachedValue = metaCachedParameter.getValue(parameterName); metaParameter.setValue(parameterName, cachedValue); } } } } }
Example #7
Source Project: mybaties Author: shurun19851206 File: BaseExecutor.java License: Apache License 2.0 | 6 votes |
private <E> List<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException { List<E> list; //先向缓存中放入占位符??? localCache.putObject(key, EXECUTION_PLACEHOLDER); try { list = doQuery(ms, parameter, rowBounds, resultHandler, boundSql); } finally { //最后删除占位符 localCache.removeObject(key); } //加入缓存 localCache.putObject(key, list); //如果是存储过程,OUT参数也加入缓存 if (ms.getStatementType() == StatementType.CALLABLE) { localOutputParameterCache.putObject(key, parameter); } return list; }
Example #8
Source Project: Mybatis-PageHelper Author: pagehelper File: MySqlRowBoundsDialect.java License: MIT License | 6 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14); sqlBuilder.append(sql); if (rowBounds.getOffset() == 0) { sqlBuilder.append(" LIMIT "); sqlBuilder.append(rowBounds.getLimit()); } else { sqlBuilder.append(" LIMIT "); sqlBuilder.append(rowBounds.getOffset()); sqlBuilder.append(","); sqlBuilder.append(rowBounds.getLimit()); pageKey.update(rowBounds.getOffset()); } pageKey.update(rowBounds.getLimit()); return sqlBuilder.toString(); }
Example #9
Source Project: mybaties Author: shurun19851206 File: DefaultResultSetHandler.java License: Apache License 2.0 | 6 votes |
private void linkToParents(ResultSet rs, ResultMapping parentMapping, Object rowValue) throws SQLException { CacheKey parentKey = createKeyForMultipleResults(rs, parentMapping, parentMapping.getColumn(), parentMapping.getForeignColumn()); List<PendingRelation> parents = pendingRelations.get(parentKey); if (parents != null) { for (PendingRelation parent : parents) { if (parent != null) { final Object collectionProperty = instantiateCollectionPropertyIfAppropriate(parent.propertyMapping, parent.metaObject); if (rowValue != null) { if (collectionProperty != null) { final MetaObject targetMetaObject = configuration.newMetaObject(collectionProperty); targetMetaObject.add(rowValue); } else { parent.metaObject.setValue(parent.propertyMapping.getProperty(), rowValue); } } } } } }
Example #10
Source Project: Mybatis-PageHelper Author: pagehelper File: ExecutorUtil.java License: MIT License | 6 votes |
/** * 执行自动生成的 count 查询 * * @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; }
Example #11
Source Project: mybaties Author: shurun19851206 File: DefaultResultSetHandler.java License: Apache License 2.0 | 6 votes |
private CacheKey createKeyForMultipleResults(ResultSet rs, ResultMapping resultMapping, String names, String columns) throws SQLException { CacheKey cacheKey = new CacheKey(); cacheKey.update(resultMapping); if (columns != null && names != null) { String[] columnsArray = columns.split(","); String[] namesArray = names.split(","); for (int i = 0 ; i < columnsArray.length ; i++) { Object value = rs.getString(columnsArray[i]); if (value != null) { cacheKey.update(namesArray[i]); cacheKey.update(value); } } } return cacheKey; }
Example #12
Source Project: mybaties Author: shurun19851206 File: DefaultResultSetHandler.java License: Apache License 2.0 | 6 votes |
private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap resultMap, ResultHandler resultHandler, RowBounds rowBounds, ResultMapping parentMapping) throws SQLException { final DefaultResultContext resultContext = new DefaultResultContext(); skipRows(rsw.getResultSet(), rowBounds); Object rowValue = null; while (shouldProcessMoreRows(resultContext, rowBounds) && rsw.getResultSet().next()) { final ResultMap discriminatedResultMap = resolveDiscriminatedResultMap(rsw.getResultSet(), resultMap, null); final CacheKey rowKey = createRowKey(discriminatedResultMap, rsw, null); Object partialObject = nestedResultObjects.get(rowKey); // issue #577 && #542 if (mappedStatement.isResultOrdered()) { if (partialObject == null && rowValue != null) { nestedResultObjects.clear(); storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet()); } rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, rowKey, null, partialObject); } else { rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, rowKey, null, partialObject); if (partialObject == null) { storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet()); } } } if (rowValue != null && mappedStatement.isResultOrdered() && shouldProcessMoreRows(resultContext, rowBounds)) { storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet()); } }
Example #13
Source Project: mybaties Author: shurun19851206 File: DefaultResultSetHandler.java License: Apache License 2.0 | 6 votes |
private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey, List<ResultMapping> resultMappings, String columnPrefix) throws SQLException { for (ResultMapping resultMapping : resultMappings) { if (resultMapping.getNestedResultMapId() != null && resultMapping.getResultSet() == null) { // Issue #392 final ResultMap nestedResultMap = configuration.getResultMap(resultMapping.getNestedResultMapId()); createRowKeyForMappedProperties(nestedResultMap, rsw, cacheKey, nestedResultMap.getConstructorResultMappings(), prependPrefix(resultMapping.getColumnPrefix(), columnPrefix)); } else if (resultMapping.getNestedQueryId() == null) { final String column = prependPrefix(resultMapping.getColumn(), columnPrefix); final TypeHandler<?> th = resultMapping.getTypeHandler(); List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix); // Issue #114 if (column != null && mappedColumnNames.contains(column.toUpperCase(Locale.ENGLISH))) { final Object value = th.getResult(rsw.getResultSet(), column); if (value != null) { cacheKey.update(column); cacheKey.update(value); } } } } }
Example #14
Source Project: mybaties Author: shurun19851206 File: CachingExecutor.java License: Apache License 2.0 | 6 votes |
@Override public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException { Cache cache = ms.getCache(); //默认情况下是没有开启缓存的(二级缓存).要开启二级缓存,你需要在你的 SQL 映射文件中添加一行: <cache/> //简单的说,就是先查CacheKey,查不到再委托给实际的执行器去查 if (cache != null) { flushCacheIfRequired(ms); if (ms.isUseCache() && resultHandler == null) { ensureNoOutParams(ms, parameterObject, boundSql); @SuppressWarnings("unchecked") List<E> list = (List<E>) tcm.getObject(cache, key); if (list == null) { list = delegate.<E> query(ms, parameterObject, rowBounds, resultHandler, key, boundSql); tcm.putObject(cache, key, list); // issue #578 and #116 } return list; } } return delegate.<E> query(ms, parameterObject, rowBounds, resultHandler, key, boundSql); }
Example #15
Source Project: Mybatis-PageHelper Author: pagehelper File: SqlServerDialect.java License: MIT License | 6 votes |
@Override public String getPageSql(String sql, Page page, CacheKey pageKey) { //处理pageKey pageKey.update(page.getStartRow()); pageKey.update(page.getPageSize()); String cacheSql = CACHE_PAGESQL.get(sql); if (cacheSql == null) { cacheSql = sql; cacheSql = replaceSql.replace(cacheSql); cacheSql = pageSql.convertToPageSql(cacheSql, null, null); cacheSql = replaceSql.restore(cacheSql); CACHE_PAGESQL.put(sql, cacheSql); } cacheSql = cacheSql.replace(String.valueOf(Long.MIN_VALUE), String.valueOf(page.getStartRow())); cacheSql = cacheSql.replace(String.valueOf(Long.MAX_VALUE), String.valueOf(page.getPageSize())); return cacheSql; }
Example #16
Source Project: QuickProject Author: chanedi File: SortListInterceptor.java License: Apache License 2.0 | 6 votes |
@Override public Object intercept(Invocation invocation) throws Throwable { List<Sort> sortList = getSortList(); if (sortList == null || sortList.size() == 0) { return invocation.proceed(); } Executor executor = (Executor) invocation.getTarget(); Object[] args = invocation.getArgs(); MappedStatement ms = (MappedStatement) args[0]; Object parameter = args[1]; RowBounds rowBounds = (RowBounds) args[2]; ResultHandler resultHandler = (ResultHandler) args[3]; // 计算修改BoundSql BoundSql boundSql = ms.getBoundSql(parameter); MetaObject boundSqlHandler = MetaObject.forObject(boundSql, new DefaultObjectFactory(), new DefaultObjectWrapperFactory()); Dialect dialect = DialectParser.parse(ms.getConfiguration()); String sql = (String) boundSqlHandler.getValue("sql"); sql = dialect.addSortString(sql, sortList); boundSqlHandler.setValue("sql", sql); // 继续执行原来的代码 CacheKey key = executor.createCacheKey(ms, parameter, rowBounds, boundSql); return executor.query(ms, parameter, rowBounds, resultHandler, key, boundSql); }
Example #17
Source Project: mybatis Author: tuguangquan File: BaseExecutor.java License: Apache License 2.0 | 6 votes |
private <E> List<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException { List<E> list; //先向缓存中放入占位符??? localCache.putObject(key, EXECUTION_PLACEHOLDER); try { list = doQuery(ms, parameter, rowBounds, resultHandler, boundSql); } finally { //最后删除占位符 localCache.removeObject(key); } //加入缓存 localCache.putObject(key, list); //如果是存储过程,OUT参数也加入缓存 if (ms.getStatementType() == StatementType.CALLABLE) { localOutputParameterCache.putObject(key, parameter); } return list; }
Example #18
Source Project: mybatis Author: tuguangquan File: DefaultResultSetHandler.java License: Apache License 2.0 | 6 votes |
private void linkToParents(ResultSet rs, ResultMapping parentMapping, Object rowValue) throws SQLException { CacheKey parentKey = createKeyForMultipleResults(rs, parentMapping, parentMapping.getColumn(), parentMapping.getForeignColumn()); List<PendingRelation> parents = pendingRelations.get(parentKey); for (PendingRelation parent : parents) { if (parent != null) { final Object collectionProperty = instantiateCollectionPropertyIfAppropriate(parent.propertyMapping, parent.metaObject); if (rowValue != null) { if (collectionProperty != null) { final MetaObject targetMetaObject = configuration.newMetaObject(collectionProperty); targetMetaObject.add(rowValue); } else { parent.metaObject.setValue(parent.propertyMapping.getProperty(), rowValue); } } } } }
Example #19
Source Project: Mybatis-PageHelper Author: pagehelper File: HsqldbRowBoundsDialect.java License: MIT License | 6 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 20); sqlBuilder.append(sql); if (rowBounds.getLimit() > 0) { sqlBuilder.append(" LIMIT "); sqlBuilder.append(rowBounds.getLimit()); pageKey.update(rowBounds.getLimit()); } if (rowBounds.getOffset() > 0) { sqlBuilder.append(" OFFSET "); sqlBuilder.append(rowBounds.getOffset()); pageKey.update(rowBounds.getOffset()); } return sqlBuilder.toString(); }
Example #20
Source Project: Mybatis-PageHelper Author: pagehelper File: MySqlDialect.java License: MIT License | 6 votes |
@Override public Object processPageParameter(MappedStatement ms, Map<String, Object> paramMap, Page page, BoundSql boundSql, CacheKey pageKey) { paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow()); paramMap.put(PAGEPARAMETER_SECOND, page.getPageSize()); //处理pageKey pageKey.update(page.getStartRow()); pageKey.update(page.getPageSize()); //处理参数配置 if (boundSql.getParameterMappings() != null) { List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>(boundSql.getParameterMappings()); if (page.getStartRow() == 0) { newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build()); } else { newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build()); newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build()); } MetaObject metaObject = MetaObjectUtil.forObject(boundSql); metaObject.setValue("parameterMappings", newParameterMappings); } return paramMap; }
Example #21
Source Project: Mybatis-PageHelper Author: pagehelper File: OracleRowBoundsDialect.java License: MIT License | 6 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { int startRow = rowBounds.getOffset(); int endRow = rowBounds.getOffset() + rowBounds.getLimit(); StringBuilder sqlBuilder = new StringBuilder(sql.length() + 120); if (startRow > 0) { sqlBuilder.append("SELECT * FROM ( "); } if (endRow > 0) { sqlBuilder.append(" SELECT TMP_PAGE.*, ROWNUM ROW_ID FROM ( "); } sqlBuilder.append(sql); if (endRow > 0) { sqlBuilder.append(" ) TMP_PAGE WHERE ROWNUM <= "); sqlBuilder.append(endRow); pageKey.update(endRow); } if (startRow > 0) { sqlBuilder.append(" ) WHERE ROW_ID > "); sqlBuilder.append(startRow); pageKey.update(startRow); } return sqlBuilder.toString(); }
Example #22
Source Project: mybatis Author: tuguangquan File: DefaultResultSetHandler.java License: Apache License 2.0 | 6 votes |
private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey, List<ResultMapping> resultMappings, String columnPrefix) throws SQLException { for (ResultMapping resultMapping : resultMappings) { if (resultMapping.getNestedResultMapId() != null && resultMapping.getResultSet() == null) { // Issue #392 final ResultMap nestedResultMap = configuration.getResultMap(resultMapping.getNestedResultMapId()); createRowKeyForMappedProperties(nestedResultMap, rsw, cacheKey, nestedResultMap.getConstructorResultMappings(), prependPrefix(resultMapping.getColumnPrefix(), columnPrefix)); } else if (resultMapping.getNestedQueryId() == null) { final String column = prependPrefix(resultMapping.getColumn(), columnPrefix); final TypeHandler<?> th = resultMapping.getTypeHandler(); List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix); // Issue #114 if (column != null && mappedColumnNames.contains(column.toUpperCase(Locale.ENGLISH))) { final Object value = th.getResult(rsw.getResultSet(), column); if (value != null) { cacheKey.update(column); cacheKey.update(value); } } } } }
Example #23
Source Project: Mybatis-PageHelper Author: pagehelper File: InformixDialect.java License: MIT License | 6 votes |
@Override public Object processPageParameter(MappedStatement ms, Map<String, Object> paramMap, Page page, BoundSql boundSql, CacheKey pageKey) { paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow()); paramMap.put(PAGEPARAMETER_SECOND, page.getPageSize()); //处理pageKey pageKey.update(page.getStartRow()); pageKey.update(page.getPageSize()); //处理参数配置 if (boundSql.getParameterMappings() != null) { List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>(); if (page.getStartRow() > 0) { newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build()); } if (page.getPageSize() > 0) { newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build()); } newParameterMappings.addAll(boundSql.getParameterMappings()); MetaObject metaObject = MetaObjectUtil.forObject(boundSql); metaObject.setValue("parameterMappings", newParameterMappings); } return paramMap; }
Example #24
Source Project: sqlhelper Author: fangjinuo File: PaginationHandler.java License: GNU Lesser General Public License v3.0 | 5 votes |
private Object executeOrderBy(OrderBy orderBy, final MappedStatement ms, final Object parameter, final RowBounds rowBounds, final ResultHandler resultHandler, final Executor executor, final BoundSql boundSql) throws Throwable { SQLStatementInstrumentor instrumentor = SqlHelperMybatisPlugin.getInstrumentor(); String orderBySqlId = getOrderById(ms, orderBy); MappedStatement orderByStatement = this.customOrderByStatement(ms, orderBySqlId); final CacheKey orderByCacheKey = executor.createCacheKey(orderByStatement, parameter, RowBounds.DEFAULT, boundSql); final String orderBySql = instrumentor.instrumentOrderBySql(boundSql.getSql(), orderBy); BoundSql orderByBoundSql = MybatisUtils.rebuildBoundSql(orderBySql, orderByStatement.getConfiguration(), boundSql); return executor.query(orderByStatement, parameter, RowBounds.DEFAULT, resultHandler, orderByCacheKey, orderByBoundSql); }
Example #25
Source Project: nexus-public Author: sonatype File: EntityExecutor.java License: Eclipse Public License 1.0 | 5 votes |
@Override public <E> List<E> query(final MappedStatement ms, final Object parameter, final RowBounds rowBounds, final ResultHandler resultHandler, final CacheKey cacheKey, final BoundSql boundSql) throws SQLException { return delegate.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql); }
Example #26
Source Project: nexus-public Author: sonatype File: EntityExecutor.java License: Eclipse Public License 1.0 | 5 votes |
@Override public CacheKey createCacheKey(final MappedStatement ms, final Object parameterObject, final RowBounds rowBounds, final BoundSql boundSql) { return delegate.createCacheKey(ms, parameterObject, rowBounds, boundSql); }
Example #27
Source Project: Mybatis-PageHelper Author: pagehelper File: AbstractHelperDialect.java License: MIT License | 5 votes |
@Override public String getPageSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey pageKey) { String sql = boundSql.getSql(); Page page = getLocalPage(); //支持 order by String orderBy = page.getOrderBy(); if (StringUtil.isNotEmpty(orderBy)) { pageKey.update(orderBy); sql = OrderByParser.converToOrderBySql(sql, orderBy); } if (page.isOrderByOnly()) { return sql; } return getPageSql(sql, page, pageKey); }
Example #28
Source Project: cacheonix-core Author: cacheonix File: MyBatisCacheTestDriver.java License: GNU Lesser General Public License v2.1 | 5 votes |
public void testClear() { final CacheKey cacheKey = createKey(); myBatisCache.putObject(cacheKey, TEST_VALUE); myBatisCache.clear(); assertEquals(0, myBatisCache.getSize()); }
Example #29
Source Project: Mybatis-PageHelper Author: pagehelper File: SqlServer2012Dialect.java License: MIT License | 5 votes |
@Override public Object processPageParameter(MappedStatement ms, Map<String, Object> paramMap, Page page, BoundSql boundSql, CacheKey pageKey) { paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow()); paramMap.put(PAGEPARAMETER_SECOND, page.getPageSize()); //处理pageKey pageKey.update(page.getStartRow()); pageKey.update(page.getPageSize()); //处理参数配置 handleParameter(boundSql, ms); return paramMap; }
Example #30
Source Project: Mybatis-PageHelper Author: pagehelper File: Db2RowBoundsDialect.java License: MIT License | 5 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { int startRow = rowBounds.getOffset() + 1; int endRow = rowBounds.getOffset() + rowBounds.getLimit(); StringBuilder sqlBuilder = new StringBuilder(sql.length() + 120); sqlBuilder.append("SELECT * FROM (SELECT TMP_PAGE.*,ROWNUMBER() OVER() AS ROW_ID FROM ( "); sqlBuilder.append(sql); sqlBuilder.append(" ) AS TMP_PAGE) TMP_PAGE WHERE ROW_ID BETWEEN "); sqlBuilder.append(startRow); sqlBuilder.append(" AND "); sqlBuilder.append(endRow); pageKey.update(startRow); pageKey.update(endRow); return sqlBuilder.toString(); }