JOOQ:将列标记为“已弃用”?

huangapple go评论57阅读模式
英文:

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 &#39;@deprecated&#39;;

它不会生成注释,但会生成等效的 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.

&lt;configuration xmlns=&quot;http://www.jooq.org/xsd/jooq-codegen-3.16.0.xsd&quot;&gt;
  &lt;generator&gt;
    &lt;database&gt;
      &lt;comments&gt;
        &lt;comment&gt;
        
          &lt;!-- Regular expression matching all objects that have this comment. --&gt;
          &lt;expression&gt;CONFIGURED_COMMENT_TABLE&lt;/expression&gt;
          
          &lt;!-- Whether the comment is a deprecation notice. --&gt;
          &lt;deprecated&gt;true&lt;/deprecated&gt;
          
          &lt;!-- Whether the original schema comment should be included. --&gt;
          &lt;includeSchemaComment&gt;false&lt;/includeSchemaComment&gt;
          
          &lt;!-- The actual comment text. Defaults to no message. --&gt;
          &lt;message&gt;Do not use this table.&lt;/message&gt;
        &lt;/comment&gt;
      &lt;/comments&gt;
    &lt;/database&gt;
  &lt;/generator&gt;
&lt;/configuration&gt;

Hack using SQL comments

Use this hack (if your RDBMS supports comments):

<!-- language: lang-sql -->

COMMENT ON COLUMN my_table.my_column IS &#39;@deprecated&#39;;

It won't produce the annotation, but it will produce equivalent Javadoc, which has the same effect in IDEs.

huangapple
  • 本文由 发表于 2020年1月4日 12:52:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/59587999.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定