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 2021/03/12 19:22:29 UTC

[isis-app-helloworld] 03/03: use JDOQL for query, reconcile whitespace with jpa version

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

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

commit 1c5e393e8723295d48a3f152f85318c812cf6e5b
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Mar 12 19:22:07 2021 +0000

    use JDOQL for query, reconcile whitespace with jpa version
---
 pom.xml                                                 |  2 +-
 .../modules/hello/dom/hwo/HelloWorldObject.java         |  8 ++++++++
 .../modules/hello/dom/hwo/HelloWorldObjects.java        | 17 ++++++-----------
 src/main/java/domainapp/modules/hello/types/Name.java   |  4 +---
 src/main/java/domainapp/modules/hello/types/Notes.java  |  9 ++++-----
 src/main/resources/application.yml                      |  3 +--
 src/main/resources/config/application.properties        |  1 -
 ...rldObjects_Test.java => HelloWorldObjects_Test.java} |  4 ++--
 8 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9d45a56..6049106 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
 	<artifactId>helloworld-jdo</artifactId>
 	<version>1.0.0-SNAPSHOT</version>
 
-	<name>Apache Isis App - HelloWorld (JDO)</name>
+	<name>HelloWorld (JDO)</name>
 
 	<packaging>jar</packaging>
 
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
index 4f5b164..c4afa18 100644
--- a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObject.java
@@ -23,6 +23,14 @@ import domainapp.modules.hello.types.Notes;
 
 @javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.DATASTORE, schema = "hello" )
 @javax.jdo.annotations.DatastoreIdentity(strategy = IdGeneratorStrategy.IDENTITY, column = "id")
+@javax.jdo.annotations.Queries(
+        @javax.jdo.annotations.Query(
+                name = "findByName",
+                value = "SELECT " +
+                        "FROM domainapp.modules.hello.dom.hwo.HelloWorldObject " +
+                        "WHERE name.indexOf(:name) > 0"
+        )
+)
 @javax.jdo.annotations.Version(strategy= VersionStrategy.DATE_TIME, column ="version")
 @javax.jdo.annotations.Unique(name="HelloWorldObject_name_UNQ", members = {"name"})
 @DomainObject(entityChangePublishing = Publishing.ENABLED)
diff --git a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObjects.java b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObjects.java
index b19417f..d5c42bb 100644
--- a/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObjects.java
+++ b/src/main/java/domainapp/modules/hello/dom/hwo/HelloWorldObjects.java
@@ -11,6 +11,7 @@ import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.annotation.PromptStyle;
 import org.apache.isis.applib.annotation.RestrictTo;
 import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.persistence.jdo.applib.services.JdoSupportService;
 
@@ -23,13 +24,10 @@ import domainapp.modules.hello.types.Name;
 public class HelloWorldObjects {
 
     private final RepositoryService repositoryService;
-    private final JdoSupportService jdoSupportService;
 
     public HelloWorldObjects(
-            final RepositoryService repositoryService,
-            final JdoSupportService jdoSupportService) {
+            final RepositoryService repositoryService) {
         this.repositoryService = repositoryService;
-        this.jdoSupportService = jdoSupportService;
     }
 
     @Action(semantics = SemanticsOf.NON_IDEMPOTENT)
@@ -47,13 +45,10 @@ public class HelloWorldObjects {
     @ActionLayout(promptStyle = PromptStyle.DIALOG_SIDEBAR)
     public List<HelloWorldObject> findByName(
             @Name final String name) {
-        JDOQLTypedQuery<HelloWorldObject> q = jdoSupportService.newTypesafeQuery(HelloWorldObject.class);
-        final QHelloWorldObject cand = QHelloWorldObject.candidate();
-        q = q.filter(
-                cand.name.indexOf(q.stringParameter("name")).ne(-1)
-                );
-        return q.setParameter("name", name)
-                .executeList();
+        return repositoryService.allMatches(
+                Query.named(HelloWorldObject.class, "findByName")
+                      .withParameter("name", name)
+        );
     }
 
     @Action(semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING)
diff --git a/src/main/java/domainapp/modules/hello/types/Name.java b/src/main/java/domainapp/modules/hello/types/Name.java
index a70b4fc..001e1a3 100644
--- a/src/main/java/domainapp/modules/hello/types/Name.java
+++ b/src/main/java/domainapp/modules/hello/types/Name.java
@@ -5,13 +5,11 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import javax.jdo.annotations.Column;
-
 import org.apache.isis.applib.annotation.Parameter;
 import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.Property;
 
-@Column(length = Name.MAX_LEN, allowsNull = "false")
+@javax.jdo.annotations.Column(length = Name.MAX_LEN, allowsNull = "false")
 @Property(maxLength = Name.MAX_LEN)
 @Parameter(maxLength = Name.MAX_LEN)
 @ParameterLayout(named = "Name")
diff --git a/src/main/java/domainapp/modules/hello/types/Notes.java b/src/main/java/domainapp/modules/hello/types/Notes.java
index 0effb61..ef02e7f 100644
--- a/src/main/java/domainapp/modules/hello/types/Notes.java
+++ b/src/main/java/domainapp/modules/hello/types/Notes.java
@@ -5,18 +5,17 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import javax.jdo.annotations.Column;
-
 import org.apache.isis.applib.annotation.Editing;
+import org.apache.isis.applib.annotation.Optionality;
 import org.apache.isis.applib.annotation.Parameter;
 import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.Property;
 import org.apache.isis.applib.annotation.PropertyLayout;
 
-@Column(length = Notes.MAX_LEN, allowsNull = "true")
-@Property(editing = Editing.ENABLED, maxLength = Notes.MAX_LEN)
+@javax.jdo.annotations.Column(length = Notes.MAX_LEN, allowsNull = "true")
+@Property(editing = Editing.ENABLED, maxLength = Notes.MAX_LEN, optionality = Optionality.OPTIONAL)
 @PropertyLayout(multiLine = 5)
-@Parameter(maxLength = Notes.MAX_LEN)
+@Parameter(maxLength = Notes.MAX_LEN, optionality = Optionality.OPTIONAL)
 @ParameterLayout(multiLine = 5)
 @Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
 @Retention(RetentionPolicy.RUNTIME)
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index e53c19e..64bf5d3 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -47,7 +47,7 @@ isis:
     schema:
       auto-create-schemas: hello
       create-schema-sql-template: "CREATE SCHEMA IF NOT EXISTS %S"
-    
+
 # note that properties under 'datanucleus' must use camelCase rather than kebab-case
 datanucleus:
   schema:
@@ -75,4 +75,3 @@ server:
 spring:
   banner:
     location: banner.txt
-
diff --git a/src/main/resources/config/application.properties b/src/main/resources/config/application.properties
index 539fc17..efbbaf4 100644
--- a/src/main/resources/config/application.properties
+++ b/src/main/resources/config/application.properties
@@ -14,4 +14,3 @@ datanucleus.schema.autoCreateAll=true
 
 spring.datasource.platform=h2
 spring.datasource.url=jdbc:h2:mem:helloworld
-
diff --git a/src/test/java/domainapp/modules/hello/dom/hwo/HellWorldObjects_Test.java b/src/test/java/domainapp/modules/hello/dom/hwo/HelloWorldObjects_Test.java
similarity index 94%
rename from src/test/java/domainapp/modules/hello/dom/hwo/HellWorldObjects_Test.java
rename to src/test/java/domainapp/modules/hello/dom/hwo/HelloWorldObjects_Test.java
index 0048143..5683e13 100644
--- a/src/test/java/domainapp/modules/hello/dom/hwo/HellWorldObjects_Test.java
+++ b/src/test/java/domainapp/modules/hello/dom/hwo/HelloWorldObjects_Test.java
@@ -21,7 +21,7 @@ import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.persistence.jdo.applib.services.JdoSupportService;
 
 @ExtendWith(MockitoExtension.class)
-class HellWorldObjects_Test {
+class HelloWorldObjects_Test {
 
     @Mock RepositoryService mockRepositoryService;
     @Mock JdoSupportService mockJdoSupportService;
@@ -30,7 +30,7 @@ class HellWorldObjects_Test {
 
     @BeforeEach
     public void setUp() {
-        objects = new HelloWorldObjects(mockRepositoryService, mockJdoSupportService);
+        objects = new HelloWorldObjects(mockRepositoryService);
     }
 
     @Nested