|
1 |
| -package org.apache.ibatis.executor.loader; |
2 |
| - |
3 |
| -import java.sql.SQLException; |
4 |
| -import java.util.HashMap; |
5 |
| -import java.util.Locale; |
6 |
| -import java.util.Map; |
7 |
| -import java.util.Set; |
8 |
| - |
9 |
| -import org.apache.ibatis.reflection.MetaObject; |
10 |
| - |
11 |
| -public class ResultLoaderMap { |
12 |
| - |
13 |
| - private final Map<String, LoadPair> loaderMap = new HashMap<String, LoadPair>(); |
14 |
| - |
15 |
| - public void addLoader(String property, MetaObject metaResultObject, ResultLoader resultLoader) { |
16 |
| - String upperFirst = getUppercaseFirstProperty(property); |
17 |
| - loaderMap.put(upperFirst, new LoadPair(property, metaResultObject, resultLoader)); |
18 |
| - } |
19 |
| - |
20 |
| - public int size() { |
21 |
| - return loaderMap.size(); |
22 |
| - } |
23 |
| - |
24 |
| - public boolean hasLoader(String methodName) { |
25 |
| - return loaderMap.containsKey(methodName.toUpperCase(Locale.ENGLISH)); |
26 |
| - } |
27 |
| - |
28 |
| - public boolean load(String property) throws SQLException { |
29 |
| - LoadPair pair = loaderMap.remove(property.toUpperCase(Locale.ENGLISH)); |
30 |
| - if (pair != null) { |
31 |
| - pair.load(); |
32 |
| - return true; |
33 |
| - } |
34 |
| - return false; |
35 |
| - } |
36 |
| - |
37 |
| - public void loadAll() throws SQLException { |
38 |
| - final Set<String> methodNameSet = loaderMap.keySet(); |
39 |
| - String[] methodNames = methodNameSet.toArray(new String[methodNameSet.size()]); |
40 |
| - for (String methodName : methodNames) { |
41 |
| - load(methodName); |
42 |
| - } |
43 |
| - } |
44 |
| - |
45 |
| - private static String getUppercaseFirstProperty(String property) { |
46 |
| - String[] parts = property.split("\\."); |
47 |
| - return parts[0].toUpperCase(Locale.ENGLISH); |
48 |
| - } |
49 |
| - |
50 |
| - private static class LoadPair { |
51 |
| - private String property; |
52 |
| - private MetaObject metaResultObject; |
53 |
| - private ResultLoader resultLoader; |
54 |
| - |
55 |
| - private LoadPair(String property, MetaObject metaResultObject, ResultLoader resultLoader) { |
56 |
| - this.property = property; |
57 |
| - this.metaResultObject = metaResultObject; |
58 |
| - this.resultLoader = resultLoader; |
59 |
| - } |
60 |
| - |
61 |
| - public void load() throws SQLException { |
62 |
| - metaResultObject.setValue(property, resultLoader.loadResult()); |
63 |
| - } |
64 |
| - } |
65 |
| -} |
| 1 | +package org.apache.ibatis.executor.loader; |
| 2 | + |
| 3 | +import java.sql.SQLException; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.Locale; |
| 6 | +import java.util.Map; |
| 7 | +import java.util.Set; |
| 8 | + |
| 9 | +import org.apache.ibatis.reflection.MetaObject; |
| 10 | + |
| 11 | +public class ResultLoaderMap { |
| 12 | + |
| 13 | + private final Map<String, LoadPair> loaderMap = new HashMap<String, LoadPair>(); |
| 14 | + |
| 15 | + public void addLoader(String property, MetaObject metaResultObject, ResultLoader resultLoader) { |
| 16 | + String upperFirst = getUppercaseFirstProperty(property); |
| 17 | + loaderMap.put(upperFirst, new LoadPair(property, metaResultObject, resultLoader)); |
| 18 | + } |
| 19 | + |
| 20 | + public Set<String> getPropertyNames() { |
| 21 | + return loaderMap.keySet(); |
| 22 | + } |
| 23 | + |
| 24 | + public int size() { |
| 25 | + return loaderMap.size(); |
| 26 | + } |
| 27 | + |
| 28 | + public boolean hasLoader(String property) { |
| 29 | + return loaderMap.containsKey(property.toUpperCase(Locale.ENGLISH)); |
| 30 | + } |
| 31 | + |
| 32 | + public boolean load(String property) throws SQLException { |
| 33 | + LoadPair pair = loaderMap.remove(property.toUpperCase(Locale.ENGLISH)); |
| 34 | + if (pair != null) { |
| 35 | + pair.load(); |
| 36 | + return true; |
| 37 | + } |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + public void loadAll() throws SQLException { |
| 42 | + final Set<String> methodNameSet = loaderMap.keySet(); |
| 43 | + String[] methodNames = methodNameSet.toArray(new String[methodNameSet.size()]); |
| 44 | + for (String methodName : methodNames) { |
| 45 | + load(methodName); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + private static String getUppercaseFirstProperty(String property) { |
| 50 | + String[] parts = property.split("\\."); |
| 51 | + return parts[0].toUpperCase(Locale.ENGLISH); |
| 52 | + } |
| 53 | + |
| 54 | + private static class LoadPair { |
| 55 | + private String property; |
| 56 | + private MetaObject metaResultObject; |
| 57 | + private ResultLoader resultLoader; |
| 58 | + |
| 59 | + private LoadPair(String property, MetaObject metaResultObject, ResultLoader resultLoader) { |
| 60 | + this.property = property; |
| 61 | + this.metaResultObject = metaResultObject; |
| 62 | + this.resultLoader = resultLoader; |
| 63 | + } |
| 64 | + |
| 65 | + public void load() throws SQLException { |
| 66 | + metaResultObject.setValue(property, resultLoader.loadResult()); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments