简体   繁体   English

如何重命名生成的表引用?

[英]How to rename generated table references?

I have two schemas in my database and both share tables with the same names.我的数据库中有两个模式,并且都共享同名表。 In order to not have naming conflicts in generated code, I want to prefix all names with the appropriate schema name.为了在生成的代码中不存在命名冲突,我想在所有名称前加上适当的模式名称作为前缀。

I made it work for class names by overriding getJavaClassName of DefaultGeneratorStrategy however I could not find a fitting override that is responsible for the table references in tables.references.Tables.kt .我通过覆盖DefaultGeneratorStrategygetJavaClassName使其适用于 class 名称,但是我找不到负责tables.references.Tables.kt中表引用的合适覆盖。

I managed to solve my problem by overriding getJavaIdentifier of DefaultGeneratorStrategy the following way:我设法通过以下方式覆盖DefaultGeneratorStrategygetJavaIdentifier来解决我的问题:

override fun getJavaIdentifier(definition: Definition): String {
    if (definition is PostgresTableDefinition) {
        return "${definition.schema.name.toUppercaseSnakeCase()}_${super.getJavaIdentifier(definition)}"
    }

    return super.getJavaIdentifier(definition)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM