jOOQ / jOOQ

jOOQ is the best way to write SQL in Java
https://www.jooq.org
Other
6.16k stars 1.21k forks source link

Bad code generated by KotlinGenerator when combining embeddable domains with interfaces #17176

Open lukaseder opened 2 months ago

lukaseder commented 2 months ago

This configuration:

<execution>
    <id>generate-embeddabledomainsinterfaces</id>
    <phase>generate-test-sources</phase>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        <generator>
            <database>
                <name>org.jooq.meta.extensions.ddl.DDLDatabase</name>
                <properties>
                    <property>
                        <key>scripts</key>
                        <value>${basedir}/src/main/resources/embeddabledomains.sql</value>
                    </property>
                </properties>
                <embeddableDomains>.*</embeddableDomains>
            </database>
            <generate>
                <interfaces>true</interfaces>
                <pojos>true</pojos>
                <records>true</records>
            </generate>
            <target>
                <packageName>org.jooq.codegen.test.embeddabledomainsinterfaces.db</packageName>
            </target>
        </generator>
    </configuration>
</execution>

Produces bad code generation output with the KotlinGenerator where the generated interface is this:

internal interface IEmbeddableDomains_2 : Serializable {
    var id: Int?
    var e: IDEmail
    var y: IDYear
    // ...
}

... and the implementation is this:

internal class EmbeddableDomains_2(
    override var id: Int? = null,
    override var e: DEmail? = null,
    override var y: DYear? = null
): IEmbeddableDomains_2 { ... }

There are 2 problems:

This would be a valid alternative, for example:

internal class EmbeddableDomains_2(
    override var id: Int? = null,
    override var e: IDEmail = DEmail(null),
    override var y: IDYear = DYear(null)
): IEmbeddableDomains_2 { ... }

To be further investigated. There are probably other, related issues (e.g. combining UDTs with interfaces)

lukaseder commented 2 months ago

This doesn't affect the ScalaGenerator as in Scala, we do not declare properties in interfaces. That feature is available in Kotlin only