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 2022/04/16 09:24:54 UTC

[isis] branch master updated: ISIS-3010: unified CommandSubscriber for JDO+JPA

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 59e8085cd6 ISIS-3010: unified CommandSubscriber for JDO+JPA
59e8085cd6 is described below

commit 59e8085cd6164847dcea5a320bad0fa94ef549d4
Author: andi-huber <ah...@apache.org>
AuthorDate: Sat Apr 16 11:24:48 2022 +0200

    ISIS-3010: unified CommandSubscriber for JDO+JPA
---
 .../applib/command/ICommandLogRepository.java      |  8 ++++++-
 .../CommandSubscriberForCommandLog.java}           | 25 +++++++++++-----------
 .../commandlog/jdo/IsisModuleExtCommandLogJdo.java |  2 ++
 .../jdo/entities/CommandJdoRepository.java         |  6 ++++++
 .../commandlog/jpa/IsisModuleExtCommandLogJpa.java |  7 ++++--
 .../jpa/entities/CommandJpaRepository.java         |  5 +++++
 6 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/applib/command/ICommandLogRepository.java b/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/applib/command/ICommandLogRepository.java
index 849e3a1533..1f659ae88d 100644
--- a/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/applib/command/ICommandLogRepository.java
+++ b/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/applib/command/ICommandLogRepository.java
@@ -27,6 +27,7 @@ import org.springframework.lang.Nullable;
 
 import org.apache.isis.applib.exceptions.RecoverableException;
 import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.schema.cmd.v2.CommandDto;
 import org.apache.isis.schema.cmd.v2.CommandsDto;
 
@@ -34,6 +35,9 @@ import lombok.Getter;
 
 public interface ICommandLogRepository<C extends ICommandLog> {
 
+    /** Creates a transient (yet not persisted) {@link ICommandLog} instance. */
+    C createCommandLog(Command command);
+
     Optional<C> findByInteractionId(UUID interactionId);
 
     List<C> findByParent(ICommandLog parent);
@@ -114,7 +118,7 @@ public interface ICommandLogRepository<C extends ICommandLog> {
 
     List<C> saveForReplay(CommandsDto commandsDto);
 
-    void persist(C commandJdo);
+    void persist(C commandLog);
 
     void truncateLog();
 
@@ -141,4 +145,6 @@ public interface ICommandLogRepository<C extends ICommandLog> {
         return commands;
     }
 
+
+
 }
diff --git a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/subscriber/CommandSubscriberForJdo.java b/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/applib/command/subscriber/CommandSubscriberForCommandLog.java
similarity index 74%
rename from extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/subscriber/CommandSubscriberForJdo.java
rename to extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/applib/command/subscriber/CommandSubscriberForCommandLog.java
index c30b228945..33010c24e8 100644
--- a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/subscriber/CommandSubscriberForJdo.java
+++ b/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/applib/command/subscriber/CommandSubscriberForCommandLog.java
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.extensions.commandlog.jdo.subscriber;
+package org.apache.isis.extensions.commandlog.applib.command.subscriber;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -28,9 +28,10 @@ import org.apache.isis.applib.annotation.PriorityPrecedence;
 import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.applib.services.publishing.spi.CommandSubscriber;
 import org.apache.isis.applib.util.JaxbUtil;
-import org.apache.isis.extensions.commandlog.jdo.IsisModuleExtCommandLogJdo;
-import org.apache.isis.extensions.commandlog.jdo.entities.CommandJdo;
-import org.apache.isis.extensions.commandlog.jdo.entities.CommandJdoRepository;
+import org.apache.isis.commons.internal.base._Casts;
+import org.apache.isis.extensions.commandlog.applib.IsisModuleExtCommandLogApplib;
+import org.apache.isis.extensions.commandlog.applib.command.CommandLog;
+import org.apache.isis.extensions.commandlog.applib.command.ICommandLogRepository;
 
 import lombok.RequiredArgsConstructor;
 import lombok.val;
@@ -40,14 +41,14 @@ import lombok.extern.log4j.Log4j2;
  * @since 2.0 {@index}
  */
 @Service
-@Named(IsisModuleExtCommandLogJdo.NAMESPACE + ".CommandCompletionHook")
+@Named(IsisModuleExtCommandLogApplib.NAMESPACE + ".CommandSubscriberForCommandLog")
 @javax.annotation.Priority(PriorityPrecedence.MIDPOINT) // after JdoPersistenceLifecycleService
 @Qualifier("Jdo")
 @RequiredArgsConstructor
 @Log4j2
-public class CommandSubscriberForJdo implements CommandSubscriber {
+public class CommandSubscriberForCommandLog implements CommandSubscriber {
 
-    @Inject final CommandJdoRepository commandJdoRepository;
+    @Inject final ICommandLogRepository<? extends CommandLog> commandLogRepository;
 
     @Override
     public void onCompleted(final Command command) {
@@ -57,7 +58,7 @@ public class CommandSubscriberForJdo implements CommandSubscriber {
         }
 
         val existingCommandJdoIfAny =
-                commandJdoRepository.findByInteractionId(command.getInteractionId());
+                commandLogRepository.findByInteractionId(command.getInteractionId());
         if(existingCommandJdoIfAny.isPresent()) {
             if(log.isDebugEnabled()) {
                 // this isn't expected to happen ... we just log the fact if it does
@@ -72,16 +73,16 @@ public class CommandSubscriberForJdo implements CommandSubscriber {
                 log.debug("proposed: \n{}", commandDtoXml);
             }
         } else {
-            val commandJdo = new CommandJdo(command);
+            val commandLogInstance = commandLogRepository.createCommandLog(command);
             val parent = command.getParent();
             val parentJdo =
                 parent != null
-                    ? commandJdoRepository
+                    ? commandLogRepository
                         .findByInteractionId(parent.getInteractionId())
                         .orElse(null)
                     : null;
-            commandJdo.setParent(parentJdo);
-            commandJdoRepository.persist(commandJdo);
+            commandLogInstance.setParent(parentJdo);
+            commandLogRepository.persist(_Casts.uncheckedCast(commandLogInstance));
         }
 
 
diff --git a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/IsisModuleExtCommandLogJdo.java b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/IsisModuleExtCommandLogJdo.java
index 54d88b36bf..e96c2845b8 100644
--- a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/IsisModuleExtCommandLogJdo.java
+++ b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/IsisModuleExtCommandLogJdo.java
@@ -24,6 +24,7 @@ import org.springframework.context.annotation.Import;
 
 import org.apache.isis.extensions.commandlog.applib.command.CommandLog;
 import org.apache.isis.extensions.commandlog.applib.command.ICommandLog;
+import org.apache.isis.extensions.commandlog.applib.command.subscriber.CommandSubscriberForCommandLog;
 import org.apache.isis.extensions.commandlog.jdo.entities.CommandJdo;
 import org.apache.isis.extensions.commandlog.jdo.entities.CommandJdoRepository;
 import org.apache.isis.extensions.commandlog.jdo.ui.CommandServiceMenu;
@@ -41,6 +42,7 @@ import org.apache.isis.testing.fixtures.applib.teardown.jdo.TeardownFixtureJdoAb
         // @Service's
         CommandJdoRepository.class,
         CommandLog.TableColumnOrderDefault.class,
+        CommandSubscriberForCommandLog.class,
 
         // entities
         CommandJdo.class
diff --git a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/entities/CommandJdoRepository.java b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/entities/CommandJdoRepository.java
index 0c1037569a..c335a2c8b1 100644
--- a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/entities/CommandJdoRepository.java
+++ b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/entities/CommandJdoRepository.java
@@ -42,6 +42,7 @@ import org.apache.isis.applib.jaxb.JavaSqlXMLGregorianCalendarMarshalling;
 import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.query.QueryRange;
 import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.applib.services.iactn.InteractionProvider;
 import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.applib.util.schema.CommandDtoUtils;
@@ -76,6 +77,11 @@ implements ICommandLogRepository<CommandJdo> {
     @Inject final Provider<RepositoryService> repositoryServiceProvider;
     @Inject final JdoSupportService jdoSupport;
 
+    @Override
+    public CommandJdo createCommandLog(final Command command) {
+        return new CommandJdo(command);
+    }
+
     @Override
     public List<CommandJdo> findByFromAndTo(
             final @Nullable LocalDate from,
diff --git a/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/IsisModuleExtCommandLogJpa.java b/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/IsisModuleExtCommandLogJpa.java
index 2e2c8eb415..20195d0fe7 100644
--- a/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/IsisModuleExtCommandLogJpa.java
+++ b/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/IsisModuleExtCommandLogJpa.java
@@ -23,6 +23,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 
 import org.apache.isis.extensions.commandlog.applib.command.CommandLog;
+import org.apache.isis.extensions.commandlog.applib.command.subscriber.CommandSubscriberForCommandLog;
 import org.apache.isis.extensions.commandlog.jpa.entities.CommandJpaRepository;
 
 /**
@@ -31,11 +32,13 @@ import org.apache.isis.extensions.commandlog.jpa.entities.CommandJpaRepository;
 @Configuration
 @Import({
         // @DomainService's
-        CommandJpaRepository.class
+        CommandJpaRepository.class,
+
 //TODO        , CommandServiceMenu.class
 
         // @Service's
-        , CommandLog.TableColumnOrderDefault.class
+        CommandLog.TableColumnOrderDefault.class,
+        CommandSubscriberForCommandLog.class,
 
 })
 @ComponentScan(
diff --git a/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/entities/CommandJpaRepository.java b/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/entities/CommandJpaRepository.java
index adf2307efc..bab666bcf2 100644
--- a/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/entities/CommandJpaRepository.java
+++ b/extensions/core/command-log/jpa/src/main/java/org/apache/isis/extensions/commandlog/jpa/entities/CommandJpaRepository.java
@@ -42,6 +42,7 @@ import org.apache.isis.applib.jaxb.JavaSqlXMLGregorianCalendarMarshalling;
 import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.query.QueryRange;
 import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.applib.services.iactn.InteractionProvider;
 import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.applib.util.schema.CommandDtoUtils;
@@ -74,6 +75,10 @@ implements ICommandLogRepository<CommandJpa> {
     @Inject final Provider<InteractionProvider> interactionProviderProvider;
     @Inject final Provider<RepositoryService> repositoryServiceProvider;
 
+    @Override
+    public CommandJpa createCommandLog(final Command command) {
+        return new CommandJpa(command);
+    }
 
     @Override
     public List<CommandJpa> findByFromAndTo(