List of usage examples for org.apache.ibatis.mapping BoundSql setAdditionalParameter
public void setAdditionalParameter(String name, Object value)
From source file:cn.com.bricks.mybatis.rbac.DynamicRbacInterceptor.java
protected BoundSql getBoundSql(Configuration configuration, Object parameterObject, SqlNode sqlNode) throws SQLException { DynamicContext context = new DynamicContext(configuration, parameterObject); sqlNode.apply(context);//from w w w. j a va 2s.com String countextSql = context.getSql(); // ? SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); String sql = modifySqlAddUserRole(countextSql, parameterObject); SqlSource sqlSource = sqlSourceParser.parse(sql, parameterType, context.getBindings()); BoundSql boundSql = sqlSource.getBoundSql(parameterObject); for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) { boundSql.setAdditionalParameter(entry.getKey(), entry.getValue()); } return boundSql; }
From source file:com.appleframework.orm.mybatis.pagehelper.sqlsource.PageDynamicSqlSource.java
License:Open Source License
@Override protected BoundSql getDefaultBoundSql(Object parameterObject) { DynamicContext context = new DynamicContext(configuration, parameterObject); rootSqlNode.apply(context);/* w w w. ja v a2 s . c o m*/ SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings()); sqlSource = new OrderByStaticSqlSource((StaticSqlSource) sqlSource); BoundSql boundSql = sqlSource.getBoundSql(parameterObject); //?? for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) { boundSql.setAdditionalParameter(entry.getKey(), entry.getValue()); } return boundSql; }
From source file:com.appleframework.orm.mybatis.pagehelper.sqlsource.PageDynamicSqlSource.java
License:Open Source License
@Override protected BoundSql getCountBoundSql(Object parameterObject) { DynamicContext context = new DynamicContext(configuration, parameterObject); rootSqlNode.apply(context);/*from w w w . j ava 2 s .c o m*/ SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings()); BoundSql boundSql = sqlSource.getBoundSql(parameterObject); sqlSource = new StaticSqlSource(configuration, localParser.get().getCountSql(boundSql.getSql()), boundSql.getParameterMappings()); boundSql = sqlSource.getBoundSql(parameterObject); //?? for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) { boundSql.setAdditionalParameter(entry.getKey(), entry.getValue()); } return boundSql; }
From source file:com.appleframework.orm.mybatis.pagehelper.sqlsource.PageDynamicSqlSource.java
License:Open Source License
@SuppressWarnings("rawtypes") @Override/*from ww w . ja v a 2 s .com*/ protected BoundSql getPageBoundSql(Object parameterObject) { DynamicContext context; //??parameterObject??? //??Map?KEY //bug#25:http://git.oschina.net/free/Mybatis_PageHelper/issues/25 if (parameterObject != null && parameterObject instanceof Map && ((Map) parameterObject).containsKey(ORIGINAL_PARAMETER_OBJECT)) { context = new DynamicContext(configuration, ((Map) parameterObject).get(ORIGINAL_PARAMETER_OBJECT)); } else { context = new DynamicContext(configuration, parameterObject); } rootSqlNode.apply(context); SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings()); sqlSource = new OrderByStaticSqlSource((StaticSqlSource) sqlSource); BoundSql boundSql = sqlSource.getBoundSql(parameterObject); sqlSource = new StaticSqlSource(configuration, localParser.get().getPageSql(boundSql.getSql()), localParser.get().getPageParameterMapping(configuration, boundSql)); boundSql = sqlSource.getBoundSql(parameterObject); //?? for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) { boundSql.setAdditionalParameter(entry.getKey(), entry.getValue()); } return boundSql; }
From source file:com.badminton.interceptors.mySqlHelper.pagehelper.util.SqlUtil.java
License:Open Source License
/** * //from w w w .j a v a 2s. 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.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor.java
License:Apache License
@SuppressWarnings("unchecked") private void changSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, LockerCache lockerCache) throws Exception { Field versionField = lockerCache.field; String versionColumn = lockerCache.column; final Object versionValue = versionField.get(parameterObject); if (versionValue != null) {// ???version,? Configuration configuration = ms.getConfiguration(); // //w w w . j av a2s . c om lockerCache.versionHandler.plusVersion(parameterObject, versionField, versionValue); // ?where?,? Update jsqlSql = (Update) CCJSqlParserUtil.parse(boundSql.getSql()); BinaryExpression expression = (BinaryExpression) jsqlSql.getWhere(); if (expression != null && !expression.toString().contains(versionColumn)) { EqualsTo equalsTo = new EqualsTo(); equalsTo.setLeftExpression(new Column(versionColumn)); equalsTo.setRightExpression(RIGHT_EXPRESSION); jsqlSql.setWhere(new AndExpression(equalsTo, expression)); List<ParameterMapping> parameterMappings = new LinkedList<>(boundSql.getParameterMappings()); parameterMappings.add(jsqlSql.getExpressions().size(), getVersionMappingInstance(configuration)); MetaObject boundSqlMeta = configuration.newMetaObject(boundSql); boundSqlMeta.setValue("sql", jsqlSql.toString()); boundSqlMeta.setValue("parameterMappings", parameterMappings); } // ? boundSql.setAdditionalParameter("originVersionValue", versionValue); } }
From source file:com.bsb.cms.commons.page.interceptor.PaginationInterceptor.java
License:Open Source License
/** * ?BoundSql/*w ww. j a v a 2s . c om*/ */ private BoundSql copyFromBoundSql(MappedStatement ms, BoundSql boundSql, String sql) { BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(), boundSql.getParameterObject()); for (ParameterMapping mapping : boundSql.getParameterMappings()) { String prop = mapping.getProperty(); if (boundSql.hasAdditionalParameter(prop)) { newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop)); } } return newBoundSql; }
From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PaginationInterceptor.java
License:Apache License
private BoundSql copyFromBoundSql(MappedStatement ms, BoundSql boundSql, String sql) { BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(), boundSql.getParameterObject()); for (ParameterMapping mapping : boundSql.getParameterMappings()) { String prop = mapping.getProperty(); if (boundSql.hasAdditionalParameter(prop)) { newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop)); }/*from w w w .j a v a2 s. co m*/ } return newBoundSql; }
From source file:com.github.pagehelper.PageInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { try {/*from w w w . ja 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)) { //????? 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 va 2 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; }