You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/12/01 08:23:44 UTC

[isis] branch master updated: ISIS-2464: deprecating RepositoryService#detachedEntity(Class ofType)

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 7eb77e3  ISIS-2464: deprecating RepositoryService#detachedEntity(Class<T> ofType)
7eb77e3 is described below

commit 7eb77e394d62dcf32ab4f155f01f63507182fff7
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Dec 1 09:23:26 2020 +0100

    ISIS-2464: deprecating RepositoryService#detachedEntity(Class<T> ofType)
---
 .../modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc | 16 ++++++++++++---
 .../services/repository/RepositoryService.java     | 24 ++++++++++++++++++----
 .../services/repository/RepositoryService.java     | 15 +++++++++++++-
 3 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc b/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc
index ff066c7..ccff51b 100644
--- a/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc
+++ b/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc
@@ -78,7 +78,7 @@ VIEW_CONTRIBUTIONS_ONLY,
 
 == Changes to the Programming Model
 
-=== Removed
+=== Removed (Programming Model)
 
 [cols="2a,3a", options="header"]
 
@@ -130,7 +130,7 @@ use `@DomainObject(nature=MIXIN, ...)` combined with one of the above
 |===
 
 
-=== Added
+=== Added (Programming Model)
 
 .Command/Execution Publishing (Member Level Annotations)
 [source,java]
@@ -148,7 +148,7 @@ use `@DomainObject(nature=MIXIN, ...)` combined with one of the above
 ----
 <.> affects EntityChange publishing (effective only for entity types)
 
-=== Renamed
+=== Renamed (Programming Model)
 
 .Publishing API/SPI
 [source,java]
@@ -180,5 +180,15 @@ PublisherDispatchServiceDefault -> ExecutionPublisherDefault & EntityChangesPubl
 CommandServiceInternal -> CommandPublisher
 ----
 
+== Deprecations
+
+.RepositoryService
+[source,java]
+----
+<T> T detachedEntity(Class<T> ofType);     // <.>
+----
+<.> if applicable use `<T> T detachedEntity(T entity)` instead ... "new is the new new", passing
+in a new-ed up (entity) instance is more flexible and also more error prone, eg. it allows the compiler to check 
+validity of the used constructor rather than doing construction reflective at runtime
 
 
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/repository/RepositoryService.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/repository/RepositoryService.java
index 6c9d963..9b3057c 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/repository/RepositoryService.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/repository/RepositoryService.java
@@ -27,6 +27,8 @@ import javax.annotation.Nullable;
 
 import org.apache.isis.applib.query.Query;
 
+import lombok.NonNull;
+import lombok.SneakyThrows;
 import lombok.val;
 
 // tag::refguide[]
@@ -44,12 +46,12 @@ public interface RepositoryService {
 
     // end::refguide[]
     /**
-     * Same as {@link org.apache.isis.applib.services.factory.FactoryService#detachedEntity(Class)}; provided as a
+     * Same as {@link org.apache.isis.applib.services.factory.FactoryService#detachedEntity(Object)}; provided as a
      * convenience because instantiating and {@link #persist(Object) persisting} are often done together.
      * @since 2.0
      */
     // tag::refguide[]
-    <T> T detachedEntity(Class<T> ofType);                  // <.>
+    <T> T detachedEntity(@NonNull T entity);                // <.>
 
     // end::refguide[]
     /**
@@ -292,11 +294,25 @@ public interface RepositoryService {
     // -- DEPRECATIONS
 
     /**
-     * @deprecated if applicable use {@link #detachedEntity(Class)} instead
+     * Same as {@link org.apache.isis.applib.services.factory.FactoryService#detachedEntity(Class)}; provided as a
+     * convenience because instantiating and {@link #persist(Object) persisting} are often done together.
+     * @deprecated if applicable use {@link #detachedEntity(Object)} instead ... "new is the new new", passing
+     * in a new-ed up instance is more flexible and also more error prone, eg. it allows the compiler to check 
+     * validity of the used constructor rather than doing construction reflective at runtime.
+     */
+    @Deprecated
+    @SneakyThrows
+    default <T> T detachedEntity(Class<T> ofType) {
+        return detachedEntity(ofType.newInstance());
+    }
+    
+    /**
+     * @deprecated if applicable use {@link #detachedEntity(Object)} instead
      */
     @Deprecated
+    @SneakyThrows
     default <T> T instantiate(Class<T> ofType) {
-        return detachedEntity(ofType);
+        return detachedEntity(ofType.newInstance());
     }
 
     /**
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java b/api/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
index a0c9dde..9b3057c 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/repository/RepositoryService.java
@@ -294,7 +294,20 @@ public interface RepositoryService {
     // -- DEPRECATIONS
 
     /**
-     * @deprecated if applicable use {@link #detachedEntity(Class)} instead
+     * Same as {@link org.apache.isis.applib.services.factory.FactoryService#detachedEntity(Class)}; provided as a
+     * convenience because instantiating and {@link #persist(Object) persisting} are often done together.
+     * @deprecated if applicable use {@link #detachedEntity(Object)} instead ... "new is the new new", passing
+     * in a new-ed up instance is more flexible and also more error prone, eg. it allows the compiler to check 
+     * validity of the used constructor rather than doing construction reflective at runtime.
+     */
+    @Deprecated
+    @SneakyThrows
+    default <T> T detachedEntity(Class<T> ofType) {
+        return detachedEntity(ofType.newInstance());
+    }
+    
+    /**
+     * @deprecated if applicable use {@link #detachedEntity(Object)} instead
      */
     @Deprecated
     @SneakyThrows