diff --git a/ebean-querybean/src/test/java/org/example/domain/Alias.java b/ebean-querybean/src/test/java/org/example/domain/Alias.java new file mode 100644 index 0000000000..9a5b38e24f --- /dev/null +++ b/ebean-querybean/src/test/java/org/example/domain/Alias.java @@ -0,0 +1,14 @@ +package org.example.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Version; + +@Entity +public class Alias { + + @Id + long id; + @Version + long version; +} diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Constants.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Constants.java index d1e5362215..5d79384586 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Constants.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/Constants.java @@ -2,9 +2,8 @@ interface Constants { - String AT_GENERATED = "@Generated(\"io.ebean.querybean.kotlin-generator\")"; - String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")"; - String GENERATED = "io.ebean.typequery.Generated"; + String AT_GENERATED = "@io.ebean.typequery.Generated(\"io.ebean.querybean.kotlin-generator\")"; + String AT_TYPEQUERYBEAN = "@io.ebean.typequery.TypeQueryBean(\"v1\")"; String MAPPED_SUPERCLASS = "jakarta.persistence.MappedSuperclass"; String DISCRIMINATOR_VALUE = "jakarta.persistence.DiscriminatorValue"; @@ -19,16 +18,9 @@ interface Constants { String DBJSONB = "io.ebean.annotation.DbJsonB"; String DBNAME = "io.ebean.annotation.DbName"; - String TQROOTBEAN = "io.ebean.typequery.TQRootBean"; String TQASSOC = "io.ebean.typequery.TQAssoc"; String TQASSOCBEAN = "io.ebean.typequery.TQAssocBean"; String TQPROPERTY = "io.ebean.typequery.TQProperty"; - String TYPEQUERYBEAN = "io.ebean.typequery.TypeQueryBean"; - String DATABASE = "io.ebean.Database"; - String DB = "io.ebean.DB"; - String FETCHGROUP = "io.ebean.FetchGroup"; - String QUERY = "io.ebean.Query"; - String TRANSACTION = "io.ebean.Transaction"; String MODULEINFO = "io.ebean.config.ModuleInfo"; String METAINF_MANIFEST = "META-INF/ebean-generated-info.mf"; diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java index d92383e970..245a07ac8d 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java @@ -3,17 +3,7 @@ class KotlinLangAdapter implements LangAdapter { @Override - public void beginClass(Append writer, String shortName) { - writer.append("class Q%s : TQRootBean<%1$s, Q%1$s> {", shortName).eol(); - } - - @Override - public void beginAssocClass(Append writer, String shortName, String origShortName) { -// writer.append("class Q%s : TQAssocBean<%s,R> {", shortName, origShortName).eol(); - } - - @Override - public void alias(Append writer, String shortName) { + public void alias(Append writer, String shortName, String fullName) { writer.append(" companion object {").eol(); writer.append(" /**").eol(); writer.append(" * shared 'Alias' instance used to provide").eol(); @@ -25,7 +15,7 @@ public void alias(Append writer, String shortName) { writer.append(" * Return a query bean used to build a FetchGroup.").eol(); writer.append(" */").eol(); writer.append(" fun forFetchGroup(): Q%s {", shortName).eol(); - writer.append(" return Q%s(FetchGroup.queryFor(%s::class.java));", shortName, shortName).eol(); + writer.append(" return Q%s(io.ebean.FetchGroup.queryFor(%s::class.java));", shortName, fullName).eol(); writer.append(" }").eol(); writer.append(" }").eol().eol(); } @@ -59,31 +49,31 @@ private void writeAssocBeanFetch(Append writer, String origShortName, String fet } @Override - public void rootBeanConstructor(Append writer, String shortName, String dbName) { + public void rootBeanConstructor(Append writer, String shortName, String dbName, String fullName) { String name = (dbName == null) ? "default" : dbName; writer.append(" /**").eol(); writer.append(" * Construct using the %s Database.", name).eol(); writer.append(" */").eol(); if (dbName == null) { - writer.append(" constructor() : super(%s::class.java)", shortName).eol().eol(); + writer.append(" constructor() : super(%s::class.java)", fullName).eol().eol(); } else { - writer.append(" constructor() : super(%s::class.java, DB.byName(\"%s\"))", shortName, dbName).eol().eol(); + writer.append(" constructor() : super(%s::class.java, io.ebean.DB.byName(\"%s\"))", fullName, dbName).eol().eol(); } writer.append(" /**").eol(); writer.append(" * Construct with a given Transaction.", name).eol(); writer.append(" */").eol(); if (dbName == null) { - writer.append(" constructor(transaction: Transaction) : super(%s::class.java, transaction)", shortName).eol().eol(); + writer.append(" constructor(transaction: io.ebean.Transaction) : super(%s::class.java, transaction)", fullName).eol().eol(); } else { - writer.append(" constructor(transaction: Transaction) : super(%s::class.java, DB.byName(\"%s\"), transaction)", shortName, dbName).eol().eol(); + writer.append(" constructor(transaction: io.ebean.Transaction) : super(%s::class.java, io.ebean.DB.byName(\"%s\"), transaction)", fullName, dbName).eol().eol(); } writer.eol(); writer.append(" /**").eol(); writer.append(" * Construct with a given Database.").eol(); writer.append(" */").eol(); - writer.append(" constructor(database: Database) : super(%s::class.java, database)", shortName).eol().eol(); + writer.append(" constructor(database: io.ebean.Database) : super(%s::class.java, database)", fullName).eol().eol(); writer.append(" /**").eol(); writer.append(" * Construct for Alias.").eol(); @@ -93,7 +83,7 @@ public void rootBeanConstructor(Append writer, String shortName, String dbName) writer.append(" /**").eol(); writer.append(" * Private constructor for FetchGroup building.").eol(); writer.append(" */").eol(); - writer.append(" private constructor(fetchGroupQuery: Query<%s>) : super(fetchGroupQuery)", shortName).eol(); + writer.append(" private constructor(fetchGroupQuery: io.ebean.Query<%s>) : super(fetchGroupQuery)", fullName).eol(); writer.eol(); writer.append(" /** Return a copy of the query. */").eol(); diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/LangAdapter.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/LangAdapter.java index 3c7dba0652..9bb48e39d7 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/LangAdapter.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/LangAdapter.java @@ -2,13 +2,10 @@ public interface LangAdapter { - void beginClass(Append writer, String shortName); - void beginAssocClass(Append writer, String shortName, String origShortName); + void alias(Append writer, String shortName, String beanFullName); - void alias(Append writer, String shortName); - - void rootBeanConstructor(Append writer, String shortName, String dbName); + void rootBeanConstructor(Append writer, String shortName, String dbName, String beanFullName); void assocBeanConstructor(Append writer, String shortName); diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java index a3a68f74a6..fd4f92438d 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleModuleInfoWriter.java @@ -91,7 +91,6 @@ private void writePackage() { writer.append("import java.util.ArrayList;").eol(); writer.append("import java.util.Collections;").eol(); writer.append("import java.util.List;").eol(); - writer.append("import %s;", Constants.GENERATED).eol(); writer.eol(); writer.append("import io.ebean.config.ModuleInfo;").eol(); writer.append("import io.ebean.config.EntityClassRegister;").eol(); diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java index 01b398fe3f..9bc4edbfad 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java @@ -123,22 +123,11 @@ private LangAdapter lang() { } private void gatherPropertyDetails() { - importTypes.add(Constants.GENERATED); - importTypes.add(beanFullName); - importTypes.add(Constants.TQROOTBEAN); - importTypes.add(Constants.TYPEQUERYBEAN); - importTypes.add(Constants.DATABASE); - importTypes.add(Constants.FETCHGROUP); - importTypes.add(Constants.QUERY); - importTypes.add(Constants.TRANSACTION); if (implementsInterface != null) { implementsInterfaceFullName = implementsInterface.getQualifiedName().toString(); boolean nested = implementsInterface.getNestingKind().isNested(); implementsInterfaceShortName = Util.shortName(nested, implementsInterfaceFullName); } - if (dbName != null) { - importTypes.add(Constants.DB); - } addClassProperties(); } @@ -230,12 +219,6 @@ void writeAssocBean() throws IOException { * Prepare the imports for writing assoc bean. */ private void prepareAssocBeanImports() { - - importTypes.remove(Constants.DB); - importTypes.remove(Constants.TQROOTBEAN); - importTypes.remove(Constants.DATABASE); - importTypes.remove(Constants.FETCHGROUP); - importTypes.remove(Constants.QUERY); if (embeddable) { importTypes.add(Constants.TQASSOC); } else { @@ -266,7 +249,6 @@ private void prepareAssocBeanImports() { * Write constructors. */ private void writeConstructors() { - if (writingAssocBean) { writeAssocBeanFetch(); writeAssocBeanConstructor(); @@ -279,7 +261,7 @@ private void writeConstructors() { * Write the constructors for 'root' type query bean. */ private void writeRootBeanConstructor() { - lang().rootBeanConstructor(writer, shortName, dbName); + lang().rootBeanConstructor(writer, shortName, dbName, beanFullName); } private void writeAssocBeanFetch() { @@ -315,7 +297,6 @@ private void writeAssocBeanExpression(boolean nullable, String expression, Strin * Write constructor for 'assoc' type query bean. */ private void writeAssocBeanConstructor() { - lang().assocBeanConstructor(writer, shortName); } @@ -344,11 +325,10 @@ private void writeClass() { writer.append(Constants.AT_GENERATED).eol(); writer.append(Constants.AT_TYPEQUERYBEAN).eol(); if (embeddable) { - writer.append("class Q%s : TQAssoc<%s,R> {", shortName, shortInnerName).eol(); + writer.append("class Q%s : TQAssoc<%s,R> {", shortName, beanFullName).eol(); } else { - writer.append("class Q%s : TQAssocBean<%s,R,Q%s> {", shortName, shortInnerName, origShortName).eol(); + writer.append("class Q%s : TQAssocBean<%s,R,Q%s> {", shortName, beanFullName, origShortName).eol(); } - } else { writer.append("/**").eol(); writer.append(" * Query bean for %s.", shortName).eol(); @@ -357,7 +337,7 @@ private void writeClass() { writer.append(" */").eol(); writer.append(Constants.AT_GENERATED).eol(); writer.append(Constants.AT_TYPEQUERYBEAN).eol(); - lang().beginClass(writer, shortName); + writer.append("class Q%s : io.ebean.typequery.TQRootBean<%s, Q%s> {", shortName, beanFullName, shortName).eol(); } writer.eol(); @@ -365,7 +345,7 @@ private void writeClass() { private void writeAlias() { if (!writingAssocBean) { - lang().alias(writer, shortName); + lang().alias(writer, shortName, beanFullName); } } diff --git a/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java b/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java index 0cb6be1420..de9315afd8 100644 --- a/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java +++ b/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java @@ -70,7 +70,6 @@ private boolean isEntity() { } private void gatherPropertyDetails() { - importTypes.add(beanFullName); if (implementsInterface != null) { String implementsInterfaceFullName = implementsInterface.getQualifiedName().toString(); boolean nested = implementsInterface.getNestingKind().isNested(); @@ -146,7 +145,7 @@ private void writeConstructors() { writer.append(" * }").eol(); writer.append(" */").eol(); writer.append(" public static Q%s forFetchGroup() {", shortName).eol(); - writer.append(" return new Q%s(io.ebean.FetchGroup.queryFor(%s.class));", shortName, shortName).eol(); + writer.append(" return new Q%s(io.ebean.FetchGroup.queryFor(%s.class));", shortName, beanFullName).eol(); writer.append(" }").eol(); writer.eol(); @@ -154,9 +153,9 @@ private void writeConstructors() { writer.append(" /** Construct using the %s Database */", name).eol(); writer.append(" public Q%s() {", shortName).eol(); if (dbName == null) { - writer.append(" super(%s.class);", shortName).eol(); + writer.append(" super(%s.class);", beanFullName).eol(); } else { - writer.append(" super(%s.class, io.ebean.DB.byName(\"%s\"));", shortName, dbName).eol(); + writer.append(" super(%s.class, io.ebean.DB.byName(\"%s\"));", beanFullName, dbName).eol(); } writer.append(" }").eol(); writer.eol(); @@ -164,16 +163,16 @@ private void writeConstructors() { writer.append(" /** Construct with a given transaction */").eol(); writer.append(" public Q%s(io.ebean.Transaction transaction) {", shortName).eol(); if (dbName == null) { - writer.append(" super(%s.class, transaction);", shortName).eol(); + writer.append(" super(%s.class, transaction);", beanFullName).eol(); } else { - writer.append(" super(%s.class, io.ebean.DB.byName(\"%s\"), transaction);", shortName, dbName).eol(); + writer.append(" super(%s.class, io.ebean.DB.byName(\"%s\"), transaction);", beanFullName, dbName).eol(); } writer.append(" }").eol(); writer.eol(); writer.append(" /** Construct with a given Database */").eol(); writer.append(" public Q%s(io.ebean.Database database) {", shortName).eol(); - writer.append(" super(%s.class, database);", shortName).eol(); + writer.append(" super(%s.class, database);", beanFullName).eol(); writer.append(" }").eol(); writer.eol(); @@ -185,13 +184,13 @@ private void writeConstructors() { writer.eol(); writer.append(" /** Private constructor for FetchGroup building */").eol(); - writer.append(" private Q%s(io.ebean.Query<%s> fetchGroupQuery) {", shortName, shortName).eol(); + writer.append(" private Q%s(io.ebean.Query<%s> fetchGroupQuery) {", shortName, beanFullName).eol(); writer.append(" super(fetchGroupQuery);").eol(); writer.append(" }").eol(); writer.eol(); writer.append(" /** Private constructor for filterMany */").eol(); - writer.append(" private Q%s(io.ebean.ExpressionList<%s> filter) {", shortName, shortName).eol(); + writer.append(" private Q%s(io.ebean.ExpressionList<%s> filter) {", shortName, beanFullName).eol(); writer.append(" super(filter);").eol(); writer.append(" }").eol(); @@ -224,7 +223,7 @@ private void writeClass() { writer.append("public final class Q%s {", shortName).eol(); } else { writer.append(Constants.AT_TYPEQUERYBEAN).eol(); - writer.append("public final class Q%s extends io.ebean.typequery.TQRootBean<%1$s,Q%1$s> {", shortName).eol(); + writer.append("public final class Q%s extends io.ebean.typequery.TQRootBean<%s,Q%s> {", shortName, beanFullName, shortName).eol(); } writer.eol(); } @@ -263,9 +262,9 @@ private void writeAssocClass() { writer.append(" ").append(Constants.AT_GENERATED).eol(); writer.append(" ").append(Constants.AT_TYPEQUERYBEAN).eol(); if (embeddable) { - writer.append(" public static final class Assoc extends io.ebean.typequery.TQAssoc<%s,R> {", shortInnerName).eol(); + writer.append(" public static final class Assoc extends io.ebean.typequery.TQAssoc<%s,R> {", beanFullName).eol(); } else { - writer.append(" public static final class Assoc extends io.ebean.typequery.TQAssocBean<%s,R,Q%s> {", shortName, shortInnerName).eol(); + writer.append(" public static final class Assoc extends io.ebean.typequery.TQAssocBean<%s,R,Q%s> {", beanFullName, shortInnerName).eol(); } for (PropertyMeta property : properties) { writer.append(" "); diff --git a/tests/test-kotlin/pom.xml b/tests/test-kotlin/pom.xml index 2f1dc4d503..df3ea04eb5 100644 --- a/tests/test-kotlin/pom.xml +++ b/tests/test-kotlin/pom.xml @@ -15,9 +15,9 @@ 11 11 - 13.13.0 - 1.8.10 - 2.12.1 + 14.0.0 + 1.9.22 + 2.16.1 @@ -29,7 +29,7 @@ ch.qos.logback logback-classic - 1.3.12 + 1.5.0 javax.validation @@ -91,7 +91,8 @@ io.ebean kotlin-querybean-generator - 13.14.0 + + 14.0.0