Skip to content

Commit f08d380

Browse files
Long cache, fragment and statement names are never replaced by a short name by StrictMap.
1 parent 3111a25 commit f08d380

File tree

4 files changed

+10
-51
lines changed

4 files changed

+10
-51
lines changed

src/main/java/org/apache/ibatis/session/Configuration.java

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class Configuration {
7777
protected final TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry();
7878
protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();
7979
protected final Map<String, MappedStatement> mappedStatements = new StrictMap<String, MappedStatement>("Mapped Statements collection");
80-
protected final Map<String, Cache> caches = new CacheMap<String, Cache>("Caches collection");
80+
protected final Map<String, Cache> caches = new StrictMap<String, Cache>("Caches collection");
8181
protected final Map<String, ResultMap> resultMaps = new StrictMap<String, ResultMap>("Result Maps collection");
8282
protected final Map<String, ParameterMap> parameterMaps = new StrictMap<String, ParameterMap>("Parameter Maps collection");
8383
protected final Map<String, KeyGenerator> keyGenerators = new StrictMap<String, KeyGenerator>("Key Generators collection");
@@ -511,26 +511,26 @@ protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
511511
}
512512
}
513513

514-
protected static class CacheMap<J extends String, K extends Object> extends HashMap<J, K> {
514+
protected static class StrictMap<J extends String, K extends Object> extends HashMap<J, K> {
515515

516516
private String name;
517517

518-
public CacheMap(String name, int initialCapacity, float loadFactor) {
518+
public StrictMap(String name, int initialCapacity, float loadFactor) {
519519
super(initialCapacity, loadFactor);
520520
this.name = name;
521521
}
522522

523-
public CacheMap(String name, int initialCapacity) {
523+
public StrictMap(String name, int initialCapacity) {
524524
super(initialCapacity);
525525
this.name = name;
526526
}
527527

528-
public CacheMap(String name) {
528+
public StrictMap(String name) {
529529
super();
530530
this.name = name;
531531
}
532532

533-
public CacheMap(String name, Map<? extends J, ? extends K> m) {
533+
public StrictMap(String name, Map<? extends J, ? extends K> m) {
534534
super(m);
535535
this.name = name;
536536
}
@@ -551,10 +551,7 @@ public K put(J key, K value) {
551551
public K get(Object key) {
552552
K value = super.get(key);
553553
if (value == null) {
554-
value = super.get(getShortName((J)key));
555-
if (value == null) {
556-
throw new IllegalArgumentException(name + " does not contain value for " + key);
557-
}
554+
throw new IllegalArgumentException(name + " does not contain value for " + key);
558555
}
559556
if (value instanceof Ambiguity) {
560557
throw new IllegalArgumentException(((Ambiguity)value).getSubject()
@@ -579,43 +576,5 @@ public String getSubject() {
579576
}
580577
}
581578
}
582-
583-
protected static class StrictMap<J extends String, K extends Object> extends HashMap<J, K> {
584579

585-
private String name;
586-
587-
public StrictMap(String name, int initialCapacity, float loadFactor) {
588-
super(initialCapacity, loadFactor);
589-
this.name = name;
590-
}
591-
592-
public StrictMap(String name, int initialCapacity) {
593-
super(initialCapacity);
594-
this.name = name;
595-
}
596-
597-
public StrictMap(String name) {
598-
super();
599-
this.name = name;
600-
}
601-
602-
public StrictMap(String name, Map<? extends J, ? extends K> m) {
603-
super(m);
604-
this.name = name;
605-
}
606-
607-
public K put(J key, K value) {
608-
if (containsKey(key))
609-
throw new IllegalArgumentException(name + " already contains value for " + key);
610-
return super.put(key, value);
611-
}
612-
613-
public K get(Object key) {
614-
K value = super.get(key);
615-
if (value == null) {
616-
throw new IllegalArgumentException(name + " does not contain value for " + key);
617-
}
618-
return value;
619-
}
620-
}
621580
}

src/test/java/org/apache/ibatis/session/SqlSessionManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void shouldResolveBothSimpleNameAndFullyQualifiedName() {
4646
assertEquals(cache, c.getCache(shortName));
4747
}
4848

49-
@Test
49+
@Test(expected=IllegalArgumentException.class)
5050
public void shouldFailOverToMostApplicableSimpleName() {
5151
Configuration c = new Configuration();
5252
final String fullName = "com.mycache.MyCache";

src/test/java/org/apache/ibatis/session/SqlSessionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void shouldResolveBothSimpleNameAndFullyQualifiedName() {
3535
assertEquals(cache, c.getCache(shortName));
3636
}
3737

38-
@Test
38+
@Test(expected=IllegalArgumentException.class)
3939
public void shouldFailOverToMostApplicableSimpleName() {
4040
Configuration c = new Configuration();
4141
final String fullName = "com.mycache.MyCache";

src/test/java/org/apache/ibatis/submitted/xml_external_ref/ShortNameTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.junit.Test;
1414

1515
public class ShortNameTest {
16-
@Test(expected = IllegalArgumentException.class)
16+
@Test
1717
public void getStatementByShortName() throws Exception {
1818
Configuration configuration = getConfiguration();
1919
// statement can be referenced by its short name.

0 commit comments

Comments
 (0)