openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r695021 - in /openjpa/branches/sql-cache/openjpa-kernel/src/main: java/org/apache/openjpa/kernel/PreparedQueryCacheImpl.java resources/org/apache/openjpa/kernel/localizer.properties
Date Sat, 13 Sep 2008 20:08:53 GMT
Author: ppoddar
Date: Sat Sep 13 13:08:52 2008
New Revision: 695021

URL: http://svn.apache.org/viewvc?rev=695021&view=rev
Log:
Add logging to PreparedQueryCache

Modified:
    openjpa/branches/sql-cache/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCacheImpl.java
    openjpa/branches/sql-cache/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties

Modified: openjpa/branches/sql-cache/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCacheImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/sql-cache/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCacheImpl.java?rev=695021&r1=695020&r2=695021&view=diff
==============================================================================
--- openjpa/branches/sql-cache/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCacheImpl.java
(original)
+++ openjpa/branches/sql-cache/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCacheImpl.java
Sat Sep 13 13:08:52 2008
@@ -28,7 +28,11 @@
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.log.LogFactory;
+import org.apache.openjpa.lib.util.Localizer;
 
 /**
  * An implementation of the cache of {@link PreparedQuery prepared queries}. 
@@ -41,7 +45,7 @@
 public class PreparedQueryCacheImpl implements PreparedQueryCache {
 	private static final String PATTERN_SEPARATOR = "\\;";
 	private static final String EXLUDED_BY_USER = "Excluded by user";
-	
+
 	// Key: Query identifier 
 	private final Map<String, PreparedQuery> _delegate;
 	// Key: Query identifier Value: Reason why excluded
@@ -49,6 +53,8 @@
 	private List<String> _exclusionPatterns;
 	private final QueryStatistics _stats;
 	private ReentrantLock _lock = new ReentrantLock();
+	private Log _log;
+	private Localizer _loc = Localizer.forPackage(PreparedQueryCacheImpl.class);
 
 	public PreparedQueryCacheImpl() {
 		_delegate = new HashMap<String, PreparedQuery>();
@@ -78,13 +84,19 @@
 		lock();
 		try {
 			String id = q.getIdentifier();
-			if (isCachable(id) == Boolean.FALSE)
+			if (isCachable(id) == Boolean.FALSE) {
+				if (_log.isWarnEnabled())
+					_log.warn(_loc.get("prepared-query-not-cachable", id));
 				return false;
+			}
 			String pattern = getMatchedExclusionPattern(id);
 			if (pattern != null) {
 				markUncachable(q.getIdentifier(), pattern);
 				return false;
 			}
+			if (_log.isTraceEnabled())
+				_log.trace(_loc.get("prepared-query-cache", q.getIdentifier(), 
+					q.getDatastoreAction()));
 			_delegate.put(q.getIdentifier(), q);
 			return true;
 		} finally {
@@ -95,6 +107,8 @@
 	public boolean invalidate(String id) {
 		lock();
 		try {
+			if (_log.isTraceEnabled())
+				_log.trace(_loc.get("prepared-query-invalidate", id));
 			return _delegate.remove(id) != null;
 		} finally {
 			unlock();
@@ -127,11 +141,19 @@
 		return markUncachable(id, EXLUDED_BY_USER);
 	}
 	
-	private PreparedQuery markUncachable(String id, String pattern) {
+	private PreparedQuery markUncachable(String id, String reason) {
 		lock();
 		try {
-			if (_uncachables.get(id) != EXLUDED_BY_USER)
-				_uncachables.put(id, pattern);
+			boolean excludedByUser = _uncachables.get(id) == EXLUDED_BY_USER;
+			if (!excludedByUser)
+				_uncachables.put(id, reason);
+			if (_log.isInfoEnabled()) {
+				if (excludedByUser) 
+					_log.info(_loc.get("prepared-query-uncache-strong", id));
+				else 
+					_log.info(_loc.get("prepared-query-uncache-weak", id, 
+						reason));
+			}
 			return _delegate.remove(id);
 		} finally {
 			unlock();
@@ -174,6 +196,9 @@
 			_exclusionPatterns.add(pattern);
 			Collection<String> invalidKeys = getMatchedKeys(pattern, 
 					_delegate.keySet());
+			if (!invalidKeys.isEmpty() && _log.isInfoEnabled())
+				_log.info(_loc.get("prepared-query-add-pattern", pattern, 
+					invalidKeys.size(), invalidKeys));
 			for (String invalidKey : invalidKeys)
 				markUncachable(invalidKey, pattern);
 		} finally {
@@ -192,8 +217,11 @@
 			if (_exclusionPatterns == null)
 				return;
 			_exclusionPatterns.remove(pattern);
-			Collection<String> rebornKeys = getMatchedKeys(pattern, _uncachables);
-			for (String rebornKey : rebornKeys)
+			Collection<String> reborns = getMatchedKeys(pattern, _uncachables);
+			if (!reborns.isEmpty() && _log.isInfoEnabled())
+				_log.info(_loc.get("prepared-query-remove-pattern", pattern, 
+					reborns.size(), reborns));
+			for (String rebornKey : reborns)
 				_uncachables.remove(rebornKey);
 		} finally {
 			unlock();
@@ -268,6 +296,7 @@
 	// Configurable contract
 	//-------------------------------------------------------
     public void setConfiguration(Configuration conf) {
+    	_log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
     }
 
     public void startConfiguration() {

Modified: openjpa/branches/sql-cache/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/sql-cache/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties?rev=695021&r1=695020&r2=695021&view=diff
==============================================================================
--- openjpa/branches/sql-cache/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
(original)
+++ openjpa/branches/sql-cache/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
Sat Sep 13 13:08:52 2008
@@ -404,4 +404,17 @@
 	bound parameters with following values "{3}". This can happen if you have \
 	declared but missed to bind values for one or more parameters.
 query-execution-error: Failed to execute query "{0}". Check the query syntax \
-	for correctness. See nested exception for details. 
\ No newline at end of file
+	for correctness. See nested exception for details. 
+prepared-query-cache: Adding query "{0}" to prepared query cache. The target \
+	database query is "{1}".
+prepared-query-not-cachable: Query "{0}" can not be cached.
+prepared-query-invalidate: Prepared Query "{0}" is invalidated 
+prepared-query-uncache-strong: Query "{0}" is marked permanently not to be \
+	cached.   
+prepared-query-uncache-weak: Query "{0}" is marked not to be cached because it \
+	matched exclusion pattern "{1}". This query can be cached if the exclusion \
+	pattern is removed later.
+prepared-query-add-pattern: Added exclusion pattern "{0}" which has removed \
+	following {1} prepared queries from the cache: "{2}"
+prepared-query-remove-pattern: Removed exclusion pattern "{0}" which has made \
+	following {1} queries again possible to be cached: "{2}"
\ No newline at end of file



Mime
View raw message