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

Kotlin - Need to be able to specify override methods for DAO - seems to only support RECORD and POJO right now #16501

Open
mikebski opened this issue Mar 23, 2024 · 4 comments

Comments

@mikebski
Copy link

Use case

I want to define an interface for each DAO to implement, and have 2 issues:

  1. Cannot provide override methods for DAO, only for RECORD and POJO
  2. Vararg methods with Int type cannot be used with interfaces - See https://stackoverflow.com/questions/78209587/kotlin-interface-with-generic-inteface-method-with-vararg-generic-param-cannot and https://youtrack.jetbrains.com/issue/KT-9495/vararg-and-substitution-of-primitives-for-type-parameters

Possible solution

The first part of the if works fine, support for the second would solve this issue

override fun getJavaMemberOverride(definition: Definition?, mode: GeneratorStrategy.Mode?): Boolean {
        LOGGER.info("Member Override: Generator mode is $mode for ${definition?.qualifiedName}")
        if (mode == GeneratorStrategy.Mode.POJO && definition?.qualifiedName?.startsWith("itr.itr_ne_") == true) {
            if (NamedEntity.FIELD_NAMES.contains(definition.name)) {
                return true
            }
        }
        if (mode == GeneratorStrategy.Mode.DAO && definition?.qualifiedName?.startsWith("itr.itr_ne_") == true) {
            if (INamedEntityService.FIELD_NAMES.contains(definition.name)) {
                return true
            }
        }
        return super.getJavaMemberOverride(definition, mode)
    }

For the varargs but, consider using Collection<Int> or something so an interface method can be written that the generated method will properly implement.

Possible workarounds

Can't really think of a workaround

jOOQ Version

3.20.0-SNAPSHOT

Database product and version

Any

Java Version

Any

JDBC / R2DBC driver name and version (include name if unofficial driver)

Any

@lukaseder
Copy link
Member

Thanks for your feature request. Can you please provide a specific example of an interface with its methods, and how you'd like to have that implemented in your DAOs?

@mikebski
Copy link
Author

In the generated DAO there is a method:

fun fetchById(vararg values: Int)

My kotlin interface that I'm adding to the dao via the DefaultGeneratorStrategy override tries to define this method and so I need

override fun fetchById(vararg values: Int) in my dao- the problem is that my getJavaMemberOverride method in my generator strategy is not being called for DAOs so I can't add override to DAO methods...

@mikebski
Copy link
Author

In other words, the first if works fine but the second is never called because the generator does not let me do this for a DAO...

override fun getJavaMemberOverride(definition: Definition?, mode: GeneratorStrategy.Mode?): Boolean {
        LOGGER.info("Member Override: Generator mode is $mode for ${definition?.qualifiedName}")
        if (mode == GeneratorStrategy.Mode.POJO && definition?.qualifiedName?.startsWith("itr.itr_ne_") == true) {
            if (NamedEntity.FIELD_NAMES.contains(definition.name)) {
                return true
            }
        }
        if (mode == GeneratorStrategy.Mode.DAO && definition?.qualifiedName?.startsWith("itr.itr_ne_") == true) {
            if (INamedEntityService.FIELD_NAMES.contains(definition.name)) {
                return true
            }
        }
        return super.getJavaMemberOverride(definition, mode)
    }

@lukaseder
Copy link
Member

Sorry for the delay, thanks for the example. I can see what you mean now. I'll investigate this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants