Skip to content

Commit 680a666

Browse files
committed
Polishing gh-44
1 parent fc31f09 commit 680a666

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

src/main/java/org/mybatis/scripting/freemarker/FreeMarkerLanguageDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public SqlSource createSqlSource(Configuration configuration, String script, Cla
138138
}
139139

140140
protected SqlSource createSqlSource(Template template, Configuration configuration) {
141-
return new FreeMarkerSqlSource(template, configuration);
141+
return new FreeMarkerSqlSource(template, configuration, driverConfig.getIncompatibleImprovementsVersion());
142142
}
143143

144144
private SqlSource createSqlSource(Configuration configuration, String scriptText) {

src/main/java/org/mybatis/scripting/freemarker/FreeMarkerSqlSource.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import java.util.HashMap;
2525
import java.util.Map;
2626

27+
import freemarker.template.Version;
2728
import org.apache.ibatis.builder.SqlSourceBuilder;
2829
import org.apache.ibatis.mapping.BoundSql;
2930
import org.apache.ibatis.mapping.SqlSource;
@@ -38,12 +39,14 @@
3839
public class FreeMarkerSqlSource implements SqlSource {
3940
private final Template template;
4041
private final Configuration configuration;
42+
private final Version incompatibleImprovementsVersion;
4143

4244
public static final String GENERATED_PARAMS_KEY = "__GENERATED__";
4345

44-
public FreeMarkerSqlSource(Template template, Configuration configuration) {
46+
public FreeMarkerSqlSource(Template template, Configuration configuration, Version incompatibleImprovementsVersion) {
4547
this.template = template;
4648
this.configuration = configuration;
49+
this.incompatibleImprovementsVersion = incompatibleImprovementsVersion;
4750
}
4851

4952
/**
@@ -72,7 +75,8 @@ public BoundSql getBoundSql(Object parameterObject) {
7275
map.put(GENERATED_PARAMS_KEY, generatedParams);
7376
dataContext = preProcessDataContext(map, true);
7477
} else {
75-
ParamObjectAdapter adapter = new ParamObjectAdapter(parameterObject, generatedParams);
78+
ParamObjectAdapter adapter = new ParamObjectAdapter(parameterObject, generatedParams,
79+
incompatibleImprovementsVersion);
7680
dataContext = preProcessDataContext(adapter, false);
7781
}
7882
} else {

src/main/java/org/mybatis/scripting/freemarker/ParamObjectAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,10 +17,10 @@
1717

1818
import freemarker.ext.beans.BeanModel;
1919
import freemarker.ext.beans.BeansWrapperBuilder;
20-
import freemarker.template.Configuration;
2120
import freemarker.template.TemplateHashModel;
2221
import freemarker.template.TemplateModel;
2322
import freemarker.template.TemplateModelException;
23+
import freemarker.template.Version;
2424

2525
import java.util.ArrayList;
2626
import java.util.HashMap;
@@ -36,8 +36,8 @@ public class ParamObjectAdapter implements TemplateHashModel {
3636
private final ArrayList generatedParams;
3737
private HashMap<String, TemplateModel> additionalParams;
3838

39-
public ParamObjectAdapter(Object paramObject, ArrayList generatedParams) {
40-
beanModel = new BeanModel(paramObject, new BeansWrapperBuilder(Configuration.VERSION_2_3_22).build());
39+
public ParamObjectAdapter(Object paramObject, ArrayList generatedParams, Version incompatibleImprovementsVersion) {
40+
beanModel = new BeanModel(paramObject, new BeansWrapperBuilder(incompatibleImprovementsVersion).build());
4141
this.generatedParams = generatedParams;
4242
}
4343

src/test/java/org/mybatis/scripting/freemarker/CustomizedDataContextTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import freemarker.template.SimpleScalar;
1919
import freemarker.template.Template;
20+
import freemarker.template.Version;
2021
import org.apache.ibatis.io.Resources;
2122
import org.apache.ibatis.jdbc.ScriptRunner;
2223
import org.apache.ibatis.mapping.Environment;
@@ -74,8 +75,8 @@ public static void setUp() throws Exception {
7475
}
7576

7677
public static class CustomSqlSource extends FreeMarkerSqlSource {
77-
public CustomSqlSource(Template template, Configuration configuration) {
78-
super(template, configuration);
78+
public CustomSqlSource(Template template, Configuration configuration, Version version) {
79+
super(template, configuration, version);
7980
}
8081

8182
@Override
@@ -93,7 +94,7 @@ protected Object preProcessDataContext(Object dataContext, boolean isMap) {
9394
public static class CustomFreeMarkerLanguageDriver extends FreeMarkerLanguageDriver {
9495
@Override
9596
protected SqlSource createSqlSource(Template template, Configuration configuration) {
96-
return new CustomSqlSource(template, configuration);
97+
return new CustomSqlSource(template, configuration, driverConfig.getIncompatibleImprovementsVersion());
9798
}
9899
}
99100

0 commit comments

Comments
 (0)