This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git
The following commit(s) were added to refs/heads/master by this push:
new 33372a718 [OPENJPA-2915] properties of type Duration can be set as
expected (#114)
33372a718 is described below
commit 33372a718ef48243f7774af43c4172d8407dfe18
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Wed Oct 11 15:09:37 2023 +0700
[OPENJPA-2915] properties of type Duration can be set as expected (#114)
---
.../src/main/java/org/apache/openjpa/lib/util/Options.java | 8 +++++++-
.../test/java/org/apache/openjpa/lib/util/TestOptions.java | 12 ++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
index 73a606141..2e9007cd3 100644
--- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
+++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
@@ -24,6 +24,7 @@ import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedActionException;
+import java.time.Duration;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -428,6 +429,11 @@ public class Options extends TypedProperties {
if (type == primWrapper[0])
return stringToObject(str, (Class<?>) primWrapper[1]);
+ // special case for Durations
+ if (type == Duration.class) {
+ return Duration.ofMillis(Long.valueOf(str));
+ }
+
// look for a string constructor
Exception err = null;
try {
@@ -627,7 +633,7 @@ public class Options extends TypedProperties {
*/
private static class EmptyOptions extends Options {
-
+
private static final long serialVersionUID = 1L;
@Override
diff --git
a/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestOptions.java
b/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestOptions.java
index c1ae1a736..0bd23f492 100644
--- a/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestOptions.java
+++ b/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestOptions.java
@@ -18,6 +18,7 @@
*/
package org.apache.openjpa.lib.util;
+import java.time.Duration;
import java.util.Properties;
import org.junit.Before;
@@ -103,9 +104,11 @@ public class TestOptions {
inner = new Inner();
opts = new Options();
opts.setProperty("mixed", "STR,1");
+ opts.setProperty("maxWait", "10000");
opts.setInto(inner);
assertEquals(1, inner.getInt());
assertEquals("STR", inner.getString());
+ assertEquals(10_000, inner.getMaxWait().toMillis());
}
/**
@@ -124,6 +127,7 @@ public class TestOptions {
private Inner _nullInner = null;
private int[] _range1 = new int[2];
private int[] _range2 = new int[2];
+ private Duration _maxWait = Duration.ofMillis(-1);
public Inner() {
}
@@ -200,6 +204,14 @@ public class TestOptions {
public void setNullInner(Inner in) {
_nullInner = in;
}
+
+ public Duration getMaxWait() {
+ return _maxWait;
+ }
+
+ public void setMaxWait(Duration dur) {
+ _maxWait = dur;
+ }
}
/**