Skip to content

Commit

Permalink
1.1.9 RELEASE
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangrongfan committed Aug 20, 2018
1 parent c8ebbb7 commit 6d470ed
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 22 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ Mybatis SQL开发神器MybatisBoost,包含通用CrudMapper、Mybatis语法增
<dependency>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost-spring-boot-starter</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</dependency>
```

Expand Down Expand Up @@ -128,6 +128,8 @@ SELECT * FROM POST WHERE ID IN #{ids} AND Name IN #{names}
List<Post> select(@Param("ids") List<Integer> ids, @Param("names") List<Integer> names);
```

需要注意的是,范围参数增强无法和MyBatis提供的"<foreach>"一起使用,使用"<foreach>"后,范围参数增强将失效。

### INSERT增强

INSERT语法增强后,可使用如下3种语法编写INSERT语句,INSERT语法增强同样支持批量插入。
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-all/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>
<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-core/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-lang/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-lang</artifactId>
Expand Down
Expand Up @@ -7,32 +7,61 @@
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.scripting.xmltags.DynamicSqlSource;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.apache.ibatis.scripting.xmltags.MixedSqlNode;
import org.apache.ibatis.scripting.xmltags.SqlNode;
import org.apache.ibatis.session.Configuration;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;

public class ListParameterEnhancement implements SqlProvider {

private static ConcurrentMap<String, Boolean> filterCache = new ConcurrentHashMap<>();

@Override
public void replace(MetaObject metaObject, MappedStatement mappedStatement, BoundSql boundSql) {
org.apache.ibatis.session.Configuration configuration =
(org.apache.ibatis.session.Configuration) metaObject.getValue("delegate.configuration");
if (filter(mappedStatement)) {
org.apache.ibatis.session.Configuration configuration =
(org.apache.ibatis.session.Configuration) metaObject.getValue("delegate.configuration");

Map<Integer, List<?>> listMap =
getLists(boundSql.getParameterObject(), boundSql.getParameterMappings(), configuration);
if (!listMap.isEmpty()) {
StringBuilder sqlBuilder = new StringBuilder(boundSql.getSql());
replacePlaceholders(listMap, sqlBuilder);
metaObject.setValue("delegate.boundSql.sql",
String.format(sqlBuilder.toString(), buildNewPlaceholders(listMap)));
refreshParameterMappings(boundSql.getParameterMappings(), configuration, listMap);
Map<Integer, List<?>> listMap =
getLists(boundSql.getParameterObject(), boundSql.getParameterMappings(), configuration);
if (!listMap.isEmpty()) {
StringBuilder sqlBuilder = new StringBuilder(boundSql.getSql());
replacePlaceholders(listMap, sqlBuilder);
metaObject.setValue("delegate.boundSql.sql",
String.format(sqlBuilder.toString(), buildNewPlaceholders(listMap)));
refreshParameterMappings(boundSql.getParameterMappings(), configuration, listMap);
}
}
}

@SuppressWarnings("unchecked")
private boolean filter(MappedStatement mappedStatement) {
return filterCache.computeIfAbsent(mappedStatement.getId(), k -> {
if (mappedStatement.getSqlSource() instanceof DynamicSqlSource) {
SqlNode rootSqlNode = (SqlNode)
SystemMetaObject.forObject(mappedStatement.getSqlSource()).getValue("rootSqlNode");
if (rootSqlNode instanceof ForEachSqlNode) return false;
if (rootSqlNode instanceof MixedSqlNode) {
List<SqlNode> contents = (List<SqlNode>)
SystemMetaObject.forObject(rootSqlNode).getValue("contents");
for (SqlNode sqlNode : contents) {
if (sqlNode instanceof ForEachSqlNode) return false;
}
}
}
return true;
});
}

private Map<Integer, List<?>> getLists(Object parameterObject, List<ParameterMapping> parameterMappings,
org.apache.ibatis.session.Configuration configuration) {
Map<Integer, List<?>> listMap = new HashMap<>();
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-limiter/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-limiter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-mapper/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-mapper</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-metric/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-metric</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-spring-boot-autoconfigure/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-spring-boot-autoconfigure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-spring-boot-starter/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-spring-boot-starter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion mybatis-boost-test/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
</parent>

<artifactId>mybatis-boost-test</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.mybatisboost</groupId>
<artifactId>mybatis-boost</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>
<packaging>pom</packaging>

<name>MybatisBoost</name>
Expand Down Expand Up @@ -48,7 +48,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version>1.1.8</version>
<version>1.1.9</version>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit 6d470ed

Please sign in to comment.