List of usage examples for org.apache.ibatis.builder SqlSourceBuilder parse
public SqlSource parse(String originalSql, Class<?> parameterType, Map<String, Object> additionalParameters)
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);//w ww .ja v a2s.co m 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);//ww w.j a v a 2s .c om 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 . ja v a2 s . c om*/ 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/* w ww .j a va 2 s. co m*/ 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.icfcc.db.pagehelper.sqlsource.PageDynamicSqlSource.java
License:Open Source License
@Override protected BoundSql getCountBoundSql(Object parameterObject) { DynamicContext context = new DynamicContext(configuration, parameterObject); rootSqlNode.apply(context);//from ww w .j a v a2 s .c om 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, parser.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.icfcc.db.pagehelper.sqlsource.PageDynamicSqlSource.java
License:Open Source License
@Override protected BoundSql getPageBoundSql(Object parameterObject) { DynamicContext context;//from w ww. ja v a 2 s . c o m //??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, parser.getPageSql(boundSql.getSql()), parser.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.linju.framework.pager.sqlsource.PageDynamicSqlSource.java
License:Open Source License
public BoundSql getBoundSql(Object parameterObject) { DynamicContext context;//from ww w. j a v a2 s . c o m //??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()); if (count) { sqlSource = msUtils.getStaticCountSqlSource(configuration, sqlSource, parameterObject); } else { sqlSource = msUtils.getStaticPageSqlSource(configuration, sqlSource, parameterObject); } 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:jetbrick.template.scripting.JetxSqlSource.java
License:Apache License
@Override public BoundSql getBoundSql(Object parameterObject) { Map<String, Object> context = (Map<String, Object>) parameterObject; if (parameterObject == null) { context = Collections.EMPTY_MAP; }//from ww w . jav a 2s . c o m StringWriter out = new StringWriter(); template.render(context, out); String sql = out.toString(); // Pass retrieved SQL into MyBatis engine, it will substitute prepared-statements parameters SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType1 = parameterObject == null ? Object.class : parameterObject.getClass(); SqlSource sqlSource = sqlSourceParser.parse(sql, parameterType1, Collections.EMPTY_MAP); return sqlSource.getBoundSql(parameterObject); }
From source file:org.fire.platform.common.page.sqlsource.PageDynamicSqlSource.java
License:Open Source License
@SuppressWarnings("rawtypes") public BoundSql getBoundSql(Object parameterObject) { DynamicContext context;// w w w . j av a 2 s . c o m //??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()); if (count) { sqlSource = msUtils.getStaticCountSqlSource(configuration, sqlSource, parameterObject); } else { sqlSource = msUtils.getStaticPageSqlSource(configuration, sqlSource, parameterObject); } 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:org.mybatis.scripting.freemarker.FreeMarkerSqlSource.java
License:Apache License
@Override public BoundSql getBoundSql(Object parameterObject) { // Add to passed parameterObject our predefined directive - MyBatisParamDirective // It will be available as "p" inside templates Object dataContext;/*from w w w.ja v a2 s . com*/ ArrayList generatedParams = new ArrayList<>(); if (parameterObject != null) { if (parameterObject instanceof Map) { HashMap<String, Object> map = new HashMap<>((Map<String, Object>) parameterObject); map.put(GENERATED_PARAMS_KEY, generatedParams); dataContext = preProcessDataContext(map, true); } else { ParamObjectAdapter adapter = new ParamObjectAdapter(parameterObject, generatedParams); dataContext = preProcessDataContext(adapter, false); } } else { HashMap<Object, Object> map = new HashMap<>(); map.put(GENERATED_PARAMS_KEY, generatedParams); dataContext = preProcessDataContext(map, true); } CharArrayWriter writer = new CharArrayWriter(); try { template.process(dataContext, writer); } catch (TemplateException | IOException e) { throw new RuntimeException(e); } // We got SQL ready for MyBatis here. This SQL contains // params declarations like "#{param}", // they will be replaced to '?' by MyBatis engine further String sql = writer.toString(); if (!generatedParams.isEmpty()) { if (!(parameterObject instanceof Map)) { throw new UnsupportedOperationException("Auto-generated prepared statements parameters" + " are not available if using parameters object. Use @Param-annotated parameters" + " instead."); } Map<String, Object> parametersMap = (Map<String, Object>) parameterObject; for (int i = 0; i < generatedParams.size(); i++) { parametersMap.put("_p" + i, generatedParams.get(i)); } } // Pass retrieved SQL into MyBatis engine, it will substitute prepared-statements parameters SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType1 = parameterObject == null ? Object.class : parameterObject.getClass(); SqlSource sqlSource = sqlSourceParser.parse(sql, parameterType1, new HashMap<String, Object>()); return sqlSource.getBoundSql(parameterObject); }