Skip to content

Commit 2e856a8

Browse files
authored
Merge pull request #1838 from zhangt2333/master
Refine some code
2 parents 684ba86 + 50eed70 commit 2e856a8

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public XNode getSqlFragment(String refid) {
108108
private void configurationElement(XNode context) {
109109
try {
110110
String namespace = context.getStringAttribute("namespace");
111-
if (namespace == null || namespace.equals("")) {
111+
if (namespace == null || namespace.isEmpty()) {
112112
throw new BuilderException("Mapper's namespace cannot be empty");
113113
}
114114
builderAssistant.setCurrentNamespace(namespace);

src/main/java/org/apache/ibatis/executor/ReuseExecutor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2020 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.
@@ -95,7 +95,8 @@ private Statement prepareStatement(StatementHandler handler, Log statementLog) t
9595

9696
private boolean hasStatementFor(String sql) {
9797
try {
98-
return statementMap.keySet().contains(sql) && !statementMap.get(sql).getConnection().isClosed();
98+
Statement statement = statementMap.get(sql);
99+
return statement != null && !statement.getConnection().isClosed();
99100
} catch (SQLException e) {
100101
return false;
101102
}

src/main/java/org/apache/ibatis/jdbc/ScriptRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private void handleLine(StringBuilder command, String line) throws SQLException
208208
}
209209
println(trimmedLine);
210210
} else if (commandReadyToExecute(trimmedLine)) {
211-
command.append(line.substring(0, line.lastIndexOf(delimiter)));
211+
command.append(line, 0, line.lastIndexOf(delimiter));
212212
command.append(LINE_SEPARATOR);
213213
println(command);
214214
executeStatement(command.toString());

src/main/java/org/apache/ibatis/reflection/Reflector.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 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.
@@ -149,8 +149,9 @@ private void addMethodConflict(Map<String, List<Method>> conflictingMethods, Str
149149
}
150150

151151
private void resolveSetterConflicts(Map<String, List<Method>> conflictingSetters) {
152-
for (String propName : conflictingSetters.keySet()) {
153-
List<Method> setters = conflictingSetters.get(propName);
152+
for (Entry<String, List<Method>> entry : conflictingSetters.entrySet()) {
153+
String propName = entry.getKey();
154+
List<Method> setters = entry.getValue();
154155
Class<?> getterType = getTypes.get(propName);
155156
boolean isGetterAmbiguous = getMethods.get(propName) instanceof AmbiguousMethodInvoker;
156157
boolean isSetterAmbiguous = false;
@@ -428,7 +429,7 @@ public String[] getSetablePropertyNames() {
428429
* @return True if the object has a writable property by the name
429430
*/
430431
public boolean hasSetter(String propertyName) {
431-
return setMethods.keySet().contains(propertyName);
432+
return setMethods.containsKey(propertyName);
432433
}
433434

434435
/**
@@ -438,7 +439,7 @@ public boolean hasSetter(String propertyName) {
438439
* @return True if the object has a readable property by the name
439440
*/
440441
public boolean hasGetter(String propertyName) {
441-
return getMethods.keySet().contains(propertyName);
442+
return getMethods.containsKey(propertyName);
442443
}
443444

444445
public String findPropertyName(String name) {

src/test/java/org/apache/ibatis/submitted/blocking_cache/Person.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2020 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.
@@ -59,9 +59,9 @@ public void setLastname(String lastname) {
5959
@Override
6060
public String toString() {
6161
StringBuilder sb = new StringBuilder();
62-
sb.append("id=" + id);
63-
sb.append(", lastname=" + lastname);
64-
sb.append(", firstname=" + firstname);
62+
sb.append("id=").append(id);
63+
sb.append(", lastname=").append(lastname);
64+
sb.append(", firstname=").append(firstname);
6565
return sb.toString();
6666
}
6767

src/test/java/org/apache/ibatis/submitted/cache/Person.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2020 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.
@@ -59,9 +59,9 @@ public void setLastname(String lastname) {
5959
@Override
6060
public String toString() {
6161
StringBuilder sb = new StringBuilder();
62-
sb.append("id=" + id);
63-
sb.append(", lastname=" + lastname);
64-
sb.append(", firstname=" + firstname);
62+
sb.append("id=").append(id);
63+
sb.append(", lastname=").append(lastname);
64+
sb.append(", firstname=").append(firstname);
6565
return sb.toString();
6666
}
6767

src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/BaseMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 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.
@@ -73,7 +73,7 @@ public String provideInsert(Map<String, Object> map) {
7373
} else {
7474
sql.append(",");
7575
}
76-
sql.append(" (#{list[" + i + "].id}, #{list[" + i + "].name})");
76+
sql.append(" (#{list[").append(i).append("].id}, #{list[").append(i).append("].name})");
7777
}
7878
return sql == null ? "" : sql.toString();
7979
}

0 commit comments

Comments
 (0)