cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [4/7] cayenne git commit: CAY-2352 Clean up build scripts and code to support Java 8 use Java 8 Function in cache-invalication module
Date Mon, 21 Aug 2017 09:49:13 GMT
CAY-2352 Clean up build scripts and code to support Java 8
   use Java 8 Function in cache-invalication module


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

Branch: refs/heads/master
Commit: b425e5010e3272f1d60890a9103330d6fe833897
Parents: 2bcefc2
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Fri Aug 18 15:24:39 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Fri Aug 18 15:24:39 2017 +0300

----------------------------------------------------------------------
 .../invalidation/CacheGroupDescriptor.java      |  2 +-
 .../cache/invalidation/CacheGroupsHandler.java  | 10 ++----
 .../invalidation/CacheInvalidationFilter.java   | 16 ++++------
 .../CacheInvalidationModuleExtender.java        | 32 +++++++++-----------
 .../invalidation/InvalidationFunction.java      |  5 ++-
 .../cache/invalidation/InvalidationHandler.java |  5 ++-
 .../invalidation/CacheGroupsHandlerTest.java    |  6 ++--
 .../CacheInvalidationCustomHandlerIT.java       | 10 ++----
 8 files changed, 40 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupDescriptor.java
b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupDescriptor.java
index 4234da1..2008c6e 100644
--- a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupDescriptor.java
+++ b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupDescriptor.java
@@ -21,7 +21,7 @@ package org.apache.cayenne.cache.invalidation;
 
 /**
  * Immutable object describing cache group.
- * Used as a result in {@link InvalidationFunction}.
+ * Used as a result in invalidation function.
  *
  * @see CacheGroupDescriptor#CacheGroupDescriptor(String)
  * @see CacheGroupDescriptor#CacheGroupDescriptor(String, Class, Class)

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandler.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandler.java
b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandler.java
index 269f249..009ae4e 100644
--- a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandler.java
+++ b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandler.java
@@ -23,6 +23,7 @@ import org.apache.cayenne.Persistent;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.function.Function;
 
 /**
  * @since 4.0
@@ -37,7 +38,7 @@ public class CacheGroupsHandler implements InvalidationHandler {
      * of {@link CacheGroups} and {@link CacheGroup} annotations for the given type.
      */
     @Override
-    public InvalidationFunction canHandle(Class<? extends Persistent> type) {
+    public Function<Persistent, Collection<CacheGroupDescriptor>> canHandle(Class<?
extends Persistent> type) {
 
         CacheGroup multipleCacheGroups = type.getAnnotation(CacheGroup.class);
         CacheGroups cacheGroups = type.getAnnotation(CacheGroups.class);
@@ -49,12 +50,7 @@ public class CacheGroupsHandler implements InvalidationHandler {
         extractCacheGroups(cacheGroups, groupsList);
         extractCacheGroups(multipleCacheGroups, groupsList);
 
-        return new InvalidationFunction() {
-            @Override
-            public Collection<CacheGroupDescriptor> apply(Persistent persistent) {
-                return groupsList;
-            }
-        };
+        return p -> groupsList;
     }
 
     private void extractCacheGroups(CacheGroup cacheGroup, Collection<CacheGroupDescriptor>
groupsList) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java
b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java
index beb3b95..85063e7 100644
--- a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java
+++ b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java
@@ -41,6 +41,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
 
 /**
  * <p>
@@ -65,18 +66,13 @@ public class CacheInvalidationFilter implements DataChannelFilter {
 
     private final Provider<QueryCache> cacheProvider;
     private final List<InvalidationHandler> handlers;
-    private final Map<Class<? extends Persistent>, InvalidationFunction> mappedHandlers;
-    private final InvalidationFunction skipHandler;
+    private final Map<Class<? extends Persistent>, Function<Persistent, Collection<CacheGroupDescriptor>>>
mappedHandlers;
+    private final Function<Persistent, Collection<CacheGroupDescriptor>> skipHandler;
     private final ThreadLocal<Set<CacheGroupDescriptor>> groups;
 
     public CacheInvalidationFilter(@Inject Provider<QueryCache> cacheProvider, @Inject
List<InvalidationHandler> handlers) {
         this.mappedHandlers = new ConcurrentHashMap<>();
-        this.skipHandler = new InvalidationFunction() {
-            @Override
-            public Collection<CacheGroupDescriptor> apply(Persistent p) {
-                return Collections.emptyList();
-            }
-        };
+        this.skipHandler = p -> Collections.emptyList();
         this.groups = new ThreadLocal<>();
         this.cacheProvider = cacheProvider;
         this.handlers = handlers;
@@ -122,11 +118,11 @@ public class CacheInvalidationFilter implements DataChannelFilter {
         // TODO: for some reason we can't use Persistent as the argument type... (is it fixed
in Cayenne 4.0.M4?)
         Persistent p = (Persistent) object;
 
-        InvalidationFunction invalidationFunction = mappedHandlers.get(p.getClass());
+        Function<Persistent, Collection<CacheGroupDescriptor>> invalidationFunction
= mappedHandlers.get(p.getClass());
         if (invalidationFunction == null) {
             invalidationFunction = skipHandler;
             for (InvalidationHandler handler : handlers) {
-                InvalidationFunction function = handler.canHandle(p.getClass());
+                Function<Persistent, Collection<CacheGroupDescriptor>> function
= handler.canHandle(p.getClass());
                 if (function != null) {
                     invalidationFunction = function;
                     break;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationModuleExtender.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationModuleExtender.java
b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationModuleExtender.java
index 1a28329..639bdc4 100644
--- a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationModuleExtender.java
+++ b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationModuleExtender.java
@@ -26,6 +26,7 @@ import org.apache.cayenne.di.Module;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.function.Function;
 
 /**
  * @since 4.0
@@ -61,27 +62,24 @@ public class CacheInvalidationModuleExtender {
     }
 
     public Module module() {
-        return new Module() {
-            @Override
-            public void configure(Binder binder) {
+        return binder -> {
 
-                if (noCacheGroupsHandler) {
-                    // replace CacheGroupsHandler with a dummy no op handler
-                    binder.bind(CacheGroupsHandler.class).toInstance(new CacheGroupsHandler()
{
-                        @Override
-                        public InvalidationFunction canHandle(Class<? extends Persistent>
type) {
-                            return null;
-                        }
-                    });
-                }
+            if (noCacheGroupsHandler) {
+                // replace CacheGroupsHandler with a dummy no op handler
+                binder.bind(CacheGroupsHandler.class).toInstance(new CacheGroupsHandler()
{
+                    @Override
+                    public Function<Persistent, Collection<CacheGroupDescriptor>>
canHandle(Class<? extends Persistent> type) {
+                        return null;
+                    }
+                });
+            }
 
-                ListBuilder<InvalidationHandler> handlers = CacheInvalidationModule.contributeInvalidationHandler(binder);
+            ListBuilder<InvalidationHandler> handlers = CacheInvalidationModule.contributeInvalidationHandler(binder);
 
-                handlers.addAll(handlerInstances);
+            handlers.addAll(handlerInstances);
 
-                for (Class<? extends InvalidationHandler> handlerType : handlerTypes)
{
-                    handlers.add(handlerType);
-                }
+            for (Class<? extends InvalidationHandler> handlerType : handlerTypes) {
+                handlers.add(handlerType);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationFunction.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationFunction.java
b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationFunction.java
index c748e80..96f2db9 100644
--- a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationFunction.java
+++ b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationFunction.java
@@ -22,11 +22,14 @@ package org.apache.cayenne.cache.invalidation;
 import org.apache.cayenne.Persistent;
 
 import java.util.Collection;
+import java.util.function.Function;
 
 /**
  * @since 4.0
+ * @deprecated since 4.1 plain Function&gt;Persistent, Collection&gt;CacheGroupDescriptor>>
can be used.
  */
-public interface InvalidationFunction {
+@Deprecated
+public interface InvalidationFunction extends Function<Persistent, Collection<CacheGroupDescriptor>>
{
 
     /**
      * @return collection of cache groups to invalidate for given object

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationHandler.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationHandler.java
b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationHandler.java
index 7b43e0b..0f54b12 100644
--- a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationHandler.java
+++ b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/InvalidationHandler.java
@@ -19,6 +19,9 @@
 
 package org.apache.cayenne.cache.invalidation;
 
+import java.util.Collection;
+import java.util.function.Function;
+
 import org.apache.cayenne.Persistent;
 
 /**
@@ -30,6 +33,6 @@ public interface InvalidationHandler {
     /**
      * @return invalidation function or null if there is nothing to invalidate
      */
-    InvalidationFunction canHandle(Class<? extends Persistent> type);
+    Function<Persistent, Collection<CacheGroupDescriptor>> canHandle(Class<?
extends Persistent> type);
 
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandlerTest.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandlerTest.java
b/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandlerTest.java
index d3eb7b8..e87db5b 100644
--- a/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandlerTest.java
+++ b/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheGroupsHandlerTest.java
@@ -21,7 +21,9 @@ package org.apache.cayenne.cache.invalidation;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.function.Function;
 
+import org.apache.cayenne.Persistent;
 import org.apache.cayenne.cache.invalidation.db.E1;
 import org.apache.cayenne.cache.invalidation.db.E2;
 import org.junit.Test;
@@ -36,7 +38,7 @@ public class CacheGroupsHandlerTest {
     @Test
     public void canHandleE1() throws Exception {
         CacheGroupsHandler handler = new  CacheGroupsHandler();
-        InvalidationFunction function = handler.canHandle(E1.class);
+        Function<Persistent, Collection<CacheGroupDescriptor>> function = handler.canHandle(E1.class);
         Collection<CacheGroupDescriptor> result = function.apply(null);
 
         assertEquals(2, result.size());
@@ -52,7 +54,7 @@ public class CacheGroupsHandlerTest {
     @Test
     public void canHandleE2() throws Exception {
         CacheGroupsHandler handler = new  CacheGroupsHandler();
-        InvalidationFunction function = handler.canHandle(E2.class);
+        Function<Persistent, Collection<CacheGroupDescriptor>> function = handler.canHandle(E2.class);
         Collection<CacheGroupDescriptor> result = function.apply(null);
 
         assertEquals(6, result.size());

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b425e501/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheInvalidationCustomHandlerIT.java
----------------------------------------------------------------------
diff --git a/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheInvalidationCustomHandlerIT.java
b/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheInvalidationCustomHandlerIT.java
index 0ccb3db..f11238d 100644
--- a/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheInvalidationCustomHandlerIT.java
+++ b/cayenne-cache-invalidation/src/test/java/org/apache/cayenne/cache/invalidation/CacheInvalidationCustomHandlerIT.java
@@ -28,6 +28,7 @@ import org.junit.Test;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.function.Function;
 
 import static org.junit.Assert.assertEquals;
 
@@ -84,13 +85,8 @@ public class CacheInvalidationCustomHandlerIT extends CacheInvalidationCase
{
 
     public static class G1InvalidationHandler implements InvalidationHandler {
         @Override
-        public InvalidationFunction canHandle(Class<? extends Persistent> type) {
-            return new InvalidationFunction() {
-                @Override
-                public Collection<CacheGroupDescriptor> apply(Persistent persistent)
{
-                    return Collections.singleton(new CacheGroupDescriptor("g1"));
-                }
-            };
+        public Function<Persistent, Collection<CacheGroupDescriptor>> canHandle(Class<?
extends Persistent> type) {
+            return p -> Collections.singleton(new CacheGroupDescriptor("g1"));
         }
     }
 }


Mime
View raw message