<!--
 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>
        <artifactId>server</artifactId>
        <groupId>org.ehrbase.openehr</groupId>
        <version>0.11.0</version>
        <relativePath>../pom.xml</relativePath>
    </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</groupId>
            <artifactId>serialisation</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen-maven</artifactId>
        </dependency>



        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </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>
                <configuration>
                    <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>
                            <!-- Generation flags: See advanced configuration properties -->
                        </generate>
                        <target>
                            <!-- The destination package of your generated classes (within the destination
                                directory) jOOQ may append the schema name to this package if generating
                                multiple schemas, e.g. org.jooq.your.packagename.schema1 org.jooq.your.packagename.schema2 -->
                            <packageName>org.ehrbase.jooq.pg</packageName>
                            <!-- The destination directory of your generated classes -->
                            <!--<directory>./build/generated-src/main/</directory>-->
                            <directory>target/generated-sources/</directory>
                        </target>
                    </generator>
                </configuration>
            </plugin>


        </plugins>
    </build>


</project>
