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 2020/02/20 07:55:47 UTC
[isis] 05/14: ISIS-2062: updates examples
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 47274d49a7c0e0d1e0ba39b2b5e60277a700abe4
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Feb 19 23:01:56 2020 +0000
ISIS-2062: updates examples
---
.../modules/applib-cm/examples/value/Password.java | 44 ++------
.../examples/services/error/ErrorDetails.java | 2 +-
.../queryresultscache/QueryResultsCache.java | 53 ++++++++--
.../QueryResultsCacheDefault.java | 114 ++++++++++++++++-----
.../examples/services/wrapper/AsyncWrap.java | 84 ++++-----------
5 files changed, 160 insertions(+), 137 deletions(-)
diff --git a/api/applib/src/main/adoc/modules/applib-cm/examples/value/Password.java b/api/applib/src/main/adoc/modules/applib-cm/examples/value/Password.java
index 6026d74..01a8435 100644
--- a/api/applib/src/main/adoc/modules/applib-cm/examples/value/Password.java
+++ b/api/applib/src/main/adoc/modules/applib-cm/examples/value/Password.java
@@ -20,52 +20,22 @@
package org.apache.isis.applib.value;
import java.io.Serializable;
+import java.util.Objects;
import org.apache.isis.applib.annotation.Value;
@Value(semanticsProviderName = "org.apache.isis.core.metamodel.facets.value.password.PasswordValueSemanticsProvider")
+@lombok.Value
public class Password implements Serializable {
+
private static final long serialVersionUID = 1L;
+
private static final String STARS = "********************";
+
private final String password;
- public Password(final String password) {
- this.password = password;
- }
-
public boolean checkPassword(final String password) {
- return this.password.equals(password);
- }
-
- public String getPassword() {
- return password;
- }
-
- @Override
- public boolean equals(final Object other) {
- if (other == this) {
- return true;
- }
- if (other == null) {
- return false;
- }
- return other.getClass() == this.getClass() && equals((Password) other);
- }
-
- public boolean equals(final Password other) {
- final String otherPassword = other.getPassword();
- if (getPassword() == null && otherPassword == null) {
- return true;
- }
- if (getPassword() == null || otherPassword == null) {
- return false;
- }
- return getPassword().equals(otherPassword);
- }
-
- @Override
- public int hashCode() {
- return password != null ? password.hashCode() : 0;
+ return Objects.equals(this.password, password);
}
@Override
@@ -73,6 +43,6 @@ public class Password implements Serializable {
if (password == null) {
return "";
}
- return STARS.substring(0, Math.min(STARS.length(), password.length()));
+ return STARS;
}
}
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/error/ErrorDetails.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/error/ErrorDetails.java
index 7ce5709..19145bb 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/error/ErrorDetails.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/error/ErrorDetails.java
@@ -46,6 +46,6 @@ public class ErrorDetails {
* One per exception cause.
*/
@Getter
- private final List<List<String>> stackDetailListPerCause;
+ private final List<List<String>> stackTraceDetailPerCause;
}
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCache.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCache.java
index 9ff8fd5..323869b 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCache.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCache.java
@@ -21,9 +21,17 @@ package org.apache.isis.applib.services.queryresultscache;
import java.util.Arrays;
import java.util.concurrent.Callable;
-import lombok.AllArgsConstructor;
+import org.apache.isis.core.commons.handler.MethodReferences.Call0;
+import org.apache.isis.core.commons.handler.MethodReferences.Call1;
+import org.apache.isis.core.commons.handler.MethodReferences.Call2;
+import org.apache.isis.core.commons.handler.MethodReferences.Call3;
+import org.apache.isis.core.commons.handler.MethodReferences.Call4;
+import org.apache.isis.core.commons.handler.MethodReferences.Call5;
+
+import lombok.Data;
import lombok.Getter;
+
/**
* This service (API and implementation) provides a mechanism by which idempotent query results can be cached for the duration of an interaction.
* Most commonly this allows otherwise "naive" - eg that makes a repository call many times within a loop - to
@@ -37,10 +45,31 @@ import lombok.Getter;
// tag::refguide[]
public interface QueryResultsCache {
-// end::refguide[]
+ <T> T execute(Callable<T> callable, Class<?> callingClass, String methodName, Object... keys);
+
+ <R> R execute(Call0<? extends R> action, Class<?> callingClass, String methodName);
+
+ <R, A0> R execute(Call1<? extends R, A0> action, Class<?> callingClass, String methodName,
+ A0 arg0);
+
+ <R, A0, A1> R execute(Call2<? extends R, A0, A1> action, Class<?> callingClass, String methodName,
+ A0 arg0, A1 arg1);
+
+ <R, A0, A1, A2> R execute(Call3<? extends R, A0, A1, A2> action, Class<?> callingClass, String methodName,
+ A0 arg0, A1 arg1, A2 arg2);
+
+ <R, A0, A1, A2, A3> R execute(Call4<? extends R, A0, A1, A2, A3> action, Class<?> callingClass, String methodName,
+ A0 arg0, A1 arg1, A2 arg2, A3 arg3);
+
+ <R, A0, A1, A2, A3, A4> R execute(Call5<? extends R, A0, A1, A2, A3, A4> action, Class<?> callingClass, String methodName,
+ A0 arg0, A1 arg1, A2 arg2, A3 arg3, A4 arg4);
+
+ void resetForNextTransaction();
- @AllArgsConstructor
+// end::refguide[]
+// tag::refguide-1[]
class Key {
+
@Getter
private final Class<?> callingClass;
@Getter
@@ -48,6 +77,12 @@ public interface QueryResultsCache {
@Getter
private final Object[] keys;
+ public Key(Class<?> callingClass, String methodName, Object... keys) {
+ this.callingClass = callingClass;
+ this.methodName = methodName;
+ this.keys = keys;
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -95,19 +130,15 @@ public interface QueryResultsCache {
return callingClass.getName() + "#" + methodName + Arrays.toString(keys);
}
}
+// end::refguide-1[]
- // -- VALUE
-
- @AllArgsConstructor
+// tag::refguide-2[]
+ @Data
class Value<T> {
- @Getter
private final T result;
}
+// end::refguide-2[]
// tag::refguide[]
- <T> T execute(Callable<T> callable, Class<?> callingClass, String methodName, Object... keys);
-
- void resetForNextTransaction();
-
}
// end::refguide[]
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCacheDefault.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCacheDefault.java
index 6f3e79c..5ddf15c 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCacheDefault.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCacheDefault.java
@@ -32,6 +32,12 @@ import org.springframework.stereotype.Service;
import org.apache.isis.applib.annotation.OrderPrecedence;
import org.apache.isis.applib.services.WithTransactionScope;
+import org.apache.isis.core.commons.handler.MethodReferences.Call0;
+import org.apache.isis.core.commons.handler.MethodReferences.Call1;
+import org.apache.isis.core.commons.handler.MethodReferences.Call2;
+import org.apache.isis.core.commons.handler.MethodReferences.Call3;
+import org.apache.isis.core.commons.handler.MethodReferences.Call4;
+import org.apache.isis.core.commons.handler.MethodReferences.Call5;
import org.apache.isis.core.commons.internal.base._Casts;
import org.apache.isis.core.commons.internal.base._NullSafe;
import org.apache.isis.core.commons.internal.collections._Maps;
@@ -58,6 +64,64 @@ import lombok.extern.log4j.Log4j2;
public class QueryResultsCacheDefault implements QueryResultsCache, WithTransactionScope {
private final Map<Key, Value<?>> cache = _Maps.newHashMap();
+
+ @Override
+ public <R> R execute(Call0<? extends R> action, Class<?> callingClass, String methodName) {
+ if(isIgnoreCache()) {
+ return action.call();
+ }
+ final Key cacheKey = new Key(callingClass, methodName);
+ return executeWithCaching(()->action.call(), cacheKey);
+ }
+
+ @Override
+ public <R, A0> R execute(Call1<? extends R, A0> action, Class<?> callingClass, String methodName, A0 arg0) {
+ if(isIgnoreCache()) {
+ return action.call(arg0);
+ }
+ final Key cacheKey = new Key(callingClass, methodName, arg0);
+ return executeWithCaching(()->action.call(arg0), cacheKey);
+ }
+
+ @Override
+ public <R, A0, A1> R execute(Call2<? extends R, A0, A1> action, Class<?> callingClass, String methodName, A0 arg0,
+ A1 arg1) {
+ if(isIgnoreCache()) {
+ return action.call(arg0, arg1);
+ }
+ final Key cacheKey = new Key(callingClass, methodName, arg0, arg1);
+ return executeWithCaching(()->action.call(arg0, arg1), cacheKey);
+ }
+
+ @Override
+ public <R, A0, A1, A2> R execute(Call3<? extends R, A0, A1, A2> action, Class<?> callingClass, String methodName,
+ A0 arg0, A1 arg1, A2 arg2) {
+ if(isIgnoreCache()) {
+ return action.call(arg0, arg1, arg2);
+ }
+ final Key cacheKey = new Key(callingClass, methodName, arg0, arg1, arg2);
+ return executeWithCaching(()->action.call(arg0, arg1, arg2), cacheKey);
+ }
+
+ @Override
+ public <R, A0, A1, A2, A3> R execute(Call4<? extends R, A0, A1, A2, A3> action, Class<?> callingClass,
+ String methodName, A0 arg0, A1 arg1, A2 arg2, A3 arg3) {
+ if(isIgnoreCache()) {
+ return action.call(arg0, arg1, arg2, arg3);
+ }
+ final Key cacheKey = new Key(callingClass, methodName, arg0, arg1, arg2, arg3);
+ return executeWithCaching(()->action.call(arg0, arg1, arg2, arg3), cacheKey);
+ }
+
+ @Override
+ public <R, A0, A1, A2, A3, A4> R execute(Call5<? extends R, A0, A1, A2, A3, A4> action, Class<?> callingClass,
+ String methodName, A0 arg0, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
+ if(isIgnoreCache()) {
+ return action.call(arg0, arg1, arg2, arg3, arg4);
+ }
+ final Key cacheKey = new Key(callingClass, methodName, arg0, arg1, arg2, arg3, arg4);
+ return executeWithCaching(()->action.call(arg0, arg1, arg2, arg3, arg4), cacheKey);
+ }
@Override
public <T> T execute(
@@ -76,18 +140,6 @@ public class QueryResultsCacheDefault implements QueryResultsCache, WithTransact
return executeWithCaching(callable, cacheKey);
}
-//XXX not used
-// private <T> T execute(final Callable<T> callable, final Key cacheKey) {
-// if(isIgnoreCache()) {
-// try {
-// return callable.call();
-// } catch (Exception e) {
-// throw new RuntimeException(e);
-// }
-// }
-// return executeWithCaching(callable, cacheKey);
-// }
-
private <T> T executeWithCaching(final Callable<T> callable, final Key cacheKey) {
try {
final Value<?> cacheValue = cache.get(cacheKey);
@@ -113,18 +165,6 @@ public class QueryResultsCacheDefault implements QueryResultsCache, WithTransact
}
}
-//XXX not used
-// private <T> Value<T> get(final Class<?> callingClass, final String methodName, final Object... keys) {
-// return get(new Key(callingClass, methodName, keys));
-// }
-//
-// @SuppressWarnings("unchecked")
-// private <T> Value<T> get(final Key cacheKey) {
-// Value<T> value = (Value<T>) cache.get(cacheKey);
-// logHitOrMiss(cacheKey, value);
-// return value;
-// }
-
private <T> void put(final Key cacheKey, final T result) {
log.debug("PUT: {}", cacheKey);
cache.put(cacheKey, new Value<T>(result));
@@ -159,5 +199,31 @@ public class QueryResultsCacheDefault implements QueryResultsCache, WithTransact
return _NullSafe.stream(cacheControl)
.anyMatch(c->c.isIgnoreCache());
}
+
+ // -- REMOVED
+
+ //XXX not used
+// private <T> Value<T> get(final Class<?> callingClass, final String methodName, final Object... keys) {
+// return get(new Key(callingClass, methodName, keys));
+// }
+//
+// @SuppressWarnings("unchecked")
+// private <T> Value<T> get(final Key cacheKey) {
+// Value<T> value = (Value<T>) cache.get(cacheKey);
+// logHitOrMiss(cacheKey, value);
+// return value;
+// }
+
+ //XXX not used
+// private <T> T execute(final Callable<T> callable, final Key cacheKey) {
+// if(isIgnoreCache()) {
+// try {
+// return callable.call();
+// } catch (Exception e) {
+// throw new RuntimeException(e);
+// }
+// }
+// return executeWithCaching(callable, cacheKey);
+// }
}
\ No newline at end of file
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/wrapper/AsyncWrap.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/wrapper/AsyncWrap.java
index 9b4bdd3..f042d97 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/wrapper/AsyncWrap.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/wrapper/AsyncWrap.java
@@ -24,6 +24,16 @@ import java.util.function.Consumer;
import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode;
import org.apache.isis.core.commons.collections.ImmutableEnumSet;
+import org.apache.isis.core.commons.handler.MethodReferences.Call1;
+import org.apache.isis.core.commons.handler.MethodReferences.Call2;
+import org.apache.isis.core.commons.handler.MethodReferences.Call3;
+import org.apache.isis.core.commons.handler.MethodReferences.Call4;
+import org.apache.isis.core.commons.handler.MethodReferences.Call5;
+import org.apache.isis.core.commons.handler.MethodReferences.Run1;
+import org.apache.isis.core.commons.handler.MethodReferences.Run2;
+import org.apache.isis.core.commons.handler.MethodReferences.Run3;
+import org.apache.isis.core.commons.handler.MethodReferences.Run4;
+import org.apache.isis.core.commons.handler.MethodReferences.Run5;
/**
* Binds to a domain object, to prepare for type-safe asynchronous action invocation.
@@ -35,60 +45,6 @@ import org.apache.isis.core.commons.collections.ImmutableEnumSet;
*/
public interface AsyncWrap<T> {
- // -- METHOD REFERENCE MATCHERS (WITHOUT RETURN VALUE)
-
- @FunctionalInterface
- public static interface Run0<T> {
- void run(T obj);
- }
-
- @FunctionalInterface
- public static interface Run1<T, A1> {
- void run(T obj, A1 arg1);
- }
-
- @FunctionalInterface
- public static interface Run2<T, A1, A2> {
- void run(T obj, A1 arg1, A2 arg2);
- }
-
- @FunctionalInterface
- public static interface Run3<T, A1, A2, A3> {
- void run(T obj, A1 arg1, A2 arg2, A3 arg3);
- }
-
- @FunctionalInterface
- public static interface Run4<T, A1, A2, A3, A4> {
- void run(T obj, A1 arg1, A2 arg2, A3 arg3, A4 arg4);
- }
-
- // -- METHOD REFERENCE MATCHERS (WITH RETURN VALUE)
-
- @FunctionalInterface
- public static interface Call0<T, R> {
- R call(T obj);
- }
-
- @FunctionalInterface
- public static interface Call1<T, R, A1> {
- R call(T obj, A1 arg1);
- }
-
- @FunctionalInterface
- public static interface Call2<T, R, A1, A2> {
- R call(T obj, A1 arg1, A2 arg2);
- }
-
- @FunctionalInterface
- public static interface Call3<T, R, A1, A2, A3> {
- R call(T obj, A1 arg1, A2 arg2, A3 arg3);
- }
-
- @FunctionalInterface
- public static interface Call4<T, R, A1, A2, A3, A4> {
- R call(T obj, A1 arg1, A2 arg2, A3 arg3, A4 arg4);
- }
-
// -- CONFIGURATION
ExecutorService getExecutor();
@@ -101,30 +57,30 @@ public interface AsyncWrap<T> {
// -- INVOCATION (WITH RETURN VALUE)
- <R> Future<R> call(Call0<? super T, ? extends R> action);
+ <R> Future<R> call(Call1<? extends R, ? super T> action);
- <R, A1> Future<R> call(Call1<? super T, ? extends R, A1> action,
+ <R, A1> Future<R> call(Call2<? extends R, ? super T, A1> action,
A1 arg1);
- <R, A1, A2> Future<R> call(Call2<? super T, ? extends R, A1, A2> action,
+ <R, A1, A2> Future<R> call(Call3<? extends R, ? super T, A1, A2> action,
A1 arg1, A2 arg2);
- <R, A1, A2, A3> Future<R> call(Call3<? super T, ? extends R, A1, A2, A3> action,
+ <R, A1, A2, A3> Future<R> call(Call4<? extends R, ? super T, A1, A2, A3> action,
A1 arg1, A2 arg2, A3 arg3);
- <R, A1, A2, A3, A4> Future<R> call(Call4<? super T, ? extends R, A1, A2, A3, A4> action,
+ <R, A1, A2, A3, A4> Future<R> call(Call5<? extends R, ? super T, A1, A2, A3, A4> action,
A1 arg1, A2 arg2, A3 arg3, A4 arg4);
// -- INVOCATION (WITHOUT RETURN VALUE)
- default Future<Void> run(Run0<? super T> action) {
+ default Future<Void> run(Run1<? super T> action) {
return call(obj->{
action.run(obj);
return null;
});
}
- default <A1> Future<Void> run(Run1<? super T, A1> action,
+ default <A1> Future<Void> run(Run2<? super T, A1> action,
A1 arg1) {
return call(obj->{
@@ -133,7 +89,7 @@ public interface AsyncWrap<T> {
});
}
- default <A1, A2> Future<Void> run(Run2<? super T, A1, A2> action,
+ default <A1, A2> Future<Void> run(Run3<? super T, A1, A2> action,
A1 arg1, A2 arg2) {
return call(obj->{
@@ -142,7 +98,7 @@ public interface AsyncWrap<T> {
});
}
- default <A1, A2, A3> Future<Void> run(Run3<? super T, A1, A2, A3> action,
+ default <A1, A2, A3> Future<Void> run(Run4<? super T, A1, A2, A3> action,
A1 arg1, A2 arg2, A3 arg3) {
return call(obj->{
@@ -151,7 +107,7 @@ public interface AsyncWrap<T> {
});
}
- default <A1, A2, A3, A4> Future<Void> run(Run4<? super T, A1, A2, A3, A4> action,
+ default <A1, A2, A3, A4> Future<Void> run(Run5<? super T, A1, A2, A3, A4> action,
A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
return call(obj->{