Author: tchemit Date: 2011-03-04 09:57:47 +0100 (Fri, 04 Mar 2011) New Revision: 2220 Url: http://nuiton.org/repositories/revision/topia/2220 Log: the cache of context is based on TopiaContext and not TopiaContextImpl... Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2011-03-04 08:52:50 UTC (rev 2219) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextFactory.java 2011-03-04 08:57:47 UTC (rev 2220) @@ -56,7 +56,7 @@ "TopiaContextImpl.properties"; /** Cache contenant tous les contexts deja créé. */ - protected static Map<Properties, TopiaContextImpl> contextCache = + protected static Map<Properties, TopiaContext> contextCache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); @@ -68,7 +68,7 @@ */ public static List<String> getContextOpened() { List<String> result = new ArrayList<String>(); - for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) { + for (Entry<Properties, TopiaContext> e : contextCache.entrySet()) { // Useless test : will never happened that e.getValue() is null, // not allowed for {@link AbstractReferenceMap#SOFT}. // if (e.getValue() != null) { @@ -97,14 +97,13 @@ // Replaced by more powerful algorithm using iterator to remove context - Iterator<TopiaContextImpl> it = contextCache.values().iterator(); + Iterator<TopiaContext> it = contextCache.values().iterator(); - boolean removed = false; - while (it.hasNext() && !removed) { - TopiaContextImpl curr = it.next(); + while (it.hasNext()) { + TopiaContext curr = it.next(); if (curr == context) { it.remove(); - removed = true; + break; } } } @@ -135,13 +134,13 @@ public static TopiaContext getContext(Properties config) throws TopiaNotFoundException { // Put all properties from a hierarchy in the current properties object. - // Resolve problem with hibernate which used iterator to get properties + // Resolve problem with hibernate which used iterator to get properties // and so only values from the current properties object and not all // hierarchy for (String key : config.stringPropertyNames()) { config.setProperty(key, config.getProperty(key)); } - TopiaContextImpl result = contextCache.get(config); + TopiaContext result = contextCache.get(config); // useless test, context is automatically removed from Factory when closed if (result == null/* || result.isClosed()*/) { result = new TopiaContextImpl(config);