mirror of https://github.com/apache/openjpa.git
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
This commit is contained in:
parent
fe2c9295f4
commit
7b6c11a6cd
|
@ -29,7 +29,6 @@ import java.util.TreeMap;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.openjpa.conf.OpenJPAConfiguration;
|
|
||||||
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
||||||
import org.apache.openjpa.jdbc.sql.Result;
|
import org.apache.openjpa.jdbc.sql.Result;
|
||||||
import org.apache.openjpa.jdbc.sql.SelectExecutor;
|
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.QueryHints;
|
||||||
import org.apache.openjpa.kernel.QueryStatistics;
|
import org.apache.openjpa.kernel.QueryStatistics;
|
||||||
import org.apache.openjpa.lib.conf.Configuration;
|
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.
|
* Implementation of FinderCache for JDBC.
|
||||||
|
@ -55,20 +52,15 @@ public class FinderCacheImpl
|
||||||
private static final String PATTERN_SEPARATOR = "\\;";
|
private static final String PATTERN_SEPARATOR = "\\;";
|
||||||
private static final String EXLUDED_BY_USER = "Excluded by user";
|
private static final String EXLUDED_BY_USER = "Excluded by user";
|
||||||
|
|
||||||
private final Map<ClassMapping,
|
private final Map<ClassMapping, FinderQuery<ClassMapping, SelectExecutor, Result>> _delegate;
|
||||||
FinderQuery<ClassMapping, SelectExecutor, Result>> _delegate;
|
|
||||||
// Key: class name Value: Reason why excluded
|
// Key: class name Value: Reason why excluded
|
||||||
private final Map<String, String> _uncachables;
|
private final Map<String, String> _uncachables;
|
||||||
private List<String> _exclusionPatterns;
|
private List<String> _exclusionPatterns;
|
||||||
private QueryStatistics<ClassMapping> _stats;
|
private QueryStatistics<ClassMapping> _stats;
|
||||||
private ReentrantLock _lock = new ReentrantLock();
|
private ReentrantLock _lock = new ReentrantLock();
|
||||||
private Log _log;
|
|
||||||
private Localizer _loc = Localizer.forPackage(FinderCacheImpl.class);
|
|
||||||
|
|
||||||
|
|
||||||
public FinderCacheImpl() {
|
public FinderCacheImpl() {
|
||||||
_delegate = new HashMap<ClassMapping,
|
_delegate = new HashMap<ClassMapping, FinderQuery<ClassMapping, SelectExecutor, Result>>();
|
||||||
FinderQuery<ClassMapping, SelectExecutor, Result>>();
|
|
||||||
_uncachables = new HashMap<String, String>();
|
_uncachables = new HashMap<String, String>();
|
||||||
_stats = new QueryStatistics.Default<ClassMapping>();
|
_stats = new QueryStatistics.Default<ClassMapping>();
|
||||||
}
|
}
|
||||||
|
@ -82,9 +74,10 @@ public class FinderCacheImpl
|
||||||
lock();
|
lock();
|
||||||
try {
|
try {
|
||||||
Map<String, String> view = new TreeMap<String, String>();
|
Map<String, String> view = new TreeMap<String, String>();
|
||||||
for (ClassMapping mapping : _delegate.keySet())
|
for (ClassMapping mapping : _delegate.keySet()) {
|
||||||
view.put(mapping.getDescribedType().getName(),
|
view.put(mapping.getDescribedType().getName(),
|
||||||
_delegate.get(mapping).getQueryString());
|
_delegate.get(mapping).getQueryString());
|
||||||
|
}
|
||||||
return view;
|
return view;
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -110,16 +103,18 @@ public class FinderCacheImpl
|
||||||
*/
|
*/
|
||||||
public FinderQuery<ClassMapping,SelectExecutor,Result>
|
public FinderQuery<ClassMapping,SelectExecutor,Result>
|
||||||
get(ClassMapping mapping, FetchConfiguration fetch) {
|
get(ClassMapping mapping, FetchConfiguration fetch) {
|
||||||
if (fetch.getReadLockLevel() != 0)
|
if (fetch.getReadLockLevel() != 0) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
boolean ignore = isHinted(fetch, QueryHints.HINT_IGNORE_FINDER);
|
boolean ignore = isHinted(fetch, QueryHints.HINT_IGNORE_FINDER);
|
||||||
boolean invalidate = isHinted(fetch, QueryHints.HINT_INVALIDATE_FINDER);
|
boolean invalidate = isHinted(fetch, QueryHints.HINT_INVALIDATE_FINDER);
|
||||||
if (invalidate)
|
if (invalidate) {
|
||||||
invalidate(mapping);
|
invalidate(mapping);
|
||||||
if (ignore)
|
}
|
||||||
|
if (ignore) {
|
||||||
return null;
|
return null;
|
||||||
FinderQuery<ClassMapping, SelectExecutor, Result> result =
|
}
|
||||||
_delegate.get(mapping);
|
FinderQuery<ClassMapping, SelectExecutor, Result> result = _delegate.get(mapping);
|
||||||
_stats.recordExecution(mapping);
|
_stats.recordExecution(mapping);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -145,8 +140,9 @@ public class FinderCacheImpl
|
||||||
(ClassMapping mapping, SelectExecutor select, FetchConfiguration fetch) {
|
(ClassMapping mapping, SelectExecutor select, FetchConfiguration fetch) {
|
||||||
lock();
|
lock();
|
||||||
try {
|
try {
|
||||||
if (fetch.getReadLockLevel() != 0)
|
if (fetch.getReadLockLevel() != 0) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
boolean recache = isHinted(fetch, QueryHints.HINT_RECACHE_FINDER);
|
boolean recache = isHinted(fetch, QueryHints.HINT_RECACHE_FINDER);
|
||||||
if (isExcluded(mapping)) {
|
if (isExcluded(mapping)) {
|
||||||
return recache ? put(mapping, select) : null;
|
return recache ? put(mapping, select) : null;
|
||||||
|
@ -167,18 +163,11 @@ public class FinderCacheImpl
|
||||||
* some Select are not cached), then the mapping is marked invalid.
|
* some Select are not cached), then the mapping is marked invalid.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private FinderQuery<ClassMapping, SelectExecutor, Result> put
|
private FinderQuery<ClassMapping, SelectExecutor, Result> put(ClassMapping mapping, SelectExecutor select) {
|
||||||
(ClassMapping mapping, SelectExecutor select) {
|
FinderQuery<ClassMapping, SelectExecutor, Result> finder = FinderQueryImpl.newFinder(mapping, select);
|
||||||
FinderQuery<ClassMapping, SelectExecutor, Result> finder =
|
|
||||||
FinderQueryImpl.newFinder(mapping, select);
|
|
||||||
if (finder != null) {
|
if (finder != null) {
|
||||||
_delegate.put(mapping, finder);
|
_delegate.put(mapping, finder);
|
||||||
if (_log != null && _log.isTraceEnabled())
|
|
||||||
_log.trace(_loc.get("finder-cached", mapping,
|
|
||||||
finder.getQueryString()));
|
|
||||||
} else {
|
} else {
|
||||||
if (_log != null && _log.isWarnEnabled())
|
|
||||||
_log.warn(_loc.get("finder-not-cachable", mapping));
|
|
||||||
invalidate(mapping);
|
invalidate(mapping);
|
||||||
}
|
}
|
||||||
return finder;
|
return finder;
|
||||||
|
@ -188,8 +177,7 @@ public class FinderCacheImpl
|
||||||
* Affirms if the given mapping is excluded from being cached.
|
* Affirms if the given mapping is excluded from being cached.
|
||||||
*/
|
*/
|
||||||
public boolean isExcluded(ClassMapping mapping) {
|
public boolean isExcluded(ClassMapping mapping) {
|
||||||
return mapping != null &&
|
return mapping != null && isExcluded(mapping.getDescribedType().getName());
|
||||||
isExcluded(mapping.getDescribedType().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,10 +202,6 @@ public class FinderCacheImpl
|
||||||
_exclusionPatterns.add(pattern);
|
_exclusionPatterns.add(pattern);
|
||||||
Collection<ClassMapping> invalidMappings = getMatchedKeys(pattern,
|
Collection<ClassMapping> invalidMappings = getMatchedKeys(pattern,
|
||||||
_delegate.keySet());
|
_delegate.keySet());
|
||||||
if (!invalidMappings.isEmpty()
|
|
||||||
&& _log != null && _log.isInfoEnabled())
|
|
||||||
_log.info(_loc.get("finder-add-pattern", pattern,
|
|
||||||
invalidMappings.size(), invalidMappings));
|
|
||||||
for (ClassMapping invalidMapping : invalidMappings)
|
for (ClassMapping invalidMapping : invalidMappings)
|
||||||
markUncachable(invalidMapping, pattern);
|
markUncachable(invalidMapping, pattern);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -237,9 +221,6 @@ public class FinderCacheImpl
|
||||||
_exclusionPatterns.remove(pattern);
|
_exclusionPatterns.remove(pattern);
|
||||||
Collection<String> reborns = getMatchedKeys(pattern,
|
Collection<String> reborns = getMatchedKeys(pattern,
|
||||||
_uncachables.keySet());
|
_uncachables.keySet());
|
||||||
if (!reborns.isEmpty() && _log != null && _log.isInfoEnabled())
|
|
||||||
_log.info(_loc.get("finder-remove-pattern", pattern,
|
|
||||||
reborns.size(), reborns));
|
|
||||||
for (String rebornKey : reborns)
|
for (String rebornKey : reborns)
|
||||||
_uncachables.remove(rebornKey);
|
_uncachables.remove(rebornKey);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -262,8 +243,7 @@ public class FinderCacheImpl
|
||||||
/**
|
/**
|
||||||
* Gets the elements of the given set that match the given pattern.
|
* Gets the elements of the given set that match the given pattern.
|
||||||
*/
|
*/
|
||||||
private Collection<ClassMapping> getMatchedKeys(String pattern,
|
private Collection<ClassMapping> getMatchedKeys(String pattern, Set<ClassMapping> set) {
|
||||||
Set<ClassMapping> set) {
|
|
||||||
List<ClassMapping> result = new ArrayList<ClassMapping>();
|
List<ClassMapping> result = new ArrayList<ClassMapping>();
|
||||||
for (ClassMapping entry : set) {
|
for (ClassMapping entry : set) {
|
||||||
if (matches(pattern, entry)) {
|
if (matches(pattern, entry)) {
|
||||||
|
@ -276,8 +256,7 @@ public class FinderCacheImpl
|
||||||
/**
|
/**
|
||||||
* Gets the elements of the given list which match the given pattern.
|
* Gets the elements of the given list which match the given pattern.
|
||||||
*/
|
*/
|
||||||
private Collection<String> getMatchedKeys(String pattern,
|
private Collection<String> getMatchedKeys(String pattern, Collection<String> coll) {
|
||||||
Collection<String> coll) {
|
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
for (String key : coll) {
|
for (String key : coll) {
|
||||||
if (matches(pattern, key)) {
|
if (matches(pattern, key)) {
|
||||||
|
@ -299,58 +278,39 @@ public class FinderCacheImpl
|
||||||
public boolean invalidate(ClassMapping mapping) {
|
public boolean invalidate(ClassMapping mapping) {
|
||||||
lock();
|
lock();
|
||||||
try {
|
try {
|
||||||
if (_log.isTraceEnabled())
|
|
||||||
_log.trace(_loc.get("finder-invalidate", mapping));
|
|
||||||
return _delegate.remove(mapping) != null;
|
return _delegate.remove(mapping) != null;
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(
|
public FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(ClassMapping mapping) {
|
||||||
ClassMapping mapping) {
|
|
||||||
return markUncachable(mapping.getDescribedType().getName());
|
return markUncachable(mapping.getDescribedType().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(
|
public FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(String id) {
|
||||||
String id) {
|
|
||||||
return markUncachable(id, EXLUDED_BY_USER);
|
return markUncachable(id, EXLUDED_BY_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(
|
private FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(String cls, String reason) {
|
||||||
String cls, String reason) {
|
|
||||||
lock();
|
lock();
|
||||||
try {
|
try {
|
||||||
boolean excludedByUser = _uncachables.get(cls) == EXLUDED_BY_USER;
|
boolean excludedByUser = _uncachables.get(cls) == EXLUDED_BY_USER;
|
||||||
if (!excludedByUser)
|
if (!excludedByUser)
|
||||||
_uncachables.put(cls, reason);
|
_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));
|
return _delegate.remove(searchMappingByName(cls));
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(
|
private FinderQuery<ClassMapping, SelectExecutor, Result> markUncachable(ClassMapping mapping, String reason) {
|
||||||
ClassMapping mapping, String reason) {
|
|
||||||
lock();
|
lock();
|
||||||
try {
|
try {
|
||||||
String cls = mapping.getDescribedType().getName();
|
String cls = mapping.getDescribedType().getName();
|
||||||
boolean excludedByUser = _uncachables.get(cls) == EXLUDED_BY_USER;
|
boolean excludedByUser = _uncachables.get(cls) == EXLUDED_BY_USER;
|
||||||
if (!excludedByUser)
|
if (!excludedByUser)
|
||||||
_uncachables.put(cls, reason);
|
_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);
|
return _delegate.remove(mapping);
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -411,10 +371,8 @@ public class FinderCacheImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfiguration(Configuration conf) {
|
public void setConfiguration(Configuration conf) {
|
||||||
_log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endConfiguration() {
|
public void endConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
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 \
|
uparam-missing: Parameter {0} in SQL Query "{1}" is not given a value. The \
|
||||||
parameters given is "{2}".
|
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 \
|
optimistic-violation-lock: An optimistic lock violation was detected when \
|
||||||
locking object instance.
|
locking object instance.
|
||||||
sql-warning: The statement resulted in SQL warning: {0}
|
sql-warning: The statement resulted in SQL warning: {0}
|
||||||
|
|
Loading…
Reference in New Issue