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/08/25 17:16:04 UTC

[isis-app-simpleapp] 05/06: updates to run using dynamic weaving.

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

danhaywood pushed a commit to branch jpa-SNAPSHOT
in repository https://gitbox.apache.org/repos/asf/isis-app-simpleapp.git

commit 11113fb0c11c4b64b70a480b1e7a681504e70499
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Aug 25 17:39:40 2022 +0100

    updates to run using dynamic weaving.
---
 README.adoc                                        |  39 ++++++++++++++++-----
 lib/README.txt                                     |   5 ---
 lib/spring-instrument-5.3.8.jar                    | Bin 7429 -> 0 bytes
 .../modules/simple/dom/so/SimpleObject.java        |   9 ++---
 .../modules/simple/dom/so/SimpleObjects.java       |   3 --
 .../src/test/resources/application-test.properties |   4 +++
 .../src/test/resources/application-test.yml        |   1 +
 webapp/pom.xml                                     |   3 ++
 .../services/homepage/HomePageViewModel.java       |  10 ++++--
 9 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/README.adoc b/README.adoc
index 5e8d9b5..09e9232 100644
--- a/README.adoc
+++ b/README.adoc
@@ -84,36 +84,57 @@ The following table explains the contents of each of the directories:
 
 |`module-simple`
 |Holds the "simple" module, consisting of the `SimpleObject` entity and supporting services.
-It also contains module-specific unit- and integration tests.
 
 [TIP]
 ====
 Larger applications should consist of multiple modules; each such module can be copied from this starter module.
 ====
 
+|`module-simple-tests`
+|Holds the unit- and integration tests for `module-simple`.
+
+
 |`webapp`
 |Holds the bootstrapping classes, along with application-level scoped services and home page.
-It also contains application-wide integration tests.
 
 The `pom.xml` also provides goals to run the app from the command line, or to be assembled into a Docker image.
 
+|`webapp-tests`
+|Contains application-wide integration tests.
+
 |====================
 
+It's more common for tests to reside within the same module, but we moved them into their own Maven modules because it makes them easier to be temporarily excluded, eg during initial explorations/prototyping.
 
-== Development
 
-Apache Isis uses DataNucleus as its ORM, which requires that any entities are "enhanced", a post-compile process.
+== ORM Support
 
-Normally this is done as part of a "mvn clean install", but the entities can also be enhanced explicity using:
+This version of the application uses EclipseLink JPA as its ORM, configured with load-time weaving.
+This requires that the application be run with a Java agent.
+
+The spring-boot plugin is configured to run with this agent already.
+If you want to run from an IDE, you will also need to specify the agent as a VM option:
 
 [source,bash]
 ----
-mvn -pl module-simple datanucleus:enhance -o
+-javaagent:${env.HOME}/.m2/repository/org/springframework/spring-instrument-${spring-framework.version}.jar
 ----
 
-This is useful to know if the application or integration test fails to bootstrap, complaining of "unenhanced entities".
-
-TIP: You can also use `enhance-all.sh`
+Substitute the two variables appropriately (with `${spring-framework.version}` obtained from the `pom.xml` file).
+
+
+//This version of the application uses DataNucleus as its ORM, which requires that any entities are "enhanced", a post-compile process.
+//
+//Normally this is done as part of a "mvn clean install", but the entities can also be enhanced explicity using:
+//
+//[source,bash]
+//----
+//mvn -pl module-simple datanucleus:enhance -o
+//----
+//
+//This is useful to know if the application or integration test fails to bootstrap, complaining of "unenhanced entities".
+//
+//TIP: You can also use `enhance-all.sh`
 
 
 == Testing
diff --git a/lib/README.txt b/lib/README.txt
deleted file mode 100644
index 17de356..0000000
--- a/lib/README.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-If eclipselink.weaving=true, then run using JVM argument:
-
--javaagent:lib/spring-instrument-5.3.8.jar
-
-Can be downloaded from: https://search.maven.org/artifact/org.springframework/spring-instrument
diff --git a/lib/spring-instrument-5.3.8.jar b/lib/spring-instrument-5.3.8.jar
deleted file mode 100644
index c0a0a9b..0000000
Binary files a/lib/spring-instrument-5.3.8.jar and /dev/null differ
diff --git a/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObject.java b/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObject.java
index 6d5bd43..098a63d 100644
--- a/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObject.java
+++ b/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObject.java
@@ -20,8 +20,10 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.ActionLayout;
+import org.apache.isis.applib.annotation.Domain;
 import org.apache.isis.applib.annotation.DomainObject;
 import org.apache.isis.applib.annotation.DomainObjectLayout;
+import org.apache.isis.applib.annotation.MemberSupport;
 import org.apache.isis.applib.annotation.PromptStyle;
 import org.apache.isis.applib.annotation.Property;
 import org.apache.isis.applib.annotation.PropertyLayout;
@@ -65,8 +67,7 @@ import domainapp.modules.simple.types.Notes;
         )
 })
 @EntityListeners(IsisEntityListener.class)
-@Named(SimpleModule.NAMESPACE +
-        ".SimpleObject")
+@Named(SimpleModule.NAMESPACE + ".SimpleObject")
 @DomainObject(entityChangePublishing = Publishing.ENABLED)
 @DomainObjectLayout()
 @NoArgsConstructor(access = AccessLevel.PUBLIC)
@@ -123,10 +124,10 @@ public class SimpleObject implements Comparable<SimpleObject> {
         setName(name);
         return this;
     }
-    public String default0UpdateName() {
+    @MemberSupport public String default0UpdateName() {
         return getName();
     }
-    public String validate0UpdateName(String newName) {
+    @MemberSupport public String validate0UpdateName(String newName) {
         for (char prohibitedCharacter : PROHIBITED_CHARACTERS.toCharArray()) {
             if( newName.contains(""+prohibitedCharacter)) {
                 return "Character '" + prohibitedCharacter + "' is not allowed.";
diff --git a/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObjects.java b/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObjects.java
index c0416e4..d161c0e 100644
--- a/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObjects.java
+++ b/module-simple/src/main/java/domainapp/modules/simple/dom/so/SimpleObjects.java
@@ -65,7 +65,6 @@ public class SimpleObjects {
     }
 
 
-    @Programmatic
     public SimpleObject findByNameExact(final String name) {
         return simpleObjectRepository.findByName(name);
     }
@@ -80,8 +79,6 @@ public class SimpleObjects {
 
 
 
-
-    @Programmatic
     public void ping() {
         jpaSupportService.getEntityManager(SimpleObject.class)
             .mapSuccess(entityManager -> {
diff --git a/webapp-tests/src/test/resources/application-test.properties b/webapp-tests/src/test/resources/application-test.properties
new file mode 100644
index 0000000..eaf3275
--- /dev/null
+++ b/webapp-tests/src/test/resources/application-test.properties
@@ -0,0 +1,4 @@
+eclipselink.weaving=false
+eclipselink.weaving.changetracking=false
+eclipselink.weaving.internal=false
+eclipselink.weaving.lazy=false
diff --git a/webapp-tests/src/test/resources/application-test.yml b/webapp-tests/src/test/resources/application-test.yml
index 3a68cae..da2e570 100644
--- a/webapp-tests/src/test/resources/application-test.yml
+++ b/webapp-tests/src/test/resources/application-test.yml
@@ -2,3 +2,4 @@ isis:
   persistence:
     schema:
       auto-create-schemas: "simple"
+
diff --git a/webapp/pom.xml b/webapp/pom.xml
index d1cff69..59743f8 100644
--- a/webapp/pom.xml
+++ b/webapp/pom.xml
@@ -49,6 +49,9 @@
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <configuration>
                     <classifier>exec</classifier>
+                    <agents>
+                        <agent>${env.HOME}/.m2/repository/org/springframework/spring-instrument-${spring-framework.version}.jar</agent>
+                    </agents>
                 </configuration>
             </plugin>
         </plugins>
diff --git a/webapp/src/main/java/domainapp/webapp/application/services/homepage/HomePageViewModel.java b/webapp/src/main/java/domainapp/webapp/application/services/homepage/HomePageViewModel.java
index 325b6d5..6365227 100644
--- a/webapp/src/main/java/domainapp/webapp/application/services/homepage/HomePageViewModel.java
+++ b/webapp/src/main/java/domainapp/webapp/application/services/homepage/HomePageViewModel.java
@@ -5,24 +5,30 @@ import java.util.List;
 import javax.inject.Inject;
 import javax.inject.Named;
 
+import org.apache.isis.applib.annotation.Collection;
+import org.apache.isis.applib.annotation.Domain;
 import org.apache.isis.applib.annotation.DomainObject;
 import org.apache.isis.applib.annotation.DomainObjectLayout;
 import org.apache.isis.applib.annotation.HomePage;
+import org.apache.isis.applib.annotation.MemberSupport;
 import org.apache.isis.applib.annotation.Nature;
+import org.apache.isis.applib.annotation.ObjectSupport;
 
+import domainapp.modules.simple.SimpleModule;
 import domainapp.modules.simple.dom.so.SimpleObject;
 import domainapp.modules.simple.dom.so.SimpleObjects;
 
-@Named("simple.HomePageViewModel")
+@Named(SimpleModule.NAMESPACE + ".HomePageViewModel")
 @DomainObject(nature = Nature.VIEW_MODEL)
 @HomePage
 @DomainObjectLayout()
 public class HomePageViewModel {
 
-    public String title() {
+    @ObjectSupport public String title() {
         return getObjects().size() + " objects";
     }
 
+    @Collection
     public List<SimpleObject> getObjects() {
         return simpleObjects.listAll();
     }