List of usage examples for org.apache.ibatis.builder StaticSqlSource StaticSqlSource
public StaticSqlSource(Configuration configuration, String sql, List<ParameterMapping> parameterMappings)
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 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()); 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// ww w.j av a2 s.c o 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.autonavi.tsp.workbackend.util.page.SqlUtil.java
License:Open Source License
/** * ?sqlSource// w w w.j av a 2 s. c om * * @param configuration * @param sqlSource * @return */ private SqlSource getPageSqlSource(Configuration configuration, SqlSource sqlSource, Object parameterObject) { BoundSql boundSql = sqlSource.getBoundSql(parameterObject); return new StaticSqlSource(configuration, sqlParser.getPageSql(boundSql.getSql()), getPageParameterMapping(configuration, boundSql)); }
From source file:com.autonavi.tsp.workbackend.util.page.SqlUtil.java
License:Open Source License
/** * ?countsqlSource/*from w w w . j a v a 2 s.c o m*/ * * @param sqlSource * @return */ private SqlSource getCountSqlSource(Configuration configuration, SqlSource sqlSource, Object parameterObject) { BoundSql boundSql = sqlSource.getBoundSql(parameterObject); return new StaticSqlSource(configuration, sqlParser.getCountSql(boundSql.getSql()), boundSql.getParameterMappings()); }
From source file:com.baomidou.mybatisplus.plugins.SqlExplainInterceptor.java
License:Apache License
/** * <p>/*from w w w.ja va 2 s.co m*/ * ? SQL * </p> * * @param configuration * @param mappedStatement * @param boundSql * @param connection * @param parameter * @return * @throws Exception */ protected void sqlExplain(Configuration configuration, MappedStatement mappedStatement, BoundSql boundSql, Connection connection, Object parameter) { StringBuilder explain = new StringBuilder("EXPLAIN "); explain.append(boundSql.getSql()); String sqlExplain = explain.toString(); StaticSqlSource sqlsource = new StaticSqlSource(configuration, sqlExplain, boundSql.getParameterMappings()); MappedStatement.Builder builder = new MappedStatement.Builder(configuration, "explain_sql", sqlsource, SqlCommandType.SELECT); builder.resultMaps(mappedStatement.getResultMaps()).resultSetType(mappedStatement.getResultSetType()) .statementType(mappedStatement.getStatementType()); MappedStatement query_statement = builder.build(); DefaultParameterHandler handler = new DefaultParameterHandler(query_statement, parameter, boundSql); try (PreparedStatement stmt = connection.prepareStatement(sqlExplain)) { handler.setParameters(stmt); try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { if (!"Using where".equals(rs.getString("Extra"))) { if (this.isStopProceed()) { throw new MybatisPlusException( "Error: Full table operation is prohibited. SQL: " + boundSql.getSql()); } break; } } } } catch (Exception e) { throw new MybatisPlusException(e); } }
From source file:com.dao.genericdao.mybatis.plugins.page.support.SqlUtil.java
License:Open Source License
/** * ?sqlSource//w w w . j a v a 2 s . com * * @param configuration * @param sqlSource * @return */ private SqlSource getPageSqlSource(Configuration configuration, SqlSource sqlSource, Object parameterObject) { BoundSql boundSql = sqlSource.getBoundSql(parameterObject); return new StaticSqlSource(configuration, parser.getPageSql(boundSql.getSql()), parser.getPageParameterMapping(configuration, boundSql)); }
From source file:com.dao.genericdao.mybatis.plugins.page.support.SqlUtil.java
License:Open Source License
/** * ?countsqlSource/*from w ww . j av a 2 s .co m*/ * * @param sqlSource * @return */ private SqlSource getCountSqlSource(Configuration configuration, SqlSource sqlSource, Object parameterObject) { BoundSql boundSql = sqlSource.getBoundSql(parameterObject); return new StaticSqlSource(configuration, parser.getCountSql(boundSql.getSql()), boundSql.getParameterMappings()); }
From source file:com.github.abel533.mapper.MapperProvider.java
License:Open Source License
/** * ?//from w w w .jav a 2s . c o m * * @param ms */ public void selectByPrimaryKey(MappedStatement ms) { Class<?> entityClass = getSelectReturnType(ms); //? List<ParameterMapping> parameterMappings = getPrimaryKeyParameterMappings(ms); //sql BEGIN(); //select SELECT(EntityHelper.getSelectColumns(entityClass)); //from FROM(tableName(entityClass)); //where?=#{property} WHERE(EntityHelper.getPrimaryKeyWhere(entityClass)); //SQL()?SQL??SqlSource StaticSqlSource sqlSource = new StaticSqlSource(ms.getConfiguration(), SQL(), parameterMappings); //?SqlSource setSqlSource(ms, sqlSource); // setResultType(ms, entityClass); }
From source file:com.github.abel533.mapper.MapperProvider.java
License:Open Source License
/** * /*from w ww. j a v a2 s . c om*/ * * @param ms */ public void deleteByPrimaryKey(MappedStatement ms) { Class<?> entityClass = getSelectReturnType(ms); List<ParameterMapping> parameterMappings = getPrimaryKeyParameterMappings(ms); //sql BEGIN(); //delete from table DELETE_FROM(tableName(entityClass)); //where =#{property} ? WHERE(EntityHelper.getPrimaryKeyWhere(entityClass)); //??SqlSource StaticSqlSource sqlSource = new StaticSqlSource(ms.getConfiguration(), SQL(), parameterMappings); //?SqlSource setSqlSource(ms, sqlSource); }
From source file:com.github.abel533.mapper.MapperProvider.java
License:Open Source License
/** * /* w w w.jav a 2 s.c om*/ * * @param ms */ public void updateByPrimaryKey(MappedStatement ms) { Class<?> entityClass = getSelectReturnType(ms); //??set=?where=? //?set List<ParameterMapping> parameterMappings = getColumnParameterMappings(ms); //?where parameterMappings.addAll(getPrimaryKeyParameterMappings(ms)); //Sql BEGIN(); //update table UPDATE(tableName(entityClass)); //? List<EntityHelper.EntityColumn> columnList = EntityHelper.getColumns(entityClass); //set column = ? for (EntityHelper.EntityColumn column : columnList) { SET(column.getColumn() + " = ?"); } //where =#{property} ? WHERE(EntityHelper.getPrimaryKeyWhere(entityClass)); //??SqlSource StaticSqlSource sqlSource = new StaticSqlSource(ms.getConfiguration(), SQL(), parameterMappings); //?SqlSource setSqlSource(ms, sqlSource); }