openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r935073 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/
Date Fri, 16 Apr 2010 20:35:42 GMT
Author: ppoddar
Date: Fri Apr 16 20:35:42 2010
New Revision: 935073

URL: http://svn.apache.org/viewvc?rev=935073&view=rev
Log:
OPENJPA-703: Disable query statistics by default.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java?rev=935073&r1=935072&r2=935073&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
Fri Apr 16 20:35:42 2010
@@ -57,7 +57,8 @@ public class PreparedQueryCacheImpl impl
 	// Key: Query identifier Value: Reason why excluded
 	private final Map<String, Exclusion> _uncachables;
 	private final List<Exclusion> _exclusionPatterns;
-	private final QueryStatistics<String> _stats;
+	private QueryStatistics<String> _stats;
+	private boolean _statsEnabled;
 	private ReentrantLock _lock = new ReentrantLock();
 	private Log _log;
     private static Localizer _loc = Localizer.forPackage(PreparedQueryCacheImpl.class);
@@ -65,7 +66,6 @@ public class PreparedQueryCacheImpl impl
 	public PreparedQueryCacheImpl() {
 		_delegate = new CacheMap();
 		_uncachables = new CacheMap();
-		_stats = new QueryStatistics.Default<String>();
 		_exclusionPatterns = new ArrayList<Exclusion>();
 	}
 	
@@ -316,6 +316,14 @@ public class PreparedQueryCacheImpl impl
         _delegate.clear();
         _stats.clear();
     }
+    
+    public void setEnableStatistics(boolean enable){
+        _statsEnabled = enable;
+    }
+    
+    public boolean getEnableStatistics(){
+        return _statsEnabled;
+    }
         
 	//-------------------------------------------------------
 	// Configurable contract
@@ -328,6 +336,8 @@ public class PreparedQueryCacheImpl impl
     }
 
     public void endConfiguration() {
+        _stats = _statsEnabled ? new QueryStatistics.Default<String>() :
+                                 new QueryStatistics.None<String>();
     }
     
     /**

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java?rev=935073&r1=935072&r2=935073&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java
Fri Apr 16 20:35:42 2010
@@ -196,7 +196,20 @@ public interface PreparedQueryCache exte
 	public void clear();
 	
 	/**
+	 * Enable/disable gathering of statistics.
+	 * 
+	 */
+    public void setEnableStatistics(boolean enable);
+    
+    /**
+     * Affirm if statistics is gathered.
+     * 
+     */
+    public boolean getEnableStatistics();
+    
+	/**
 	 * Gets the simple statistics for executed queries.
+	 * If the statistics gathering is disabled, an empty statistics is returned. 
 	 */
 	public QueryStatistics<String> getStatistics();
 	

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java?rev=935073&r1=935072&r2=935073&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
Fri Apr 16 20:35:42 2010
@@ -20,8 +20,8 @@ package org.apache.openjpa.kernel;
 
 import java.io.PrintStream;
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -268,4 +268,75 @@ public interface QueryStatistics<T> exte
             return row[READ] + ":" + row[HIT] + "(" + pct(row[HIT], row[READ]) + "%)";
 		}
 	}
-}
\ No newline at end of file
+	
+	/**
+	 * A do-nothing implementation.
+	 * 
+	 * @author Pinaki Poddar
+	 *
+	 * @param <T>
+	 */
+	public static class None<T> implements QueryStatistics<T> {
+        private Date start = new Date();
+        private Date since = start;
+
+        public void clear() {
+        }
+
+        public void dump(PrintStream out) {
+        }
+
+        public long getExecutionCount() {
+            return 0;
+        }
+
+        public long getExecutionCount(T query) {
+            return 0;
+        }
+
+        public long getHitCount() {
+            return 0;
+        }
+
+        public long getHitCount(T query) {
+            return 0;
+        }
+
+        public long getTotalExecutionCount() {
+            return 0;
+        }
+
+        public long getTotalExecutionCount(T query) {
+            return 0;
+        }
+
+        public long getTotalHitCount() {
+            return 0;
+        }
+
+        public long getTotalHitCount(T query) {
+            return 0;
+        }
+
+        public Set<T> keys() {
+            return Collections.emptySet();
+        }
+
+        public void recordExecution(T query) {
+        }
+
+        public void reset() {
+            start  = new Date();
+            since  = start;
+        }
+
+        public Date since() {
+            return since;
+        }
+
+        public Date start() {
+            return start;
+        }
+	}
+}
+

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java?rev=935073&r1=935072&r2=935073&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
Fri Apr 16 20:35:42 2010
@@ -109,7 +109,7 @@ public class TestPreparedQueryCache exte
             Properties config = new Properties();
             config.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true,SchemaAction='drop,add')");
             config.put("openjpa.jdbc.JDBCListeners", new JDBCListener[] { auditor = new SQLAuditor()});
-            config.put("openjpa.jdbc.QuerySQLCache", "true");
+            config.put("openjpa.jdbc.QuerySQLCache", "true(EnableStatistics=true)");
             config.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
             config.put("openjpa.DynamicEnhancementAgent", "false");
             emf = (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.createEntityManagerFactory(



Mime
View raw message