diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java index 5026c4ef8..9bee222bd 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java @@ -57,7 +57,7 @@ public class PreparedQueryCacheImpl implements PreparedQueryCache { // Key: Query identifier Value: Reason why excluded private final Map _uncachables; private List _exclusionPatterns; - private final QueryStatistics _stats; + private final QueryStatistics _stats; private ReentrantLock _lock = new ReentrantLock(); private Log _log; private Localizer _loc = Localizer.forPackage(PreparedQueryCacheImpl.class); @@ -65,7 +65,7 @@ public class PreparedQueryCacheImpl implements PreparedQueryCache { public PreparedQueryCacheImpl() { _delegate = new HashMap(); _uncachables = new HashMap(); - _stats = new QueryStatistics.Default(); + _stats = new QueryStatistics.Default(); } public Boolean register(String id, Query query, FetchConfiguration hints) { @@ -264,7 +264,7 @@ public class PreparedQueryCacheImpl implements PreparedQueryCache { } } - public QueryStatistics getStatistics() { + public QueryStatistics getStatistics() { return _stats; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java index c9ad36d0a..ebd31c0d1 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PreparedQueryCache.java @@ -188,5 +188,5 @@ public interface PreparedQueryCache extends Configurable { /** * Gets the simple statistics for executed queries. */ - public QueryStatistics getStatistics(); + public QueryStatistics getStatistics(); } \ No newline at end of file diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java index d8145627a..c54d16016 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java @@ -37,13 +37,13 @@ import java.util.Map; * @author Pinaki Poddar * */ -public interface QueryStatistics extends Serializable { +public interface QueryStatistics extends Serializable { /** * Record that the given query has been executed. The boolean parameter * designates whether the executed query is a cached version. */ - void recordExecution(String query, boolean cached); + void recordExecution(T query, boolean cached); /** * Gets number of total query execution since last reset. @@ -58,12 +58,12 @@ public interface QueryStatistics extends Serializable { /** * Gets number of executions for the given query since last reset. */ - public long getExecutionCount(String query); + public long getExecutionCount(T query); /** * Gets number of executions for the given query since start. */ - public long getTotalExecutionCount(String query); + public long getTotalExecutionCount(T query); /** * Gets number of total query execution that are cached since last reset. @@ -79,13 +79,13 @@ public interface QueryStatistics extends Serializable { * Gets number of executions for the given query that are cached since * last reset. */ - public long getHitCount(String query); + public long getHitCount(T query); /** * Gets number of executions for the given query that are cached since * start. */ - public long getTotalHitCount(String query); + public long getTotalHitCount(T query); /** * Gets the time of last reset. @@ -111,12 +111,12 @@ public interface QueryStatistics extends Serializable { * A default implementation. * */ - public static class Default implements QueryStatistics { + public static class Default implements QueryStatistics { private static final int ARRAY_SIZE = 2; private long[] astat = new long[ARRAY_SIZE]; private long[] stat = new long[ARRAY_SIZE]; - private Map stats = new HashMap(); - private Map astats = new HashMap(); + private Map stats = new HashMap(); + private Map astats = new HashMap(); private Date start = new Date(); private Date since = start; @@ -131,11 +131,11 @@ public interface QueryStatistics extends Serializable { return astat[READ]; } - public long getExecutionCount(String query) { + public long getExecutionCount(T query) { return getCount(stats, query, READ); } - public long getTotalExecutionCount(String query) { + public long getTotalExecutionCount(T query) { return getCount(astats, query, READ); } @@ -147,15 +147,15 @@ public interface QueryStatistics extends Serializable { return astat[HIT]; } - public long getHitCount(String query) { + public long getHitCount(T query) { return getCount(stats, query, HIT); } - public long getTotalHitCount(String query) { + public long getTotalHitCount(T query) { return getCount(astats, query, HIT); } - private long getCount(Map target, String query, int i) { + private long getCount(Map target, T query, int i) { long[] row = target.get(query); return (row == null) ? 0 : row[i]; } @@ -174,14 +174,14 @@ public interface QueryStatistics extends Serializable { since = new Date(); } - private void addSample(String query, int index) { + private void addSample(T query, int index) { stat[index]++; astat[index]++; addSample(stats, query, index); addSample(astats, query, index); } - private void addSample(Map target, String query, int i) { + private void addSample(Map target, T query, int i) { long[] row = target.get(query); if (row == null) { row = new long[ARRAY_SIZE]; @@ -190,7 +190,7 @@ public interface QueryStatistics extends Serializable { target.put(query, row); } - public void recordExecution(String query, boolean cached) { + public void recordExecution(T query, boolean cached) { addSample(query, READ); if (cached) addSample(query, HIT); @@ -210,7 +210,7 @@ public interface QueryStatistics extends Serializable { out.println("\tSince Start \tSince Reset \t\tQuery"); } int i = 0; - for (String key : stats.keySet()) { + for (T key : stats.keySet()) { i++; long[] arow = astats.get(key); if (since == start) { diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java index d0afa93bd..1fe5b7ad9 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java @@ -587,7 +587,7 @@ public class QueryImpl implements OpenJPAQuerySPI, Serializable { Boolean registered = cache.register(_id, _query, fetch); boolean alreadyCached = (registered == null); String lang = _query.getLanguage(); - QueryStatistics stats = cache.getStatistics(); + QueryStatistics stats = cache.getStatistics(); if (alreadyCached && LANG_PREPARED_SQL.equals(lang)) { PreparedQuery pq = _em.getPreparedQuery(_id); if (pq.isInitialized()) {