Skip to content

Commit 93a8f5a

Browse files
committed
http://code.google.com/p/mybatis/issues/detail?id=218 . autoMappingBehaviour=NONE|PARTIAL|FULL -> autoMapping=true|false. Thank you Iwao!
1 parent aafd50a commit 93a8f5a

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.apache.ibatis.mapping.SqlSource;
4545
import org.apache.ibatis.mapping.StatementType;
4646
import org.apache.ibatis.reflection.MetaClass;
47-
import org.apache.ibatis.session.AutoMappingBehavior;
4847
import org.apache.ibatis.session.Configuration;
4948
import org.apache.ibatis.type.JdbcType;
5049
import org.apache.ibatis.type.TypeHandler;
@@ -166,11 +165,11 @@ public ResultMap addResultMap(
166165
String extend,
167166
Discriminator discriminator,
168167
List<ResultMapping> resultMappings,
169-
AutoMappingBehavior autoMappingBehavior) {
168+
Boolean autoMapping) {
170169
id = applyCurrentNamespace(id, false);
171170
extend = applyCurrentNamespace(extend, true);
172171

173-
ResultMap.Builder resultMapBuilder = new ResultMap.Builder(configuration, id, type, resultMappings, autoMappingBehavior);
172+
ResultMap.Builder resultMapBuilder = new ResultMap.Builder(configuration, id, type, resultMappings, autoMapping);
174173
if (extend != null) {
175174
if (!configuration.hasResultMap(extend)) {
176175
throw new IncompleteElementException("Could not find a parent resultmap with id '" + extend + "'");

src/main/java/org/apache/ibatis/builder/ResultMapResolver.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.ibatis.mapping.Discriminator;
2121
import org.apache.ibatis.mapping.ResultMap;
2222
import org.apache.ibatis.mapping.ResultMapping;
23-
import org.apache.ibatis.session.AutoMappingBehavior;
2423

2524
public class ResultMapResolver {
2625
private final MapperBuilderAssistant assistant;
@@ -29,20 +28,20 @@ public class ResultMapResolver {
2928
private String extend;
3029
private Discriminator discriminator;
3130
private List<ResultMapping> resultMappings;
32-
private AutoMappingBehavior autoMappingBehavior;
31+
private Boolean autoMapping;
3332

34-
public ResultMapResolver(MapperBuilderAssistant assistant, String id, Class<?> type, String extend, Discriminator discriminator, List<ResultMapping> resultMappings, AutoMappingBehavior autoMappingBehavior) {
33+
public ResultMapResolver(MapperBuilderAssistant assistant, String id, Class<?> type, String extend, Discriminator discriminator, List<ResultMapping> resultMappings, Boolean autoMapping) {
3534
this.assistant = assistant;
3635
this.id = id;
3736
this.type = type;
3837
this.extend = extend;
3938
this.discriminator = discriminator;
4039
this.resultMappings = resultMappings;
41-
this.autoMappingBehavior = autoMappingBehavior;
40+
this.autoMapping = autoMapping;
4241
}
4342

4443
public ResultMap resolve() {
45-
return assistant.addResultMap(this.id, this.type, this.extend, this.discriminator, this.resultMappings, this.autoMappingBehavior);
44+
return assistant.addResultMap(this.id, this.type, this.extend, this.discriminator, this.resultMappings, this.autoMapping);
4645
}
4746

4847
}

src/main/java/org/apache/ibatis/builder/xml/XMLMapperBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.ibatis.mapping.ResultMapping;
4343
import org.apache.ibatis.parsing.XNode;
4444
import org.apache.ibatis.parsing.XPathParser;
45-
import org.apache.ibatis.session.AutoMappingBehavior;
4645
import org.apache.ibatis.session.Configuration;
4746
import org.apache.ibatis.type.JdbcType;
4847
import org.apache.ibatis.type.TypeHandler;
@@ -253,7 +252,7 @@ private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> addi
253252
resultMapNode.getStringAttribute("resultType",
254253
resultMapNode.getStringAttribute("javaType"))));
255254
String extend = resultMapNode.getStringAttribute("extends");
256-
AutoMappingBehavior autoMappingBehavior = resultMapNode.getEnumAttribute(AutoMappingBehavior.class, "autoMappingBehavior");
255+
Boolean autoMapping = resultMapNode.getBooleanAttribute("autoMapping", null);
257256
Class<?> typeClass = resolveClass(type);
258257
Discriminator discriminator = null;
259258
List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
@@ -272,7 +271,7 @@ private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> addi
272271
resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
273272
}
274273
}
275-
ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator, resultMappings, autoMappingBehavior);
274+
ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator, resultMappings, autoMapping);
276275
try {
277276
return resultMapResolver.resolve();
278277
} catch (IncompleteElementException e) {

src/main/java/org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ typeHandler CDATA #IMPLIED
5959
id CDATA #REQUIRED
6060
type CDATA #REQUIRED
6161
extends CDATA #IMPLIED
62-
autoMappingBehavior (NONE | PARTIAL | FULL) #IMPLIED
62+
autoMapping (true|false) #IMPLIED
6363
>
6464

6565
<!ELEMENT constructor (idArg*,arg*)>

src/main/java/org/apache/ibatis/executor/resultset/FastResultSetHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ protected Object getRowValue(ResultSet rs, ResultMap resultMap, CacheKey rowKey,
256256
if (resultObject != null && !typeHandlerRegistry.hasTypeHandler(resultMap.getType())) {
257257
final MetaObject metaObject = configuration.newMetaObject(resultObject);
258258
boolean foundValues = resultMap.getConstructorResultMappings().size() > 0;
259-
if (!AutoMappingBehavior.NONE.equals(getAutoMappingBehavior(resultMap))) {
259+
if (shouldApplyAutomaticMappings(resultMap, !AutoMappingBehavior.NONE.equals(configuration.getAutoMappingBehavior()))) {
260260
final List<String> unmappedColumnNames = resultColumnCache.getUnmappedColumnNames(resultMap, null);
261261
foundValues = applyAutomaticMappings(rs, unmappedColumnNames, metaObject, null, resultColumnCache) || foundValues;
262262
}
@@ -269,9 +269,9 @@ protected Object getRowValue(ResultSet rs, ResultMap resultMap, CacheKey rowKey,
269269
return resultObject;
270270
}
271271

272-
protected AutoMappingBehavior getAutoMappingBehavior(ResultMap resultMap) {
273-
if (resultMap.getAutoMappingBehavior() != null) return resultMap.getAutoMappingBehavior();
274-
return configuration.getAutoMappingBehavior();
272+
protected boolean shouldApplyAutomaticMappings(ResultMap resultMap, boolean def) {
273+
if (resultMap.getAutoMapping() != null) return resultMap.getAutoMapping();
274+
return def;
275275
}
276276

277277
protected ResultLoaderMap instantiateResultLoaderMap() {

src/main/java/org/apache/ibatis/executor/resultset/NestedResultSetHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected Object getRowValue(ResultSet rs, ResultMap resultMap, CacheKey combine
140140
if (rowKey != CacheKey.NULL_CACHE_KEY) ancestorCache.put(rowKey, resultObject);
141141
final MetaObject metaObject = configuration.newMetaObject(resultObject);
142142
boolean foundValues = resultMap.getConstructorResultMappings().size() > 0;
143-
if (AutoMappingBehavior.FULL.equals(getAutoMappingBehavior(resultMap))) {
143+
if (shouldApplyAutomaticMappings(resultMap, AutoMappingBehavior.FULL.equals(configuration.getAutoMappingBehavior()))) {
144144
final List<String> unmappedColumnNames = resultColumnCache.getUnmappedColumnNames(resultMap, columnPrefix);
145145
foundValues = applyAutomaticMappings(rs, unmappedColumnNames, metaObject, columnPrefix, resultColumnCache) || foundValues;
146146
}

src/main/java/org/apache/ibatis/mapping/ResultMap.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
*/
1616
package org.apache.ibatis.mapping;
1717

18-
import org.apache.ibatis.session.AutoMappingBehavior;
19-
import org.apache.ibatis.session.Configuration;
18+
import java.util.ArrayList;
19+
import java.util.Collections;
20+
import java.util.HashSet;
21+
import java.util.List;
22+
import java.util.Locale;
23+
import java.util.Set;
2024

21-
import java.util.*;
25+
import org.apache.ibatis.session.Configuration;
2226

2327
public class ResultMap {
2428
private String id;
@@ -31,7 +35,7 @@ public class ResultMap {
3135
private Discriminator discriminator;
3236
private boolean hasNestedResultMaps;
3337
private boolean hasNestedQueries;
34-
private AutoMappingBehavior autoMappingBehavior;
38+
private Boolean autoMapping;
3539

3640
private ResultMap() {
3741
}
@@ -43,11 +47,11 @@ public Builder(Configuration configuration, String id, Class<?> type, List<Resul
4347
this(configuration, id, type, resultMappings, null);
4448
}
4549

46-
public Builder(Configuration configuration, String id, Class<?> type, List<ResultMapping> resultMappings, AutoMappingBehavior autoMappingBehavior) {
50+
public Builder(Configuration configuration, String id, Class<?> type, List<ResultMapping> resultMappings, Boolean autoMapping) {
4751
resultMap.id = id;
4852
resultMap.type = type;
4953
resultMap.resultMappings = resultMappings;
50-
resultMap.autoMappingBehavior = autoMappingBehavior;
54+
resultMap.autoMapping = autoMapping;
5155
}
5256

5357
public Builder discriminator(Discriminator discriminator) {
@@ -147,8 +151,8 @@ public void forceNestedResultMaps() {
147151
hasNestedResultMaps = true;
148152
}
149153

150-
public AutoMappingBehavior getAutoMappingBehavior() {
151-
return autoMappingBehavior;
154+
public Boolean getAutoMapping() {
155+
return autoMapping;
152156
}
153157

154158
}

src/test/java/org/apache/ibatis/submitted/automapping/Mapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
select * from users
2525
</select>
2626

27-
<resultMap type="org.apache.ibatis.submitted.automapping.User" id="result" autoMappingBehavior="PARTIAL">
27+
<resultMap type="org.apache.ibatis.submitted.automapping.User" id="result" autoMapping="true">
2828
</resultMap>
2929

3030
</mapper>

0 commit comments

Comments
 (0)