mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Scalar type querybeans generics error (#2082)
* Add failing test case for generic querybeans Types with generics arguments have not been processed correctly, they will lose their generics. This is not critical in Java, as the language has to be backwards compatible with Java 1.4, but will still become highlighted as a warning in all common IDEs. In Kotlin however, it's not a warning but a compile error. * Fix problem with generics in scalar type arg This fixes the issue introduced with ScalarType aware querybeans.
This commit is contained in:
1 parent
ee73fd47d5
commit
bcc8040afe
27 files changed
+427
-143
No files matched your search
@@ -1,40 +0,0 @@
|
||||
package io.ebean.querybean.generator;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
public class SplitTest {
|
||||
|
||||
@Test
|
||||
public void trimType() {
|
||||
assertEquals(Split.trimType("com.foo.domain.Customer"), "com.foo.domain.Customer");
|
||||
assertEquals(Split.trimType("? extends com.foo.domain.Customer"), "com.foo.domain.Customer");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortName() {
|
||||
assertEquals(Split.shortName("com.foo.domain.Customer"), "Customer");
|
||||
assertEquals(Split.shortName("Customer"), "Customer");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void split_normal() {
|
||||
|
||||
String[] split = Split.split("com.foo.domain.Customer");
|
||||
|
||||
assertEquals(split[0], "com.foo.domain");
|
||||
assertEquals(split[1], "Customer");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void split_noPackage() {
|
||||
|
||||
String[] split = Split.split("Customer");
|
||||
|
||||
assertNull(split[0]);
|
||||
assertEquals(split[1], "Customer");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.ebean.querybean.generator
|
||||
|
||||
import org.testng.Assert.assertEquals
|
||||
import org.testng.Assert.assertNull
|
||||
import org.testng.annotations.Test
|
||||
import java.lang.Exception
|
||||
import java.util.Arrays
|
||||
import java.util.HashSet
|
||||
|
||||
class SplitTest {
|
||||
@Test
|
||||
fun trimType() {
|
||||
assertEquals(Split.trimType("com.foo.domain.Customer"), "com.foo.domain.Customer")
|
||||
assertEquals(Split.trimType("? extends com.foo.domain.Customer"), "com.foo.domain.Customer")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shortName() {
|
||||
assertEquals(Split.shortName("com.foo.domain.Customer"), "Customer")
|
||||
assertEquals(Split.shortName("Customer"), "Customer")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun split_normal() {
|
||||
val split = Split.split("com.foo.domain.Customer")
|
||||
assertEquals(split[0], "com.foo.domain")
|
||||
assertEquals(split[1], "Customer")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun split_noPackage() {
|
||||
val split = Split.split("Customer")
|
||||
assertNull(split[0])
|
||||
assertEquals(split[1], "Customer")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun split_generics() {
|
||||
assertEquals("Foo<Bar, XFoo<XBar>>", Split.genericsSplit("com.Foo<com.Bar, org.XFoo<org.XBar>>").key)
|
||||
assertEquals(
|
||||
HashSet(Arrays.asList("com.Foo", "com.Bar", "org.XFoo", "org.XBar")),
|
||||
Split.genericsSplit("com.Foo<com.Bar, org.XFoo<org.XBar>>").value
|
||||
)
|
||||
assertEquals("Foo", Split.genericsSplit("com.bar.Foo").key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.example.domain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.example.otherpackage.GenericType;
|
||||
import org.example.otherpackage.GenericTypeArgument;
|
||||
|
||||
/**
|
||||
* Address entity bean.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "o_address")
|
||||
class Address(
|
||||
@Size(max = 100)
|
||||
var line1: String,
|
||||
@Size(max = 100)
|
||||
var line2: String,
|
||||
@Size(max = 100)
|
||||
var city: String,
|
||||
// Dummy metadata field just to test generation
|
||||
val metadata: GenericType<GenericTypeArgument>
|
||||
) : BaseModel()
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.example.domain;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.WhenCreated;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
|
||||
@MappedSuperclass
|
||||
abstract class BaseModel : Model() {
|
||||
@Id
|
||||
val id: Long? = null
|
||||
|
||||
@Version
|
||||
val version: Int = 0
|
||||
|
||||
@WhenCreated
|
||||
val whenCreated: Instant? = null
|
||||
|
||||
@WhenModified
|
||||
val whenModified: Instant? = null
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
interface Email<T> : Comparable<T>
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
class GenericType<T>(
|
||||
val data: T
|
||||
)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
enum class GenericTypeArgument {
|
||||
FOO,
|
||||
BAR,
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
import javax.persistence.AttributeConverter
|
||||
import javax.persistence.Converter
|
||||
|
||||
@Converter
|
||||
class GenericTypeAttributeConverter : AttributeConverter<GenericType<GenericTypeArgument>, String> {
|
||||
override fun convertToDatabaseColumn(attribute: GenericType<GenericTypeArgument>): String {
|
||||
return attribute.data.name
|
||||
}
|
||||
|
||||
override fun convertToEntityAttribute(dbData: String): GenericType<GenericTypeArgument> {
|
||||
return GenericType(GenericTypeArgument.valueOf(dbData))
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
import javax.persistence.AttributeConverter
|
||||
import javax.persistence.Converter
|
||||
|
||||
@Converter
|
||||
class PhoneAttributeConverter : AttributeConverter<PhoneNumber, String> {
|
||||
override fun convertToDatabaseColumn(attribute: PhoneNumber): String {
|
||||
return attribute.msisdn
|
||||
}
|
||||
|
||||
override fun convertToEntityAttribute(dbData: String): PhoneNumber {
|
||||
return PhoneNumber(dbData)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
class PhoneNumber(
|
||||
val msisdn: String
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
class ValidEmail(
|
||||
val emailAddress: String
|
||||
) : Email<ValidEmail> {
|
||||
override fun compareTo(other: ValidEmail): Int {
|
||||
return emailAddress.compareTo(other.emailAddress)
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package org.example.otherpackage
|
||||
|
||||
import javax.persistence.AttributeConverter
|
||||
import javax.persistence.Converter
|
||||
|
||||
@Converter
|
||||
class ValidEmailAttributeConverter : AttributeConverter<ValidEmail, String> {
|
||||
override fun convertToDatabaseColumn(attribute: ValidEmail): String {
|
||||
return attribute.emailAddress
|
||||
}
|
||||
|
||||
override fun convertToEntityAttribute(dbData: String): ValidEmail {
|
||||
return ValidEmail(dbData)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user