Hyperjaxb3 命名策略在 0.5.6 和 0.6.2 之间发生变化

Hyperjaxb3 naming strategy change between 0.5.6 and 0.6.2

我们有一个重要的代码库,它利用 Hyperjaxb3 来注释 Java 类,这些代码是使用 xjc(以及其他 xjc 插件,包括自己开发的插件)生成的。

我们正在尝试从 Hyperjaxb3 0.5.6 升级到 0.6.2,但是 运行 由于这些版本之间的命名策略发生了明显的变化,因此遇到了一个重大问题。

具体来说,像 "OneTwo" 这样的复杂类型名称在 0.5.6 中导致 table 名称 "ONETWO",而在 0.6.2 中 table 名称是 "ONE_TWO"。列名相同。

我们非常倾向于不重构数百个查询来适应这样的命名更改(尽管更新、更传统的 SQL 命名当然有意义——我们希望它是默认行为六年前开始的项目)。

有没有简单的方法可以切换到旧的命名策略?如果做不到这一点,您能否提供有关如何使用自定义命名策略扩展 Hyperjaxb3 的详细信息?

已查看 this test or this one, it is not clear to us exactly what we need to do to our pom to specify a different naming strategy class, and the Extension Guide 当前为空。

  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <configuration>
      <extension>true</extension>
      <plugins>
        <plugin>
          <groupId>org.jvnet.jaxb2_commons</groupId>
          <artifactId>jaxb2-basics</artifactId>
          <version>${jaxb.commons.version}</version>
        </plugin>
        <plugin>
          <groupId>org.jvnet.hyperjaxb3</groupId>
          <artifactId>hyperjaxb3-ejb-plugin</artifactId>
          <version>${hyperjaxb3.version}</version>
        </plugin>
        <plugin>
          <groupId>${project.groupId}</groupId>
          <artifactId>jaxb-x12</artifactId>
          <version>${project.version}</version>
        </plugin>
      </plugins>
      <args>
        <arg>-enableIntrospection</arg>
        <arg>-Xcopyable</arg>
        <arg>-Xequals</arg>
        <arg>-XhashCode</arg>
        <arg>-Xinheritance</arg>
        <arg>-Xhyperjaxb3-ejb</arg>
        <arg>-Xx12</arg>
      </args>
    </configuration>
  </plugin>

这里是 HJ3 的作者。

看看 custom-naming 测试项目。它实现并配置自定义命名策略。

解决方案由两部分组成:implementation of the naming strategy and configuration of this implementation

您的命名实现必须实现 org.jvnet.hyperjaxb3.ejb.strategy.naming.Naming 接口。最简单的方法是从 org.jvnet.hyperjaxb3.ejb.strategy.naming.impl.DefaultNaming.

继承

要配置,您必须创建一个资源 /org/jvnet/hyperjaxb3/ejb/plugin/custom/applicationContext.xml,它基本上是一个 Spring XML 配置。在那里,定义一个名为 naming:

的 bean
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean name="naming" class="com.acme.foo.MyNaming">
        <property name="reservedNames" ref="reservedNames"/>
    </bean>

</beans>

这将覆盖标准命名策略。