#2219 - Compile error with ZonedDateTime and query beans - type argument java.time.ZonedDateTime is not within bounds of type-variable D

This commit is contained in:
Robin Bygrave
2021-04-19 17:04:57 +12:00
parent 65b282a056
commit 9d54b264ad
5 changed files with 77 additions and 18 deletions
@@ -0,0 +1,50 @@
package io.ebean.typequery;
import java.time.ZonedDateTime;
/**
* ZonedDateTime property.
*
* @param <R> the root query bean type
*/
public class PZonedDateTime<R> extends PBaseCompareable<R, ZonedDateTime> {
/**
* Construct with a property name and root instance.
*
* @param name property name
* @param root the root query bean instance
*/
public PZonedDateTime(String name, R root) {
super(name, root);
}
/**
* Construct with additional path prefix.
*/
public PZonedDateTime(String name, R root, String prefix) {
super(name, root, prefix);
}
/**
* Same as greater than.
*
* @param value the equal to bind value
* @return the root query bean instance
*/
public R after(ZonedDateTime value) {
expr().gt(_name, value);
return _root;
}
/**
* Same as less than.
*
* @param value the equal to bind value
* @return the root query bean instance
*/
public R before(ZonedDateTime value) {
expr().lt(_name, value);
return _root;
}
}
@@ -3,6 +3,7 @@ package org.example.domain;
import io.ebean.annotation.DbArray;
import javax.persistence.*;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -11,33 +12,35 @@ import java.util.Map;
* Contact entity bean.
*/
@Entity
@Table(name="be_contact")
@Table(name = "be_contact")
public class Contact extends BaseModel {
@DbArray
List<String> phoneNumbers = new ArrayList();
List<String> phoneNumbers = new ArrayList<>();
@Column(length=50)
@Column(length = 50)
String firstName;
@Column(length=50)
@Column(length = 50)
String lastName;
@Column(length=200)
@Column(length = 200)
String email;
@Column(length=20)
@Column(length = 20)
String phone;
@ManyToOne(optional=false)
ZonedDateTime zoneDateTime;
@ManyToOne(optional = false)
Customer customer;
@OneToMany(mappedBy = "contact")
List<ContactNote> notes;
@OneToMany(cascade = CascadeType.PERSIST)
@MapKey(name="key")
Map<String,ContactOther> others;
@MapKey(name = "key")
Map<String, ContactOther> others;
/**
* Default constructor.
@@ -85,6 +88,14 @@ public class Contact extends BaseModel {
this.phone = phone;
}
public ZonedDateTime getZoneDateTime() {
return zoneDateTime;
}
public void setZoneDateTime(ZonedDateTime zoneDateTime) {
this.zoneDateTime = zoneDateTime;
}
public Customer getCustomer() {
return customer;
}
@@ -3,13 +3,15 @@ package org.querytest;
import org.example.domain.query.QContact;
import org.junit.Test;
import java.time.ZonedDateTime;
public class QContactTest {
@Test
public void test_oneToManyMap() {
new QContact()
.others.fetch()
.zoneDateTime.before(ZonedDateTime.now())
.findList();
}
}
@@ -25,10 +25,9 @@ class PropertyTypeMap {
*/
private final PropertyType dbJsonType = new PropertyType("PJson");
private Map<String,PropertyType> map = new HashMap<>();
private final Map<String,PropertyType> map = new HashMap<>();
PropertyTypeMap() {
map.put("boolean", new PropertyType("PBoolean"));
map.put("short", new PropertyType("PShort"));
map.put("int", new PropertyType("PInteger"));
@@ -57,7 +56,6 @@ class PropertyTypeMap {
addType(Locale.class);
addType(File.class);
addType(InetAddress.class);
map.put(URI.class.getName(), new PropertyType("PUri"));
map.put(URL.class.getName(), new PropertyType("PUrl"));
map.put(UUID.class.getName(), new PropertyType("PUuid"));
@@ -74,7 +72,6 @@ class PropertyTypeMap {
}
private void addJava8Types() {
try {
Class.forName("java.time.Instant");
} catch (ClassNotFoundException e) {
@@ -94,6 +91,7 @@ class PropertyTypeMap {
addType(java.time.YearMonth.class);
addType(java.time.ZoneId.class);
addType(java.time.ZoneOffset.class);
addType(java.time.ZonedDateTime.class);
}
private void addJodaTypes() {
@@ -25,10 +25,9 @@ class PropertyTypeMap {
*/
private final PropertyType dbJsonType = new PropertyType("PJson");
private Map<String,PropertyType> map = new HashMap<>();
private final Map<String,PropertyType> map = new HashMap<>();
PropertyTypeMap() {
map.put("boolean", new PropertyType("PBoolean"));
map.put("short", new PropertyType("PShort"));
map.put("int", new PropertyType("PInteger"));
@@ -57,7 +56,6 @@ class PropertyTypeMap {
map.put("java.lang.Class<?>", new PropertyType("PClass"));
addType(File.class);
addType(InetAddress.class);
map.put(URI.class.getName(), new PropertyType("PUri"));
map.put(URL.class.getName(), new PropertyType("PUrl"));
map.put(UUID.class.getName(), new PropertyType("PUuid"));
@@ -73,7 +71,6 @@ class PropertyTypeMap {
}
private void addJava8Types() {
try {
Class.forName("java.time.Instant");
} catch (ClassNotFoundException e) {
@@ -93,6 +90,7 @@ class PropertyTypeMap {
addType(java.time.YearMonth.class);
addType(java.time.ZoneId.class);
addType(java.time.ZoneOffset.class);
addType(java.time.ZonedDateTime.class);
}
private void addJodaTypes() {