<?xml version="1.0" encoding="UTF-8"?>
<project name="Execute SQL Statement for Test">

  <property file="/etc/unitedfront2/localConfiguration.properties"/>
  <property name="localRepository" value="${user.home}/.m2/repository"/>
  <property name="dataSource.driver" value="${dataSource.driver}"/>
  <property name="dataSource.driver.version" value="5.1.6"/>
  <property name="dataSource.driver.classpath" value="${localRepository}/mysql/mysql-connector-java/${dataSource.driver.version}/mysql-connector-java-${dataSource.driver.version}.jar"/>
  <property name="dataSource.username" value="{dataSource.username}"/>
  <property name="dataSource.password" value="{dataSource.password}"/>
  <property name="dataSource.url.base" value="jdbc:mysql://localhost:3306"/>
  <property name="dataSource.url.uf2" value="${dataSource.url.base}/UnitedFront2?useUnicode=true&amp;characterEncoding=utf8"/>
  <property name="dataSource.url.uf2test" value="${dataSource.url.base}/UnitedFront2Test?useUnicode=true&amp;characterEncoding=utf8"/>

  <target name="create-db">
    <sql driver="${dataSource.driver}" classpath="${dataSource.driver.classpath}" url="${dataSource.url.base}"
        userid="${dataSource.username}" password="${dataSource.password}">
      CREATE DATABASE UnitedFront2;
    </sql>
  </target>

  <target name="drop-db">
    <sql driver="${dataSource.driver}" classpath="${dataSource.driver.classpath}" url="${dataSource.url.base}"
        userid="${dataSource.username}" password="${dataSource.password}" onerror="continue">
      DROP DATABASE UnitedFront2;
    </sql>
  </target>

  <target name="create-table">
    <sql driver="${dataSource.driver}" classpath="${dataSource.driver.classpath}" url="${dataSource.url.uf2}"
        userid="${dataSource.username}" password="${dataSource.password}"
        src="src/main/sql/unitedfront2-ddl.sql" encoding="UTF-8" autocommit="true"/>
  </target>

  <target name="restore-db">
    <antcall target="drop-db"/>
    <antcall target="create-db"/>
    <antcall target="create-table"/>
  </target>

  <target name="create-test-db">
    <sql driver="${dataSource.driver}" classpath="${dataSource.driver.classpath}" url="${dataSource.url.base}"
        userid="${dataSource.username}" password="${dataSource.password}">
      CREATE DATABASE UnitedFront2Test;
    </sql>
  </target>

  <target name="drop-test-db">
    <sql driver="${dataSource.driver}" classpath="${dataSource.driver.classpath}" url="${dataSource.url.base}"
        userid="${dataSource.username}" password="${dataSource.password}" onerror="continue">
      DROP DATABASE UnitedFront2Test;
    </sql>
  </target>

  <target name="create-test-table">
    <sql driver="${dataSource.driver}" classpath="${dataSource.driver.classpath}" url="${dataSource.url.uf2test}"
        userid="${dataSource.username}" password="${dataSource.password}"
        src="src/main/sql/unitedfront2-ddl.sql" encoding="UTF-8" autocommit="true"/>
    <sql driver="${dataSource.driver}" classpath="${dataSource.driver.classpath}" url="${dataSource.url.uf2test}"
        userid="${dataSource.username}" password="${dataSource.password}"
        src="src/test/sql/unitedfront2-test-ddl.sql" encoding="UTF-8" autocommit="true"/>
  </target>

  <target name="restore-test-db">
    <antcall target="drop-test-db"/>
    <antcall target="create-test-db"/>
    <antcall target="create-test-table"/>
  </target>

</project>