Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OPENJPA-2915] properties of type Duration can be set as expected #114

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -428,6 +429,11 @@ private Object stringToObject(String str, Class<?> type) throws Exception {
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 {
Expand Down Expand Up @@ -627,7 +633,7 @@ public String removeProperty(String key, String key2, String def) {
*/
private static class EmptyOptions extends Options {


private static final long serialVersionUID = 1L;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.openjpa.lib.util;

import java.time.Duration;
import java.util.Properties;

import org.junit.Before;
Expand Down Expand Up @@ -103,9 +104,11 @@ public void testSetObject() {
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());
}

/**
Expand All @@ -124,6 +127,7 @@ public static class Inner {
private Inner _nullInner = null;
private int[] _range1 = new int[2];
private int[] _range2 = new int[2];
private Duration _maxWait = Duration.ofMillis(-1);

public Inner() {
}
Expand Down Expand Up @@ -200,6 +204,14 @@ public Inner getNullInner() {
public void setNullInner(Inner in) {
_nullInner = in;
}

public Duration getMaxWait() {
return _maxWait;
}

public void setMaxWait(Duration dur) {
_maxWait = dur;
}
}

/**
Expand Down