From 7b6c11a6cd8987e33b3f0cd5c77a16798471acf6 Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Thu, 18 Feb 2010 17:23:06 +0000 Subject: [PATCH] OPENJPA-924: Remove logging from FinderCache -- such low-level details seem to confuse rather to inform the user. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@911496 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/kernel/FinderCacheImpl.java | 86 +++++-------------- .../openjpa/jdbc/kernel/localizer.properties | 4 - 2 files changed, 22 insertions(+), 68 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java index 46b247b47..98bb6d413 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java @@ -29,7 +29,6 @@ import java.util.TreeMap; import java.util.concurrent.locks.ReentrantLock; import org.apache.commons.lang.StringUtils; -import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.jdbc.meta.ClassMapping; import org.apache.openjpa.jdbc.sql.Result; import org.apache.openjpa.jdbc.sql.SelectExecutor; @@ -39,8 +38,6 @@ import org.apache.openjpa.kernel.FinderQuery; import org.apache.openjpa.kernel.QueryHints; import org.apache.openjpa.kernel.QueryStatistics; import org.apache.openjpa.lib.conf.Configuration; -import org.apache.openjpa.lib.log.Log; -import org.apache.openjpa.lib.util.Localizer; /** * Implementation of FinderCache for JDBC. @@ -55,20 +52,15 @@ public class FinderCacheImpl private static final String PATTERN_SEPARATOR = "\\;"; private static final String EXLUDED_BY_USER = "Excluded by user"; - private final Map> _delegate; + private final Map> _delegate; // Key: class name Value: Reason why excluded private final Map _uncachables; private List _exclusionPatterns; private QueryStatistics _stats; private ReentrantLock _lock = new ReentrantLock(); - private Log _log; - private Localizer _loc = Localizer.forPackage(FinderCacheImpl.class); - public FinderCacheImpl() { - _delegate = new HashMap>(); + _delegate = new HashMap>(); _uncachables = new HashMap(); _stats = new QueryStatistics.Default(); } @@ -82,9 +74,10 @@ public class FinderCacheImpl lock(); try { Map view = new TreeMap(); - for (ClassMapping mapping : _delegate.keySet()) + for (ClassMapping mapping : _delegate.keySet()) { view.put(mapping.getDescribedType().getName(), _delegate.get(mapping).getQueryString()); + } return view; } finally { unlock(); @@ -110,16 +103,18 @@ public class FinderCacheImpl */ public FinderQuery get(ClassMapping mapping, FetchConfiguration fetch) { - if (fetch.getReadLockLevel() != 0) + if (fetch.getReadLockLevel() != 0) { return null; + } boolean ignore = isHinted(fetch, QueryHints.HINT_IGNORE_FINDER); boolean invalidate = isHinted(fetch, QueryHints.HINT_INVALIDATE_FINDER); - if (invalidate) + if (invalidate) { invalidate(mapping); - if (ignore) + } + if (ignore) { return null; - FinderQuery result = - _delegate.get(mapping); + } + FinderQuery result = _delegate.get(mapping); _stats.recordExecution(mapping); return result; } @@ -145,8 +140,9 @@ public class FinderCacheImpl (ClassMapping mapping, SelectExecutor select, FetchConfiguration fetch) { lock(); try { - if (fetch.getReadLockLevel() != 0) + if (fetch.getReadLockLevel() != 0) { return null; + } boolean recache = isHinted(fetch, QueryHints.HINT_RECACHE_FINDER); if (isExcluded(mapping)) { return recache ? put(mapping, select) : null; @@ -167,18 +163,11 @@ public class FinderCacheImpl * some Select are not cached), then the mapping is marked invalid. * */ - private FinderQuery put - (ClassMapping mapping, SelectExecutor select) { - FinderQuery finder = - FinderQueryImpl.newFinder(mapping, select); + private FinderQuery put(ClassMapping mapping, SelectExecutor select) { + FinderQuery finder = FinderQueryImpl.newFinder(mapping, select); if (finder != null) { _delegate.put(mapping, finder); - if (_log != null && _log.isTraceEnabled()) - _log.trace(_loc.get("finder-cached", mapping, - finder.getQueryString())); } else { - if (_log != null && _log.isWarnEnabled()) - _log.warn(_loc.get("finder-not-cachable", mapping)); invalidate(mapping); } return finder; @@ -188,8 +177,7 @@ public class FinderCacheImpl * Affirms if the given mapping is excluded from being cached. */ public boolean isExcluded(ClassMapping mapping) { - return mapping != null && - isExcluded(mapping.getDescribedType().getName()); + return mapping != null && isExcluded(mapping.getDescribedType().getName()); } /** @@ -214,10 +202,6 @@ public class FinderCacheImpl _exclusionPatterns.add(pattern); Collection invalidMappings = getMatchedKeys(pattern, _delegate.keySet()); - if (!invalidMappings.isEmpty() - && _log != null && _log.isInfoEnabled()) - _log.info(_loc.get("finder-add-pattern", pattern, - invalidMappings.size(), invalidMappings)); for (ClassMapping invalidMapping : invalidMappings) markUncachable(invalidMapping, pattern); } finally { @@ -237,9 +221,6 @@ public class FinderCacheImpl _exclusionPatterns.remove(pattern); Collection reborns = getMatchedKeys(pattern, _uncachables.keySet()); - if (!reborns.isEmpty() && _log != null && _log.isInfoEnabled()) - _log.info(_loc.get("finder-remove-pattern", pattern, - reborns.size(), reborns)); for (String rebornKey : reborns) _uncachables.remove(rebornKey); } finally { @@ -262,8 +243,7 @@ public class FinderCacheImpl /** * Gets the elements of the given set that match the given pattern. */ - private Collection getMatchedKeys(String pattern, - Set set) { + private Collection getMatchedKeys(String pattern, Set set) { List result = new ArrayList(); for (ClassMapping entry : set) { if (matches(pattern, entry)) { @@ -276,8 +256,7 @@ public class FinderCacheImpl /** * Gets the elements of the given list which match the given pattern. */ - private Collection getMatchedKeys(String pattern, - Collection coll) { + private Collection getMatchedKeys(String pattern, Collection coll) { List result = new ArrayList(); for (String key : coll) { if (matches(pattern, key)) { @@ -299,58 +278,39 @@ public class FinderCacheImpl public boolean invalidate(ClassMapping mapping) { lock(); try { - if (_log.isTraceEnabled()) - _log.trace(_loc.get("finder-invalidate", mapping)); return _delegate.remove(mapping) != null; } finally { unlock(); } } - public FinderQuery markUncachable( - ClassMapping mapping) { + public FinderQuery markUncachable(ClassMapping mapping) { return markUncachable(mapping.getDescribedType().getName()); } - public FinderQuery markUncachable( - String id) { + public FinderQuery markUncachable(String id) { return markUncachable(id, EXLUDED_BY_USER); } - private FinderQuery markUncachable( - String cls, String reason) { + private FinderQuery markUncachable(String cls, String reason) { lock(); try { boolean excludedByUser = _uncachables.get(cls) == EXLUDED_BY_USER; if (!excludedByUser) _uncachables.put(cls, reason); - if (_log != null && _log.isInfoEnabled()) { - if (excludedByUser) - _log.info(_loc.get("finder-uncache-strong", cls)); - else - _log.info(_loc.get("finder-uncache-weak", cls, - reason)); - } return _delegate.remove(searchMappingByName(cls)); } finally { unlock(); } } - private FinderQuery markUncachable( - ClassMapping mapping, String reason) { + private FinderQuery markUncachable(ClassMapping mapping, String reason) { lock(); try { String cls = mapping.getDescribedType().getName(); boolean excludedByUser = _uncachables.get(cls) == EXLUDED_BY_USER; if (!excludedByUser) _uncachables.put(cls, reason); - if (_log != null && _log.isInfoEnabled()) { - if (excludedByUser) - _log.info(_loc.get("finder-uncache-strong", cls)); - else - _log.info(_loc.get("finder-uncache-weak", cls, reason)); - } return _delegate.remove(mapping); } finally { unlock(); @@ -411,10 +371,8 @@ public class FinderCacheImpl } public void setConfiguration(Configuration conf) { - _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); } public void endConfiguration() { } - } diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties index 9ffff7aa6..5ba876d53 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties @@ -135,10 +135,6 @@ uparam-pc-key: Class "{0}" uses {1} primary key columns but corresponding \ positions {2} in the parameter list of the prepared query is not compatible. uparam-missing: Parameter {0} in SQL Query "{1}" is not given a value. The \ parameters given is "{2}". -finder-cached: Cached finder for "{0}" SQL: "{1}" -finder-not-cachable: Finder for "{0}" is not cachable. -finder-add-pattern: Exclusion pattern "{0}" for finder query has invalidated \ - {1} existing entries "{2}" optimistic-violation-lock: An optimistic lock violation was detected when \ locking object instance. sql-warning: The statement resulted in SQL warning: {0}