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/01/23 16:19:51 UTC
[isis] branch master updated: ISIS-2158: demo: add complex number
demo
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 a187ccc ISIS-2158: demo: add complex number demo
a187ccc is described below
commit a187cccf93fde87433dc931c12fa02ae94541f07
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jan 23 17:19:40 2020 +0100
ISIS-2158: demo: add complex number demo
experimental, so we can investigate what it takes to implement semantics
for a composite value type (typed tuple)
---
.../org/apache/isis/applib/value/TypedTuple.java | 10 ++++
.../isis/core/commons/internal/base/_Tuples.java | 62 ++++++++++++++++++++++
.../demo/src/main/java/demoapp/dom/package.jdo | 4 ++
.../demoapp/dom/types/tuple/ComplexNumber.java | 11 ++++
.../dom/types/tuple/DnComplexConverter.java | 25 +++++++++
.../demoapp/dom/types/tuple/NumberConstant.java | 36 +++++++++++++
.../dom/types/tuple/NumberConstantRepository.java | 55 +++++++++++++++++++
.../java/demoapp/dom/types/tuple/TupleDemo.java | 55 +++++++++++++++++++
.../demoapp/dom/types/tuple/TupleDemoMenu.java | 48 +++++++++++++++++
.../main/java/demoapp/webapp/menubars.layout.xml | 12 ++++-
.../demo/src/main/resources/META-INF/MANIFEST.MF | 6 +++
examples/demo/src/main/resources/plugin.xml | 14 +++++
12 files changed, 336 insertions(+), 2 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/value/TypedTuple.java b/api/applib/src/main/java/org/apache/isis/applib/value/TypedTuple.java
new file mode 100644
index 0000000..c642c93
--- /dev/null
+++ b/api/applib/src/main/java/org/apache/isis/applib/value/TypedTuple.java
@@ -0,0 +1,10 @@
+package org.apache.isis.applib.value;
+
+import org.apache.isis.core.commons.collections.Can;
+
+public interface TypedTuple {
+
+ Can<Class<?>> getTypes();
+ Can<Can<?>> getValues();
+
+}
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_Tuples.java b/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_Tuples.java
index daedf41..6720a49 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_Tuples.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_Tuples.java
@@ -19,7 +19,17 @@
package org.apache.isis.core.commons.internal.base;
+import java.io.Serializable;
+import java.util.List;
+
+import javax.persistence.Tuple;
+import javax.persistence.TupleElement;
+
+import org.apache.isis.core.commons.collections.Can;
+import org.apache.isis.core.commons.internal.exceptions._Exceptions;
+
import lombok.Value;
+import lombok.val;
/**
* <h1>- internal use only -</h1>
@@ -74,4 +84,56 @@ public final class _Tuples {
return Indexed.of(index, value);
}
+ // -- JAVAX - PERSISTENCE
+
+ //TODO just a sketch yet
+ @Value(staticConstructor = "of")
+ private static final class TypedTuple implements Tuple {
+
+ final Can<Class<? extends Serializable>> types;
+ final List<Serializable> values;
+
+ @Override
+ public <X> X get(TupleElement<X> tupleElement) {
+ throw _Exceptions.notImplemented();
+ }
+
+ @Override
+ public <X> X get(String alias, Class<X> type) {
+ throw _Exceptions.notImplemented();
+ }
+
+ @Override
+ public Object get(String alias) {
+ throw _Exceptions.notImplemented();
+ }
+
+ @Override
+ public <X> X get(int i, Class<X> requiredType) {
+ val value = values.get(i);
+ return _Casts.uncheckedCast(value);
+ }
+
+ @Override
+ public Object get(int i) {
+ return values.get(i);
+ }
+
+ @Override
+ public Object[] toArray() {
+ throw _Exceptions.notImplemented();
+ }
+
+ @Override
+ public List<TupleElement<?>> getElements() {
+ throw _Exceptions.notImplemented();
+ }
+
+ }
+
+ public static Tuple of(Can<Class<? extends Serializable>> types, List<Serializable> values) {
+ return of(types, values);
+ }
+
+
}
diff --git a/examples/demo/src/main/java/demoapp/dom/package.jdo b/examples/demo/src/main/java/demoapp/dom/package.jdo
index 95a0c4a..4bb35e9 100644
--- a/examples/demo/src/main/java/demoapp/dom/package.jdo
+++ b/examples/demo/src/main/java/demoapp/dom/package.jdo
@@ -8,5 +8,9 @@
<class name="EventLogEntry" />
</package>
+ <package name="demoapp.dom.types.tuple">
+ <class name="NumberConstant" />
+ </package>
+
</jdo>
diff --git a/examples/demo/src/main/java/demoapp/dom/types/tuple/ComplexNumber.java b/examples/demo/src/main/java/demoapp/dom/types/tuple/ComplexNumber.java
new file mode 100644
index 0000000..b43cddc
--- /dev/null
+++ b/examples/demo/src/main/java/demoapp/dom/types/tuple/ComplexNumber.java
@@ -0,0 +1,11 @@
+package demoapp.dom.types.tuple;
+
+import lombok.Value;
+
+@Value(staticConstructor = "of")
+public class ComplexNumber {
+
+ final double re;
+ final double im;
+
+}
diff --git a/examples/demo/src/main/java/demoapp/dom/types/tuple/DnComplexConverter.java b/examples/demo/src/main/java/demoapp/dom/types/tuple/DnComplexConverter.java
new file mode 100644
index 0000000..f3c03d1
--- /dev/null
+++ b/examples/demo/src/main/java/demoapp/dom/types/tuple/DnComplexConverter.java
@@ -0,0 +1,25 @@
+package demoapp.dom.types.tuple;
+
+import org.datanucleus.store.types.converters.MultiColumnConverter;
+import org.datanucleus.store.types.converters.TypeConverter;
+
+public class DnComplexConverter implements TypeConverter<ComplexNumber, double[]>, MultiColumnConverter {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Class[] getDatastoreColumnTypes() {
+ return new Class<?>[] {double.class, double.class};
+ }
+
+ @Override
+ public double[] toDatastoreType(ComplexNumber memberValue) {
+ return new double[] {memberValue.getRe(), memberValue.getIm()};
+ }
+
+ @Override
+ public ComplexNumber toMemberType(double[] datastoreValue) {
+ return ComplexNumber.of(datastoreValue[0], datastoreValue[1]);
+ }
+
+}
diff --git a/examples/demo/src/main/java/demoapp/dom/types/tuple/NumberConstant.java b/examples/demo/src/main/java/demoapp/dom/types/tuple/NumberConstant.java
new file mode 100644
index 0000000..fc45f88
--- /dev/null
+++ b/examples/demo/src/main/java/demoapp/dom/types/tuple/NumberConstant.java
@@ -0,0 +1,36 @@
+package demoapp.dom.types.tuple;
+
+import javax.jdo.annotations.DatastoreIdentity;
+import javax.jdo.annotations.IdGeneratorStrategy;
+import javax.jdo.annotations.IdentityType;
+import javax.jdo.annotations.NotPersistent;
+import javax.jdo.annotations.PersistenceCapable;
+
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Property;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@PersistenceCapable(identityType = IdentityType.DATASTORE, schema = "demo" )
+@DatastoreIdentity(strategy = IdGeneratorStrategy.IDENTITY, column = "id")
+@DomainObject
+public class NumberConstant {
+
+ @javax.jdo.annotations.Column(allowsNull = "false")
+ @Property
+ @Getter @Setter
+ private String name;
+
+ @javax.jdo.annotations.Column(allowsNull = "false")
+ @Property
+ @Getter @Setter
+ private ComplexNumber number;
+
+ @NotPersistent
+ @Property
+ public String getStringified() {
+ return "" + number;
+ }
+
+}
diff --git a/examples/demo/src/main/java/demoapp/dom/types/tuple/NumberConstantRepository.java b/examples/demo/src/main/java/demoapp/dom/types/tuple/NumberConstantRepository.java
new file mode 100644
index 0000000..be828e3
--- /dev/null
+++ b/examples/demo/src/main/java/demoapp/dom/types/tuple/NumberConstantRepository.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demoapp.dom.types.tuple;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.springframework.stereotype.Repository;
+
+import org.apache.isis.applib.services.factory.FactoryService;
+import org.apache.isis.applib.services.repository.RepositoryService;
+
+import lombok.val;
+
+@Repository
+@Named("demoapp.numberConstantRepository")
+public class NumberConstantRepository {
+
+ @Inject private RepositoryService repository;
+ @Inject private FactoryService factory;
+
+ public List<NumberConstant> listAll(){
+ return repository.allInstances(NumberConstant.class);
+ }
+
+ public void add(String name, ComplexNumber number) {
+ val numConst = factory.detachedEntity(NumberConstant.class);
+ numConst.setName(name);
+ numConst.setNumber(number);
+ add(numConst);
+ }
+
+ public void add(NumberConstant entry) {
+ repository.persist(entry);
+ }
+
+}
diff --git a/examples/demo/src/main/java/demoapp/dom/types/tuple/TupleDemo.java b/examples/demo/src/main/java/demoapp/dom/types/tuple/TupleDemo.java
new file mode 100644
index 0000000..b46d066
--- /dev/null
+++ b/examples/demo/src/main/java/demoapp/dom/types/tuple/TupleDemo.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demoapp.dom.types.tuple;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.annotation.Collection;
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Nature;
+
+import demoapp.utils.DemoStub;
+
+@DomainObject(nature=Nature.VIEW_MODEL, objectType = "demo.TupleDemo")
+public class TupleDemo extends DemoStub {
+
+ @Inject private NumberConstantRepository numberConstantRepo;
+
+ @Override
+ public String title() {
+ return "Tuple Demo";
+ }
+
+ @Override
+ public void initDefaults() {
+ if(numberConstantRepo.listAll().size() == 0) {
+ numberConstantRepo.add("Pi", ComplexNumber.of(Math.PI, 0.));
+ numberConstantRepo.add("Euler's Constant", ComplexNumber.of(Math.E, 0.));
+ numberConstantRepo.add("Imaginary Unit", ComplexNumber.of(0, 1.));
+ }
+ }
+
+ @Collection
+ public List<NumberConstant> getAllConstants(){
+ return numberConstantRepo.listAll();
+ }
+
+}
diff --git a/examples/demo/src/main/java/demoapp/dom/types/tuple/TupleDemoMenu.java b/examples/demo/src/main/java/demoapp/dom/types/tuple/TupleDemoMenu.java
new file mode 100644
index 0000000..99c4026
--- /dev/null
+++ b/examples/demo/src/main/java/demoapp/dom/types/tuple/TupleDemoMenu.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demoapp.dom.types.tuple;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.ActionLayout;
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.services.factory.FactoryService;
+
+import lombok.val;
+
+@DomainService(nature=NatureOfService.VIEW, objectType = "demo.TupleDemoMenu")
+@DomainObjectLayout(named="Tuple Demo")
+public class TupleDemoMenu {
+
+ @Inject private FactoryService factoryService;
+
+ @Action
+ @ActionLayout(cssClassFa="fa-bolt")
+ public TupleDemo tupleDemo(){
+ val demo = factoryService.viewModel(TupleDemo.class);
+ demo.initDefaults();
+ return demo;
+ }
+
+
+
+}
diff --git a/examples/demo/src/main/java/demoapp/webapp/menubars.layout.xml b/examples/demo/src/main/java/demoapp/webapp/menubars.layout.xml
index 447d8fa..8500499 100644
--- a/examples/demo/src/main/java/demoapp/webapp/menubars.layout.xml
+++ b/examples/demo/src/main/java/demoapp/webapp/menubars.layout.xml
@@ -66,13 +66,21 @@
<mb3:serviceAction objectType="demo.ErrorMenu" id="errorHandling" />
</mb3:section>
</mb3:menu>
- <mb3:menu>
- <mb3:named>JEE/CDI</mb3:named>
+
+ <mb3:menu>
+ <mb3:named>Experimental</mb3:named>
<mb3:section>
+ <mb3:serviceAction objectType="demo.TupleDemoMenu" id="tupleDemo">
+ <cpt:named>Tuple Types</cpt:named>
+ </mb3:serviceAction>
<mb3:serviceAction objectType="demo.JeeMenu" id="jeeInjectDemo" />
</mb3:section>
</mb3:menu>
+ <mb3:menu>
+
+ </mb3:menu>
+
<mb3:menu unreferencedActions="true">
<mb3:named>Other</mb3:named>
</mb3:menu>
diff --git a/examples/demo/src/main/resources/META-INF/MANIFEST.MF b/examples/demo/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..16687e1
--- /dev/null
+++ b/examples/demo/src/main/resources/META-INF/MANIFEST.MF
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: org.apache.isis.persistence.dn-plugins
+Bundle-SymbolicName: org.apache.isis.persistence.dn-plugins
+Bundle-Version: 1.0.0
+Bundle-Vendor: Apache Isis
diff --git a/examples/demo/src/main/resources/plugin.xml b/examples/demo/src/main/resources/plugin.xml
new file mode 100644
index 0000000..0aaabcf
--- /dev/null
+++ b/examples/demo/src/main/resources/plugin.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<plugin
+ id="org.apache.isis.persistence.dn-plugins"
+ name="org.apache.isis.persistence.dn-plugins"
+ provider-name="Apache Isis">
+
+ <extension point="org.datanucleus.type_converter">
+ <type-converter name="isis.tuple"
+ member-type="demoapp.dom.types.tuple.ComplexNumber"
+ datastore-type="[D"
+ converter-class="demoapp.dom.types.tuple.DnComplexConverter"/>
+ </extension>
+
+</plugin>