Skip to content

Commit 06e6db5

Browse files
committed
Refactoring : lower nested levels
1 parent 528d923 commit 06e6db5

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -355,22 +355,17 @@ private void sqlElement(List<XNode> list, String requiredDatabaseId) {
355355

356356
private boolean databaseIdMatchesCurrent(String id, String databaseId, String requiredDatabaseId) {
357357
if (requiredDatabaseId != null) {
358-
if (!requiredDatabaseId.equals(databaseId)) {
359-
return false;
360-
}
361-
} else {
362-
if (databaseId != null) {
363-
return false;
364-
}
365-
// skip this fragment if there is a previous one with a not null databaseId
366-
if (this.sqlFragments.containsKey(id)) {
367-
XNode context = this.sqlFragments.get(id);
368-
if (context.getStringAttribute("databaseId") != null) {
369-
return false;
370-
}
371-
}
358+
return requiredDatabaseId.equals(databaseId);
359+
}
360+
if (databaseId != null) {
361+
return false;
362+
}
363+
if (!this.sqlFragments.containsKey(id)) {
364+
return true;
372365
}
373-
return true;
366+
// skip this fragment if there is a previous one with a not null databaseId
367+
XNode context = this.sqlFragments.get(id);
368+
return context.getStringAttribute("databaseId") == null;
374369
}
375370

376371
private ResultMapping buildResultMappingFromContext(XNode context, Class<?> resultType, List<ResultFlag> flags) throws Exception {

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,18 @@ private void removeSelectKeyNodes(List<XNode> selectKeyNodes) {
173173

174174
private boolean databaseIdMatchesCurrent(String id, String databaseId, String requiredDatabaseId) {
175175
if (requiredDatabaseId != null) {
176-
if (!requiredDatabaseId.equals(databaseId)) {
177-
return false;
178-
}
179-
} else {
180-
if (databaseId != null) {
181-
return false;
182-
}
183-
// skip this statement if there is a previous one with a not null databaseId
184-
id = builderAssistant.applyCurrentNamespace(id, false);
185-
if (this.configuration.hasStatement(id, false)) {
186-
MappedStatement previous = this.configuration.getMappedStatement(id, false); // issue #2
187-
if (previous.getDatabaseId() != null) {
188-
return false;
189-
}
190-
}
176+
return requiredDatabaseId.equals(databaseId);
177+
}
178+
if (databaseId != null) {
179+
return false;
180+
}
181+
id = builderAssistant.applyCurrentNamespace(id, false);
182+
if (!this.configuration.hasStatement(id, false)) {
183+
return true;
191184
}
192-
return true;
185+
// skip this statement if there is a previous one with a not null databaseId
186+
MappedStatement previous = this.configuration.getMappedStatement(id, false); // issue #2
187+
return previous.getDatabaseId() == null;
193188
}
194189

195190
private LanguageDriver getLanguageDriver(String lang) {

0 commit comments

Comments
 (0)