Jooq Maven and multiple schemas

I am trying to use maven to automatically generate pojo for my postgres database. Although even if I take maven out of the equation, I still have a problem.

My data is split into multiple schemas and I will need to work with all of them in my codebase. I would like to know how I can accomplish this without running a task for each one in maven. This is what I have so far.

Obviously this only seems to work for one circuit. I would like to be able to generate POJOs for multiple. I tried multiple xml elements or comma but these are just errors.

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 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>

      

+3


source to share


1 answer


The secret is to replace this:

<inputSchema>ui</inputSchema>

      

Thus:



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

      

You can also completely remove all configuration <inputSchema/>

, then the jOOQ code generator will generate classes for all detected schemas (including pg_catalog

and information_schema

)

More details can be found in the jOOQ manual .

+8


source







All Articles