You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2022/11/01 07:36:53 UTC
[isis] 01/01: ISIS-3267: adds new repo method and JDO/JPA annotations
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-3267
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 847274c1826fd078af6d74f5ae6408022dfeba95
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Nov 1 07:36:37 2022 +0000
ISIS-3267: adds new repo method and JDO/JPA annotations
---
.../wrapper/WrapperFactoryDefault.java | 3 +-
.../commandlog/applib/dom/CommandLogEntry.java | 2 +-
.../applib/dom/CommandLogEntryRepository.java | 15 ++++++++
.../commandlog/jdo/dom/CommandLogEntry.java | 8 ++++-
.../commandlog/jpa/dom/CommandLogEntry.java | 40 +++++++++++++---------
5 files changed, 48 insertions(+), 20 deletions(-)
diff --git a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
index 2e027dc06c..c3a01281ed 100644
--- a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
@@ -582,7 +582,8 @@ implements WrapperFactory, HasMetaModelContext {
@Getter private final UUID parentInteractionId;
/**
- * Note that is a <code>transient</code> field in order that {@link org.apache.causeway.applib.services.wrapper.callable.AsyncCallable} can be declared as
+ * Note this is a <code>transient</code> field, in order that
+ * {@link org.apache.causeway.applib.services.wrapper.callable.AsyncCallable} can be declared as
* {@link java.io.Serializable}.
*
* <p>
diff --git a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntry.java b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntry.java
index 166854151a..f21c15e2eb 100644
--- a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntry.java
+++ b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntry.java
@@ -50,7 +50,6 @@ import org.apache.causeway.applib.annotation.Publishing;
import org.apache.causeway.applib.annotation.Where;
import org.apache.causeway.applib.jaxb.JavaSqlXMLGregorianCalendarMarshalling;
import org.apache.causeway.applib.mixins.system.DomainChangeRecord;
-import org.apache.causeway.applib.mixins.system.DomainChangeRecord.ChangeType;
import org.apache.causeway.applib.mixins.system.HasInteractionId;
import org.apache.causeway.applib.services.bookmark.Bookmark;
import org.apache.causeway.applib.services.command.Command;
@@ -135,6 +134,7 @@ implements Comparable<CommandLogEntry>, DomainChangeRecord, HasCommandDto {
public static final String FIND_MOST_RECENT_REPLAYED = LOGICAL_TYPE_NAME + ".findMostRecentReplayed";
public static final String FIND_MOST_RECENT_COMPLETED = LOGICAL_TYPE_NAME + ".findMostRecentCompleted";
public static final String FIND_BY_REPLAY_STATE = LOGICAL_TYPE_NAME + ".findNotYetReplayed";
+ public static final String FIND_NOT_YET_STARTED = "findNotYetStarted";
}
diff --git a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntryRepository.java b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntryRepository.java
index dbf03593ac..bdb8915b67 100644
--- a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntryRepository.java
+++ b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/dom/CommandLogEntryRepository.java
@@ -255,6 +255,21 @@ public abstract class CommandLogEntryRepository<C extends CommandLogEntry> {
.orElse(Collections.emptyList());
}
+ /**
+ * Returns any parented commands that have not yet started.
+ *
+ * <p>
+ * This is to support the notion of background commands (the same as their implementation in v1) whereby a
+ * custom executor service for {@link org.apache.causeway.applib.services.wrapper.WrapperFactory} would
+ * "execute" a {@link Command} simply by persisting it as a {@link CommandLogEntry}, so that a
+ * quartz or similar background job could execute the {@link Command} at some point later.
+ * </p>
+ */
+ public Optional<C> findParentedCommandsNotYetStarted() {
+ return repositoryService().firstMatch(
+ Query.named(commandLogEntryClass, CommandLogEntry.Nq.FIND_NOT_YET_STARTED));
+ }
+
/**
* The most recent replayed command previously replicated from primary to
* secondary.
diff --git a/extensions/core/commandlog/persistence-jdo/src/main/java/org/apache/causeway/extensions/commandlog/jdo/dom/CommandLogEntry.java b/extensions/core/commandlog/persistence-jdo/src/main/java/org/apache/causeway/extensions/commandlog/jdo/dom/CommandLogEntry.java
index c120f33814..0b4acc2502 100644
--- a/extensions/core/commandlog/persistence-jdo/src/main/java/org/apache/causeway/extensions/commandlog/jdo/dom/CommandLogEntry.java
+++ b/extensions/core/commandlog/persistence-jdo/src/main/java/org/apache/causeway/extensions/commandlog/jdo/dom/CommandLogEntry.java
@@ -172,7 +172,12 @@ import lombok.Setter;
+ " && startedAt != null "
+ " && completedAt != null "
+ "ORDER BY timestamp ASC"),
-
+ @Query(
+ name = Nq.FIND_NOT_YET_STARTED,
+ value = "SELECT "
+ + "FROM " + CommandLogEntry.FQCN + " "
+ + "WHERE startedAt == null "
+ + "ORDER BY timestamp ASC "),
// most recent (replayed) command previously replicated from primary to
// secondary. This should always exist except for the very first times
// (after restored the prod DB to secondary).
@@ -306,6 +311,7 @@ extends org.apache.causeway.extensions.commandlog.applib.dom.CommandLogEntry {
@Getter @Setter
private String exception;
+
@Column(allowsNull = ReplayState.ALLOWS_NULL, length = ReplayState.MAX_LENGTH)
@ReplayState
@Getter @Setter
diff --git a/extensions/core/commandlog/persistence-jpa/src/main/java/org/apache/causeway/extensions/commandlog/jpa/dom/CommandLogEntry.java b/extensions/core/commandlog/persistence-jpa/src/main/java/org/apache/causeway/extensions/commandlog/jpa/dom/CommandLogEntry.java
index 12787cf61d..9ffd8aea3a 100644
--- a/extensions/core/commandlog/persistence-jpa/src/main/java/org/apache/causeway/extensions/commandlog/jpa/dom/CommandLogEntry.java
+++ b/extensions/core/commandlog/persistence-jpa/src/main/java/org/apache/causeway/extensions/commandlog/jpa/dom/CommandLogEntry.java
@@ -73,23 +73,6 @@ import lombok.Setter;
query = "SELECT cl "
+ " FROM CommandLogEntry cl "
+ " WHERE cl.pk.interactionId = :interactionId"),
- @NamedQuery(
- name = Nq.FIND_BY_PARENT,
- query = "SELECT cl "
- + " FROM CommandLogEntry cl "
- + " WHERE cl.parent = :parent "),
- @NamedQuery(
- name = Nq.FIND_CURRENT,
- query = "SELECT cl "
- + " FROM CommandLogEntry cl "
- + " WHERE cl.completedAt is null "
- + " ORDER BY cl.timestamp DESC"),
- @NamedQuery(
- name = Nq.FIND_COMPLETED,
- query = "SELECT cl "
- + " FROM CommandLogEntry cl "
- + " WHERE cl.completedAt is not null "
- + " ORDER BY cl.timestamp DESC"),
@NamedQuery(
name = Nq.FIND_RECENT_BY_TARGET,
query = "SELECT cl "
@@ -166,6 +149,23 @@ import lombok.Setter;
+ " FROM CommandLogEntry cl "
+ " WHERE cl.username = :username "
+ " ORDER BY cl.timestamp DESC"), // programmatic LIMIT 30
+ @NamedQuery(
+ name = Nq.FIND_BY_PARENT,
+ query = "SELECT cl "
+ + " FROM CommandLogEntry cl "
+ + " WHERE cl.parent = :parent "),
+ @NamedQuery(
+ name = Nq.FIND_CURRENT,
+ query = "SELECT cl "
+ + " FROM CommandLogEntry cl "
+ + " WHERE cl.completedAt is null "
+ + " ORDER BY cl.timestamp DESC"),
+ @NamedQuery(
+ name = Nq.FIND_COMPLETED,
+ query = "SELECT cl "
+ + " FROM CommandLogEntry cl "
+ + " WHERE cl.completedAt is not null "
+ + " ORDER BY cl.timestamp DESC"),
@NamedQuery(
name = Nq.FIND_FIRST,
query = "SELECT cl "
@@ -181,6 +181,12 @@ import lombok.Setter;
+ " AND cl.startedAt is not null "
+ " AND cl.completedAt is not null "
+ " ORDER BY cl.timestamp ASC"),
+ @NamedQuery(
+ name = Nq.FIND_NOT_YET_STARTED,
+ query = "SELECT cl "
+ + " FROM CommandLogEntry cl "
+ + " WHERE cl.startedAt is null "
+ + " ORDER BY cl.timestamp ASC"),
// most recent (replayed) command previously replicated from primary to
// secondary. This should always exist except for the very first times
// (after restored the prod DB to secondary).