【问题标题】:Jooq Maven and multiple schemasJooq Maven 和多个模式
【发布时间】:2014-12-28 01:17:04
【问题描述】:

我正在尝试使用 maven 为我的 postgres 数据库自动生成 pojo。虽然即使我把 maven 排除在外,我也有问题。

我的数据被拆分为多个模式,我需要在我的代码库中处理所有这些模式。我想知道如何在 Maven 中为他们每个人设置一项任务。这是我目前所拥有的。

显然,这似乎只适用于单一模式。我希望能够为多个 POJO 生成 POJO。我尝试了多个 xml 元素,或者用逗号分隔,但它只是出错了。

mvn -PDBGen generate-sources #is the command i use

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.foobar.sandbox</groupId>
    <artifactId>playBox</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <jooq-version>3.4.4</jooq-version>
        <psql-version>9.1-901-1.jdbc4</psql-version>
    </properties>

    <profiles>
        <profile>
            <id>DBGen</id>

            <build>
                <plugins>

                    <!-- Maven Auto Generation -->
                    <plugin>
                        <groupId>org.jooq</groupId>
                        <artifactId>jooq-codegen-maven</artifactId>
                        <version>${jooq-version}</version>

                        <!-- The plugin should hook into the generate goal -->
                        <executions>
                            <execution>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>

                        <!-- Manage the plugin's dependency. In this example, we'll use a PostgreSQL database -->
                        <dependencies>
                            <dependency>
                                <groupId>postgresql</groupId>
                                <artifactId>postgresql</artifactId>
                                <version>${psql-version}</version>
                            </dependency>
                        </dependencies>

                        <!-- Specify the plugin configuration.
                             The configuration format is the same as for the standalone code generator -->
                        <configuration>

                            <!-- JDBC connection parameters -->
                            <jdbc>
                                <driver>org.postgresql.Driver</driver>
                                <url>jdbc:postgresql://localhost:5433/mydb</url>
                                <user>user</user>
                                <password>s3cret</password>
                            </jdbc>

                            <!-- Generator parameters -->
                            <generator>
                                <name>org.jooq.util.DefaultGenerator</name>
                                <database>
                                    <name>org.jooq.util.postgres.PostgresDatabase</name>
                                    <includes>.*</includes>
                                    <inputSchema>ui</inputSchema>
                                    <excludes></excludes>
                                </database>
                                <target>
                                    <packageName>com.foobar.playbox.jooq.generated</packageName>
                                    <directory>target/generated-sources/jooq</directory>
                                </target>
                            </generator>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>


    <build>
        <plugins>
            <!-- compiler -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>target/generated-sources/jooq</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>


    <dependencies>
        <!-- postgres -->
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${psql-version}</version>
        </dependency>
        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.33</version>
        </dependency>
        <!-- DataBase -->
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>${jooq-version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>${jooq-version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>${jooq-version}</version>
        </dependency>
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <!-- Test -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

【问题讨论】:

    标签: java postgresql maven jooq


    【解决方案1】:

    秘诀就是替换这个:

    <inputSchema>ui</inputSchema>
    

    通过这个:

    <schemata>
      <schema>
        <inputSchema>ui</inputSchema>
      </schema>
      <schema>
        <inputSchema>other_schema</inputSchema>
      </schema>
    </schemata>
    

    您也可以完全删除所有&lt;inputSchema/&gt; 配置,然后jOOQ 代码生成器将为它发现的所有模式生成类(包括pg_cataloginformation_schema

    More details can be found in the jOOQ manual.

    【讨论】:

    • 这看起来很有希望。谢谢卢卡斯。我会在明天上班时确认这一点,如果它有效,我会给你信用。 :) 非常感谢。
    猜你喜欢
    • 2021-12-17
    • 2018-01-06
    • 2014-10-02
    • 2018-03-03
    • 1970-01-01
    • 2019-02-24
    • 2019-02-16
    • 2013-08-13
    • 1970-01-01
    相关资源
    最近更新 更多