Jooq Maven和多个模式

时间:2014-10-31 16:36:54

标签: java postgresql maven jooq

我试图使用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>

1 个答案:

答案 0 :(得分:11)

秘诀就是取代它:

<inputSchema>ui</inputSchema>

由此:

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

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

More details can be found in the jOOQ manual