<?xml version="1.0" encoding="UTF-8"?>

<!--
    Copyright (C) 2019 Vitasystems GmbH and Hannover Medical School.

    This file is part of Project EHRbase

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied. See the License for the
    specific language governing permissions and limitations
    under the License.
-->

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

    <parent>
        <groupId>org.ehrbase.openehr</groupId>
        <artifactId>server</artifactId>
        <version>0.21.0</version>
    </parent>

    <artifactId>jooq-pg</artifactId>

    <name>jooq-pq</name>

    <dependencies>
        <!-- Generation of the DB  -->
        <dependency>
            <groupId>org.ehrbase.openehr</groupId>
            <artifactId>base</artifactId>
        </dependency>
        <dependency>
            <groupId>org.ehrbase.openehr.sdk</groupId>
            <artifactId>serialisation</artifactId>
        </dependency>
        <dependency>
            <groupId>com.nedap.healthcare.archie</groupId>
            <artifactId>openehr-rm</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <configuration>
                    <locations>
                        <location>classpath:db/migration</location>
                    </locations>
                    <url>jdbc:postgresql://${database.host}:${database.port}/${database.name}</url>
                    <driver>org.postgresql.Driver</driver>
                    <user>${database.user}</user>
                    <password>${database.pass}</password>
                    <defaultSchema>ehr</defaultSchema>
                    <schemas>
                        <schema>ehr</schema>
                    </schemas>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <!-- The plugin should hook into the generate goal -->
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <!-- Manage the plugin's dependency. In this example, we'll use a PostgreSQL database -->
                <dependencies>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgressql.version}</version>
                    </dependency>
                </dependencies>
                <!-- Specify the plugin configuration.
                     The configuration format is the same as for the standalone code generator -->
                <configuration>
                    <!-- Configure the database connection here -->
                    <jdbc>
                        <driver>org.postgresql.Driver</driver>
                        <url>jdbc:postgresql://${database.host}:${database.port}/${database.name}</url>
                        <user>${database.user}</user>
                        <password>${database.pass}</password>
                    </jdbc>
                    <generator>
                        <database>
                            <!-- The database dialect fromBinder jooq-meta. Available dialects are named
                                org.responsedata.[database].[database]Database. Known values are: org.jooq.responsedata.ase.ASEDatabase
                                (to be used with Sybase ASE) org.jooq.responsedata.cubrid.CUBRIDDatabase org.jooq.responsedata.db2.DB2Database
                                org.jooq.responsedata.derby.DerbyDatabase org.jooq.responsedata.h2.H2Database org.jooq.responsedata.hsqldb.HSQLDBDatabase
                                org.jooq.responsedata.ingres.IngresDatabase org.jooq.responsedata.mysql.MySQLDatabase org.jooq.responsedata.oracle.OracleDatabase
                                org.jooq.responsedata.postgres.PostgresDatabase org.jooq.responsedata.sqlite.SQLiteDatabase
                                org.jooq.responsedata.sqlserver.SQLServerDatabase org.jooq.responsedata.sybase.SybaseDatabase
                                (to be used with Sybase SQL Anywhere) You can also provide your own org.jooq.responsedata.Database
                                implementation here, if your database is currently not supported or if you
                                wish to read the database schema fromBinder a file, such as a Hibernate .hbm.xml
                                file -->
                            <name>org.jooq.meta.postgres.PostgresDatabase</name>
                            <!-- All elements that are generated fromBinder your schema (A Java regular
                                expression. Use the pipe to separate several expressions) Watch out for case-sensitivity.
                                Depending on your database, this might be important! You can storeComposition case-insensitive
                                regular expressions using this syntax: (?i:expr) -->
                            <includes></includes>
                            <!-- All elements that are excluded fromBinder your schema (A Java regular expression.
                                Use the pipe to separate several expressions). Excludes match before includes -->
                            <excludes></excludes>
                            <!-- The schema that is used locally as a source for meta information.
                                This could be your development schema or the production schema, etc This
                                cannot be combined with the schemata element. If left empty, jOOQ will generate
                                all available schemata. See the manual's next section to learn how to generate
                                several schemata -->
                            <inputSchema>ehr</inputSchema>
                            <forcedTypes>
                                <forcedType>
                                    <!-- Specify the Java type of your custom type. This corresponds to the Binding's <U> type. -->
                                    <userType>com.nedap.archie.rm.datastructures.ItemStructure</userType>

                                    <!-- Associate that custom type with your binding. -->
                                    <binding>org.ehrbase.jooq.binding.OtherDetailsJsonbBinder</binding>

                                    <!-- Add a Java regular expression matching fully-qualified columns. Use the pipe to separate several expressions.

                                         If provided, both "includeExpressions" and "includeTypes" must match. -->
                                    <includeExpression>^(other_)?details$</includeExpression>

                                    <!-- Add a Java regular expression matching data types to be forced to
                                         have this type.

                                         Data types may be reported by your database as:
                                         - NUMBER              regexp suggestion: NUMBER
                                         - NUMBER(5)           regexp suggestion: NUMBER\(5\)
                                         - NUMBER(5, 2)        regexp suggestion: NUMBER\(5,\s*2\)
                                         - any other form

                                         It is thus recommended to use defensive regexes for types.

                                         If provided, both "includeExpressions" and "includeTypes" must match. -->
                                    <includeTypes>.*</includeTypes>
                                </forcedType>
                                <forcedType>
                                    <!-- Specify the Java type of your custom type. This corresponds to the Binding's <U> type. -->
                                    <userType>java.util.AbstractMap.SimpleEntry&lt;java.time.OffsetDateTime, java.time.OffsetDateTime></userType>
                                    <!--<userType>java.util.AbstractMap.SimpleEntry</userType>-->

                                    <!-- Associate that custom type with your binding. -->
                                    <binding>org.ehrbase.jooq.binding.SysPeriodBinder</binding>

                                    <!-- Add a Java regular expression matching fully-qualified columns. Use the pipe to separate several expressions.

                                         If provided, both "includeExpressions" and "includeTypes" must match. -->
                                    <includeExpression>sys_period</includeExpression>

                                    <!-- Add a Java regular expression matching data types to be forced to
                                         have this type.

                                         Data types may be reported by your database as:
                                         - NUMBER              regexp suggestion: NUMBER
                                         - NUMBER(5)           regexp suggestion: NUMBER\(5\)
                                         - NUMBER(5, 2)        regexp suggestion: NUMBER\(5,\s*2\)
                                         - any other form

                                         It is thus recommended to use defensive regexes for types.

                                         If provided, both "includeExpressions" and "includeTypes" must match. -->
                                    <includeTypes>.*</includeTypes>
                                </forcedType>

                            </forcedTypes>
                        </database>
                        <generate>
                            <javaTimeTypes>false</javaTimeTypes>
                        </generate>
                        <target>
                            <packageName>org.ehrbase.jooq.pg</packageName>
                            <directory>target/generated-sources/</directory>
                        </target>
                    </generator>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
