This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 57dc852  ISIS-1827 RepositoryService: split out deprecated methods
57dc852 is described below

commit 57dc852ad4892e4a007049d76e64acaf57e185bd
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Wed Feb 21 09:59:16 2018 +0100

    ISIS-1827 RepositoryService: split out deprecated methods
    
    With Isis 2.0 we'll break backward compatibility with
    o.a.i.applib.services.repository.RepositoryService
    
    To ease transition from Isis 1.x to 2.x for users, we'll provide a new
    o.a.i.applib.services.repository.RepositoryServiceLegacy as a drop-in
    replacement, that preserves deprecated usage.
---
 .../services/repository/RepositoryService.java     | 47 -------------------
 ...ryService.java => RepositoryServiceLegacy.java} | 33 ++++---------
 .../RepositoryServiceInternalDefault.java          | 54 ----------------------
 ...=> RepositoryServiceLegacyInternalDefault.java} | 34 ++++----------
 4 files changed, 18 insertions(+), 150 deletions(-)

diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
 
b/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
index e0961e4..eb01160 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
@@ -147,13 +147,6 @@ public interface RepositoryService {
     <T> List<T> allMatches(final Class<T> ofType, final Predicate<? super T> 
predicate, long... range);
     
     /**
-     * @deprecated will be removed, use drop in replacement {@link 
#allMatches(Class, Predicate, long...)}
-     * utilizing java.util.function.Predicate 
-     */
-    @Programmatic @Deprecated //TODO ISIS-1827 remove guava from public API
-    <T> List<T> allMatches(final Class<T> ofType, final 
com.google.common.base.Predicate<? super T> predicate, long... range);
-    
-    /**
      * Returns all the instances that match the given {@link Query}.
      *
      * <p>
@@ -171,38 +164,6 @@ public interface RepositoryService {
     <T> List<T> allMatches(Query<T> query);
 
     /**
-     * Returns the first instance of the specified type (including subtypes)
-     * that matches the supplied {@link Predicate}, or <tt>null</tt> if none.
-     *
-     * <p>
-     * This method is useful during exploration/prototyping, but - because the 
filtering is performed client-side -
-     * this method is only really suitable for initial 
development/prototyping, or for classes with very few
-     * instances.  Use {@link #firstMatch(Query)} for production code.
-     * </p>
-     *
-     * @deprecated - use {@link #uniqueMatch(Class, Predicate)} or {@link 
#allMatches(Class, Predicate, long...)}
-     */
-    @Deprecated //TODO ISIS-1827 remove guava from public API 
-    @Programmatic 
-    <T> T firstMatch(final Class<T> ofType, final 
com.google.common.base.Predicate<T> predicate);
-
-    /**
-     * Returns the first instance that matches the supplied query, or 
<tt>null</tt> if none.
-     *
-     * <p>
-     *     This method is the recommended way of querying for an instance when 
one or more may match.  See also
-     *     {@link #uniqueMatch(Query)}.
-     * </p>
-     *
-     * @see #uniqueMatch(Query)
-     *
-     * @deprecated - use {@link #uniqueMatch(Query)} or {@link 
#allMatches(Query)}.
-     */
-    @Deprecated
-    @Programmatic
-    <T> T firstMatch(Query<T> query);
-
-    /**
      * Find the only instance of the specified type (including subtypes) that
      * has the specified title.
      *
@@ -220,14 +181,6 @@ public interface RepositoryService {
     <T> T uniqueMatch(final Class<T> ofType, final Predicate<T> predicate);
     
     /**
-     * @deprecated will be removed, use drop in replacement {@link 
#uniqueMatch(Class, Predicate)}
-     * utilizing java.util.function.Predicate 
-     */
-    @Programmatic @Deprecated //TODO ISIS-1827 remove guava from public API 
-    <T> T uniqueMatch(final Class<T> ofType, final 
com.google.common.base.Predicate<T> predicate);
-
-
-    /**
      * Find the only instance that matches the provided query.
      *
      * <p>
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
 
b/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryServiceLegacy.java
similarity index 90%
copy from 
core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
copy to 
core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryServiceLegacy.java
index e0961e4..c3b4e3d 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryServiceLegacy.java
@@ -20,12 +20,19 @@
 package org.apache.isis.applib.services.repository;
 
 import java.util.List;
-import java.util.function.Predicate;
 
 import org.apache.isis.applib.annotation.Programmatic;
 import org.apache.isis.applib.query.Query;
 
-public interface RepositoryService {
+/**
+ * Legacy interface to ease transition from Isis 1.x to 2.x.
+ * 
+ * @deprecated use {@link RepositoryService} instead. 
+ * (Requires you to refactor Guava Predicates to Java Predicates in your 
domain code.)
+ * 
+ */
+@Deprecated
+public interface RepositoryServiceLegacy {
 
     /**
      * Normally any queries are automatically preceded by flushing pending 
executions.
@@ -142,11 +149,6 @@ public interface RepositoryService {
      * @see #allMatches(Class, Predicate, long...)
      *
      * @param range 2 longs, specifying 0-based start and count.
-     */
-    @Programmatic
-    <T> List<T> allMatches(final Class<T> ofType, final Predicate<? super T> 
predicate, long... range);
-    
-    /**
      * @deprecated will be removed, use drop in replacement {@link 
#allMatches(Class, Predicate, long...)}
      * utilizing java.util.function.Predicate 
      */
@@ -201,23 +203,6 @@ public interface RepositoryService {
     @Deprecated
     @Programmatic
     <T> T firstMatch(Query<T> query);
-
-    /**
-     * Find the only instance of the specified type (including subtypes) that
-     * has the specified title.
-     *
-     * <p>
-     * If no instance is found then <tt>null</tt> will be return, while if 
there
-     * is more that one instances a run-time exception will be thrown.
-     *
-     * <p>
-     * This method is useful during exploration/prototyping, but - because the 
filtering is performed client-side -
-     * this method is only really suitable for initial 
development/prototyping, or for classes with very few
-     * instances.  Use {@link #uniqueMatch(Query)} for production code.
-     * </p>
-     */
-    @Programmatic
-    <T> T uniqueMatch(final Class<T> ofType, final Predicate<T> predicate);
     
     /**
      * @deprecated will be removed, use drop in replacement {@link 
#uniqueMatch(Class, Predicate)}
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
index 0242a5e..9152d6a 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
@@ -150,19 +150,6 @@ public class RepositoryServiceInternalDefault implements 
RepositoryService {
     // //////////////////////////////////////
 
     @Programmatic
-    @Override
-    public <T> List<T> allMatches(final Class<T> cls, final 
com.google.common.base.Predicate<? super T> predicate, long... range) {
-        final List<T> allInstances = allInstances(cls, range);
-        final List<T> filtered = new ArrayList<T>();
-        for (final T instance : allInstances) {
-            if (predicate.apply(instance)) {
-                filtered.add(instance);
-            }
-        }
-        return filtered;
-    }
-    
-    @Programmatic
        @Override
        public <T> List<T> allMatches(Class<T> ofType, final Predicate<? super 
T> predicate, long... range) {
                return _NullSafe.stream(allInstances(ofType, range))
@@ -170,7 +157,6 @@ public class RepositoryServiceInternalDefault implements 
RepositoryService {
                                
.collect(Collectors.toCollection(ArrayList::new));
        }
 
-
     @Programmatic
     @Override
     public <T> List<T> allMatches(final Query<T> query) {
@@ -188,17 +174,6 @@ public class RepositoryServiceInternalDefault implements 
RepositoryService {
 
     // //////////////////////////////////////
 
-
-    @Programmatic
-    @Override
-    public <T> T uniqueMatch(final Class<T> type, final 
com.google.common.base.Predicate<T> predicate) {
-        final List<T> instances = allMatches(type, predicate, 0, 2); // No 
need to fetch more than 2.
-        if (instances.size() > 1) {
-            throw new RepositoryException("Found more than one instance of " + 
type + " matching filter " + predicate);
-        }
-        return firstInstanceElseNull(instances);
-    }
-    
     @Programmatic
     @Override
     public <T> T uniqueMatch(final Class<T> type, final Predicate<T> 
predicate) {
@@ -220,37 +195,8 @@ public class RepositoryServiceInternalDefault implements 
RepositoryService {
         return firstInstanceElseNull(instances);
     }
 
-
-    // //////////////////////////////////////
-
-
-    @Programmatic
-    @Override
-    public <T> T firstMatch(final Class<T> cls, final 
com.google.common.base.Predicate<T> predicate) {
-        final List<T> allInstances = allInstances(cls); // Have to fetch all, 
as matching is done in next loop
-        for (final T instance : allInstances) {
-            if (predicate.apply(instance)) {
-                return instance;
-            }
-        }
-        return null;
-    }
-
-    @Programmatic
-    @Override
-    @SuppressWarnings("unchecked")
-    public <T> T firstMatch(final Query<T> query) {
-        if(autoFlush) {
-            transactionService.flushTransaction();
-        }
-        final ObjectAdapter firstMatching = 
persistenceSessionServiceInternal.firstMatchingQuery(query);
-        return (T) ObjectAdapter.Util.unwrap(firstMatching);
-    }
-
-
     // //////////////////////////////////////
 
-
     private static <T> T firstInstanceElseNull(final List<T> instances) {
         return instances.size() == 0 ? null : instances.get(0);
     }
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceLegacyInternalDefault.java
similarity index 91%
copy from 
core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
copy to 
core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceLegacyInternalDefault.java
index 0242a5e..3d8cd06 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceLegacyInternalDefault.java
@@ -22,12 +22,11 @@ package org.apache.isis.core.metamodel.services.repository;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-
-import javax.annotation.PostConstruct;
-
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
+import javax.annotation.PostConstruct;
+
 import org.apache.isis.applib.PersistFailedException;
 import org.apache.isis.applib.RepositoryException;
 import org.apache.isis.applib.annotation.DomainService;
@@ -37,17 +36,22 @@ import org.apache.isis.applib.internal.base._NullSafe;
 import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.query.QueryFindAllInstances;
 import org.apache.isis.applib.services.factory.FactoryService;
-import org.apache.isis.applib.services.repository.RepositoryService;
+import org.apache.isis.applib.services.repository.RepositoryServiceLegacy;
 import org.apache.isis.applib.services.wrapper.WrapperFactory;
 import org.apache.isis.applib.services.xactn.TransactionService;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import 
org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
 
+/**
+ * 
+ * Legacy Service default implementation to ease transition from Isis 1.x to 
2.x.
+ *
+ */
 @DomainService(
         nature = NatureOfService.DOMAIN,
         menuOrder = "" + Integer.MAX_VALUE
 )
-public class RepositoryServiceInternalDefault implements RepositoryService {
+public class RepositoryServiceLegacyInternalDefault implements 
RepositoryServiceLegacy {
 
     private boolean autoFlush;
 
@@ -163,15 +167,6 @@ public class RepositoryServiceInternalDefault implements 
RepositoryService {
     }
     
     @Programmatic
-       @Override
-       public <T> List<T> allMatches(Class<T> ofType, final Predicate<? super 
T> predicate, long... range) {
-               return _NullSafe.stream(allInstances(ofType, range))
-                               .filter(predicate)
-                               
.collect(Collectors.toCollection(ArrayList::new));
-       }
-
-
-    @Programmatic
     @Override
     public <T> List<T> allMatches(final Query<T> query) {
         if(autoFlush) {
@@ -198,17 +193,6 @@ public class RepositoryServiceInternalDefault implements 
RepositoryService {
         }
         return firstInstanceElseNull(instances);
     }
-    
-    @Programmatic
-    @Override
-    public <T> T uniqueMatch(final Class<T> type, final Predicate<T> 
predicate) {
-        final List<T> instances = allMatches(type, predicate, 0, 2); // No 
need to fetch more than 2.
-        if (instances.size() > 1) {
-            throw new RepositoryException("Found more than one instance of " + 
type + " matching filter " + predicate);
-        }
-        return firstInstanceElseNull(instances);
-    }
-
 
     @Programmatic
     @Override

-- 
To stop receiving notification emails like this one, please contact
ahu...@apache.org.

Reply via email to