英文:
JOOQ: mark column as "deprecated"?
问题
我想在我的模式中某种方式标记一列为“已弃用”(可能是在列注释中添加某种标签之类的方式),然后让这个信息通过代码生成过程传播,以在生成的代码中为该列的字段/方法添加@Deprecated
注解。
JOOL是否具有与此相关的功能?
浏览用户手册似乎没有显示任何相关内容。
英文:
I'd like to somehow mark a column in my schema as "deprecated" (probably as some kind of tag in the column comment or something), and then have that info bubble up through the code generation process to result in an @Deprecated
annotation being added to the fields/methods for that column in the generated code.
Does JOOQ have any functionality related to that?
Browsing through the user manual doesn't seem to show anything relevant.
答案1
得分: 1
使用 jOOQ 3.15 的合成注释功能
从 jOOQ 3.15 开始,您可以使用代码生成器中的合成注释功能,例如:
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.16.0.xsd">
<generator>
<database>
<comments>
<comment>
<!-- 匹配具有此注释的所有对象的正则表达式。 -->
<expression>CONFIGURED_COMMENT_TABLE</expression>
<!-- 是否为废弃通知的注释。 -->
<deprecated>true</deprecated>
<!-- 是否应包含原始模式注释。 -->
<includeSchemaComment>false</includeSchemaComment>
<!-- 实际注释文本。默认情况下不包含消息。 -->
<message>不要使用此表格。</message>
</comment>
</comments>
</database>
</generator>
</configuration>
使用 SQL 注释的 Hack
使用此 Hack(如果您的关系数据库管理系统支持注释):
<!-- language: lang-sql -->
COMMENT ON COLUMN my_table.my_column IS '@deprecated';
它不会生成注释,但会生成等效的 Javadoc,在集成开发环境中具有相同的效果。
英文:
Using the jOOQ 3.15 synthetic comments feature
Starting from jOOQ 3.15, you can use the synthetic comments feature from the code generator, e.g.
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.16.0.xsd">
<generator>
<database>
<comments>
<comment>
<!-- Regular expression matching all objects that have this comment. -->
<expression>CONFIGURED_COMMENT_TABLE</expression>
<!-- Whether the comment is a deprecation notice. -->
<deprecated>true</deprecated>
<!-- Whether the original schema comment should be included. -->
<includeSchemaComment>false</includeSchemaComment>
<!-- The actual comment text. Defaults to no message. -->
<message>Do not use this table.</message>
</comment>
</comments>
</database>
</generator>
</configuration>
Hack using SQL comments
Use this hack (if your RDBMS supports comments):
<!-- language: lang-sql -->
COMMENT ON COLUMN my_table.my_column IS '@deprecated';
It won't produce the annotation, but it will produce equivalent Javadoc, which has the same effect in IDEs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论