<?xml version="1.0"?>
<!--

    Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Public License v. 2.0, which is available at
    http://www.eclipse.org/legal/epl-2.0.

    This Source Code may also be made available under the following Secondary
    Licenses when the conditions for such availability set forth in the
    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
    version 2 with the GNU Classpath Exception, which is available at
    https://www.gnu.org/software/classpath/license.html.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<project name="JSTL Database Initialization" basedir="." default="init.javadb">

    <property file="${ts.home}/bin/ts.jte"/>
    <property name="jdbc.classpath" value="${jdbc.classes}"/>
    <property name="sql.base.dir" value="${ts.home}/sql"/>   
    
    <target name="init.derby">
        <antcall target="configure.backend">
            <param name="db.delimiter" value=";"/>
            <param name="db.name" value="derby"/>
        </antcall>    
        <copy file="${sql.base.dir}/derby/derby.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>

    <!--
       Added to support the Sun version of Derby 
    -->
    <target name="init.javadb" >
      <antcall target="init.derby"/>
    </target>


    <target name="init.db2">
        <antcall target="configure.backend">
            <param name="db.delimiter" value="!"/>
            <param name="db.name" value="db2"/>
        </antcall>
        <copy file="${sql.base.dir}/db2/db2.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>

    <target name="init.mssqlserver">
        <antcall target="configure.backend">
            <param name="db.delimiter" value="!"/>
            <param name="db.name" value="mssqlserver"/>
        </antcall>
        <copy file="${sql.base.dir}/mssqlserver/mssqlserver.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>

    <target name="init.mysql">
        <antcall target="configure.backend">
            <param name="db.delimiter" value="!"/>
            <param name="db.name" value="mysql"/>
        </antcall>
        <copy file="${sql.base.dir}/mysql/mysql.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>

    <target name="init.oracle">
        <antcall target="configure.backend">
            <param name="db.delimiter" value="!"/>
            <param name="db.name" value="oracle"/>
        </antcall>
        <copy file="${sql.base.dir}/oracle/oracle.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>

    <target name="init.postgresql" >
        <antcall target="configure.backend" >
            <param name="db.delimiter" value=";"/>
            <param name="db.name" value="postgresql" />
        </antcall>
        <copy file="${sql.base.dir}/postgres/postgres.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>

    <target name="init.pointbase">
        <antcall target="configure.backend">
            <param name="db.delimiter" value=";"/>
            <param name="db.name" value="pointbase"/>
        </antcall>
        <copy file="${sql.base.dir}/pointbase/pointbase.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>

    <target name="init.sybase">
        <antcall target="configure.backend">
            <param name="db.delimiter" value="!"/>
            <param name="db.name" value="sybase"/>
        </antcall>
        <copy file="${sql.base.dir}/sybase/sybase.dml.jstl.sql"
              tofile="${bin.dir}/tssql.stmt"
	      overwrite="true"/>
    </target>
    
    <target name="configure.backend">
        <sql driver="${jstl.db.driver}"
             url="${jstl.db.url}"
             userid="${jstl.db.user}"
             password="${jstl.db.password}"
             classpath="${jdbc.classpath}"
             delimiter="${db.delimiter}"
             autocommit="true"
             onerror="continue">            
            <transaction
                src="${ts.home}/sql/${db.name}/${db.name}.ddl.jstl.sql"/>            
        </sql>
    </target>       

</project>
