cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: QueryCacheEntryFactory type-safety: it now returns List instead of plain Object
Date Fri, 10 Feb 2017 13:27:54 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 478ebac32 -> 00551aa28


QueryCacheEntryFactory type-safety: it now returns List instead of plain Object


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/00551aa2
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/00551aa2
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/00551aa2

Branch: refs/heads/master
Commit: 00551aa28efcd29f49ff66594f4e3d7e6debad34
Parents: 478ebac
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Fri Feb 10 16:19:15 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Fri Feb 10 16:19:15 2017 +0300

----------------------------------------------------------------------
 .../apache/cayenne/CayenneContextQueryAction.java |  3 ++-
 .../cayenne/access/DataDomainQueryAction.java     |  4 ++--
 .../apache/cayenne/cache/EhCacheQueryCache.java   | 14 ++++----------
 .../org/apache/cayenne/cache/MapQueryCache.java   | 18 +++++-------------
 .../cayenne/cache/QueryCacheEntryFactory.java     |  4 +++-
 .../cayenne/util/ObjectContextQueryAction.java    |  7 +++----
 .../cayenne/cache/EhCacheQueryCacheTest.java      |  6 +++---
 .../cache/EhCacheQueryCache_WithConfigTest.java   |  2 +-
 8 files changed, 23 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
b/cayenne-server/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
index 2ce289f..e0b693c 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
@@ -21,6 +21,7 @@ package org.apache.cayenne;
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.cayenne.cache.QueryCacheEntryFactory;
 import org.apache.cayenne.map.EntityResolver;
@@ -61,7 +62,7 @@ class CayenneContextQueryAction extends ObjectContextQueryAction {
     protected QueryCacheEntryFactory getCacheObjectFactory() {
         return new QueryCacheEntryFactory() {
 
-            public Object createObject() {
+            public List createObject() {
                 if (interceptPaginatedQuery() != DONE) {
                     runQuery();
                 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
index 5e9e8bb..933d616 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
@@ -404,7 +404,7 @@ class DataDomainQueryAction implements QueryRouter, OperationObserver
{
         } else {
             // on cache-refresh request, fetch without blocking and fill the
             // cache
-            queryCache.put(metadata, (List) factory.createObject());
+            queryCache.put(metadata, factory.createObject());
         }
 
         return DONE;
@@ -414,7 +414,7 @@ class DataDomainQueryAction implements QueryRouter, OperationObserver
{
         return new QueryCacheEntryFactory() {
 
             @Override
-            public Object createObject() {
+            public List createObject() {
                 runQueryInTransaction();
 
                 List list = response.firstList();

http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
b/cayenne-server/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
index 0bd5b6c..4dfa1dd 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
@@ -120,19 +120,13 @@ public class EhCacheQueryCache implements QueryCache {
 
             // if not succeeded in reading again putting
             // object to the cache ourselves
-            Object object = factory.createObject();
-            if (!(object instanceof List)) {
-                if (object == null) {
-                    throw new CayenneRuntimeException("Null object created: " + metadata.getCacheKey());
-                } else {
-                    throw new CayenneRuntimeException("Invalid query result, expected List,
got "
-                            + object.getClass().getName());
-                }
+            List object = factory.createObject();
+            if (object == null) {
+                throw new CayenneRuntimeException("Null object created: " + metadata.getCacheKey());
             }
 
             cache.put(new Element(key, object));
-
-            return (List) object;
+            return object;
 
         } finally {
             cache.releaseWriteLockOnKey(key);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/main/java/org/apache/cayenne/cache/MapQueryCache.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/cache/MapQueryCache.java b/cayenne-server/src/main/java/org/apache/cayenne/cache/MapQueryCache.java
index 82f4ffa..de74b13 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/cache/MapQueryCache.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/cache/MapQueryCache.java
@@ -43,6 +43,7 @@ public class MapQueryCache implements QueryCache, Serializable {
         this(DEFAULT_CACHE_SIZE);
     }
 
+    @SuppressWarnings("unchecked")
     public MapQueryCache(int maxSize) {
         this.map = new LRUMap(maxSize);
     }
@@ -72,21 +73,12 @@ public class MapQueryCache implements QueryCache, Serializable {
     public List get(QueryMetadata metadata, QueryCacheEntryFactory factory) {
         List result = get(metadata);
         if (result == null) {
-            Object newObject = factory.createObject();
-
-            if (!(newObject instanceof List)) {
-                if (newObject == null) {
-                    throw new CayenneRuntimeException("Null on cache rebuilding: "
-                            + metadata.getCacheKey());
-                }
-                else {
-                    throw new CayenneRuntimeException(
-                            "Invalid query result, expected List, got "
-                                    + newObject.getClass().getName());
-                }
+            List newObject = factory.createObject();
+            if (newObject == null) {
+                throw new CayenneRuntimeException("Null on cache rebuilding: " + metadata.getCacheKey());
             }
 
-            result = (List) newObject;
+            result = newObject;
             put(metadata, result);
         }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/main/java/org/apache/cayenne/cache/QueryCacheEntryFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/cache/QueryCacheEntryFactory.java
b/cayenne-server/src/main/java/org/apache/cayenne/cache/QueryCacheEntryFactory.java
index 0e7dedb..8f74a1e 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/cache/QueryCacheEntryFactory.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/cache/QueryCacheEntryFactory.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.cache;
 
+import java.util.List;
+
 /**
  * A factory that is used by the cache to rebuild expired entries.
  * 
@@ -29,5 +31,5 @@ public interface QueryCacheEntryFactory {
      * Provides a fresh value of the cache entry. Normally this operation would perform a
      * database query. This operation must not return null.
      */
-    Object createObject();
+    List createObject();
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
b/cayenne-server/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
index 41f4a54..0db049b 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
@@ -348,10 +348,9 @@ public abstract class ObjectContextQueryAction {
             if (response == null) {
                 response = new ListResponse(cachedResults);
             }
-        }
-        else {
+        } else {
             // on cache-refresh request, fetch without blocking and fill the cache
-            queryCache.put(metadata, (List) factory.createObject());
+            queryCache.put(metadata, factory.createObject());
         }
 
         return DONE;
@@ -370,7 +369,7 @@ public abstract class ObjectContextQueryAction {
     protected QueryCacheEntryFactory getCacheObjectFactory() {
         return new QueryCacheEntryFactory() {
 
-            public Object createObject() {
+            public List createObject() {
                 executePostCache();
                 return response.firstList();
             }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
index e487dd7..eda8ee2 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
@@ -67,7 +67,7 @@ public class EhCacheQueryCacheTest {
 
         EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
 
-        Object[] lists = new Object[] { new ArrayList<Object>(), new ArrayList<Object>(),
new ArrayList<Object>() };
+        ArrayList[] lists = new ArrayList[] { new ArrayList<>(), new ArrayList<>(),
new ArrayList<>() };
         QueryCacheEntryFactory factory = mock(QueryCacheEntryFactory.class);
         when(factory.createObject()).thenReturn(lists[0], lists[1], lists[2]);
 
@@ -88,7 +88,7 @@ public class EhCacheQueryCacheTest {
 
         EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
 
-        Object[] lists = new Object[] { new ArrayList<Object>(), new ArrayList<Object>(),
new ArrayList<Object>() };
+        ArrayList[] lists = new ArrayList[] { new ArrayList<>(), new ArrayList<>(),
new ArrayList<>() };
         QueryCacheEntryFactory factory = mock(QueryCacheEntryFactory.class);
         when(factory.createObject()).thenReturn(lists[0], lists[1], lists[2]);
 
@@ -110,7 +110,7 @@ public class EhCacheQueryCacheTest {
 
         EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
 
-        Object[] lists = new Object[] { new ArrayList<Object>(), new ArrayList<Object>(),
new ArrayList<Object>() };
+        ArrayList[] lists = new ArrayList[] { new ArrayList<>(), new ArrayList<>(),
new ArrayList<>() };
         QueryCacheEntryFactory factory = mock(QueryCacheEntryFactory.class);
         when(factory.createObject()).thenReturn(lists[0], lists[1], lists[2]);
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/00551aa2/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
index 964abd0..48569a9 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
@@ -55,7 +55,7 @@ public class EhCacheQueryCache_WithConfigTest {
 
         EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
 
-        Object[] lists = new Object[] { new ArrayList<Object>(), new ArrayList<Object>(),
new ArrayList<Object>() };
+        ArrayList[] lists = new ArrayList[] { new ArrayList<>(), new ArrayList<>(),
new ArrayList<>() };
         QueryCacheEntryFactory factory = mock(QueryCacheEntryFactory.class);
         when(factory.createObject()).thenReturn(lists[0], lists[1], lists[2]);
 


Mime
View raw message