12
12
import java .util .Properties ;
13
13
14
14
import org .apache .ibatis .builder .BaseBuilder ;
15
+ import org .apache .ibatis .builder .BuilderException ;
15
16
import org .apache .ibatis .builder .CacheRefResolver ;
16
17
import org .apache .ibatis .builder .IncompleteCacheException ;
17
18
import org .apache .ibatis .builder .MapperBuilderAssistant ;
@@ -35,6 +36,7 @@ public class XMLMapperBuilder extends BaseBuilder {
35
36
private XPathParser parser ;
36
37
private MapperBuilderAssistant builderAssistant ;
37
38
private Map <String , XNode > sqlFragments ;
39
+ private String resource ;
38
40
39
41
@ Deprecated
40
42
public XMLMapperBuilder (Reader reader , Configuration configuration , String resource , Map <String , XNode > sqlFragments , String namespace ) {
@@ -63,27 +65,28 @@ private XMLMapperBuilder(XPathParser parser, Configuration configuration, String
63
65
this .builderAssistant = new MapperBuilderAssistant (configuration , resource );
64
66
this .parser = parser ;
65
67
this .sqlFragments = sqlFragments ;
68
+ this .resource = resource ;
66
69
}
67
-
70
+
68
71
public void parse () {
69
- XNode context = parser .evalNode ("/mapper" );
70
- String namespace = context .getStringAttribute ("namespace" );
71
- builderAssistant .setCurrentNamespace (namespace );
72
- if (!configuration .isResourceLoaded (namespace )) {
73
- configurationElement (context );
74
- configuration .addLoadedResource (namespace );
72
+ if (!configuration .isResourceLoaded (resource )) {
73
+ configurationElement (parser .evalNode ("/mapper" ));
74
+ configuration .addLoadedResource (resource );
75
75
bindMapperForNamespace ();
76
- parsePendingChacheRefs ();
77
- parsePendingStatements ();
78
76
}
77
+
78
+ parsePendingChacheRefs ();
79
+ parsePendingStatements ();
79
80
}
80
-
81
+
81
82
public XNode getSqlFragment (String refid ) {
82
83
return sqlFragments .get (refid );
83
84
}
84
85
85
86
private void configurationElement (XNode context ) {
86
87
try {
88
+ String namespace = context .getStringAttribute ("namespace" );
89
+ builderAssistant .setCurrentNamespace (namespace );
87
90
cacheRefElement (context .evalNode ("cache-ref" ));
88
91
cacheElement (context .evalNode ("cache" ));
89
92
parameterMapElement (context .evalNodes ("/mapper/parameterMap" ));
@@ -93,7 +96,6 @@ private void configurationElement(XNode context) {
93
96
} catch (Exception e ) {
94
97
throw new RuntimeException ("Error parsing Mapper XML. Cause: " + e , e );
95
98
}
96
-
97
99
}
98
100
99
101
private void buildStatementFromContext (List <XNode > list ) {
@@ -305,6 +307,10 @@ private void bindMapperForNamespace() {
305
307
}
306
308
if (boundType != null ) {
307
309
if (!configuration .hasMapper (boundType )) {
310
+ // Spring may not know the real resource name so we set a flag
311
+ // to prevent loading again this resource from the mapper interface
312
+ // look at MapperAnnotationBuilder#loadXmlResource
313
+ configuration .addLoadedResource ("namespace:" + namespace );
308
314
configuration .addMapper (boundType );
309
315
}
310
316
}
0 commit comments