139 lines
5.9 KiB
XML
139 lines
5.9 KiB
XML
<?xml version="1.0"?>
|
|
|
|
<!--
|
|
Copyright 2004-2007 the original author or authors.
|
|
|
|
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.
|
|
|
|
- - -
|
|
|
|
Author: Colin Sampaleanu
|
|
Author: Keith Donald
|
|
|
|
Ant XML fragment that contains useful targets for working with databases. These
|
|
include targets to load the project db schema and test data, as well as export a
|
|
dbunit dtd to facilitate validating xml test data documents.
|
|
|
|
This fragment is meant to be imported into a project build file, along with
|
|
common-targets.xml, in order to provide build handling for basic db-properties and
|
|
operations. This is an optional module, and due to the way the ant import works,
|
|
there is no way to automatically hook this up into the build. The importing project
|
|
must override appropropriate 'hook' targets from common-targets.xml, and then have
|
|
the override targets depend on both the targets from common-targets and those from here.
|
|
-->
|
|
<project name="db-targets" xmlns:ivy="antlib:fr.jayasoft.ivy.ant">
|
|
|
|
<import file="common-targets.xml" />
|
|
|
|
<!-- db.task.init: not to be called directly, but needed by other targets -->
|
|
<target name="db.task.init" depends="dbunit.presetdef.schema,
|
|
dbunit.presetdef.noschema,
|
|
retrieve">
|
|
<property name="src.db.dir" value="${src.etc.dir}/db"/>
|
|
<property name="target.db.dir" value="${target.dir}/db"/>
|
|
<presetdef name="my.sql">
|
|
<sql driver="${database.driver}" url="${database.url}" userid="${database.username}" password="${database.password}" classpathref="test.classpath" />
|
|
</presetdef>
|
|
<presetdef name="my.sqladmin">
|
|
<sql driver="${database.driver}" url="${database.url}" userid="${database.admin.username}" password="${database.admin.password}" classpathref="test.classpath" />
|
|
</presetdef>
|
|
</target>
|
|
|
|
<target name="dbunit.presetdef.schema" if="database.schema">
|
|
<taskdef name="dbunit" classname="org.dbunit.ant.DbUnitTask" classpathref="test.classpath" />
|
|
<presetdef name="my.dbunit">
|
|
<dbunit driver="${database.driver}" url="${database.url}" schema="${database.schema}"
|
|
userid="${database.username}" password="${database.password}">
|
|
<classpath>
|
|
<path refid="test.classpath" />
|
|
<pathelement location="${src.test.resources.dir}" />
|
|
</classpath>
|
|
</dbunit>
|
|
</presetdef>
|
|
</target>
|
|
<target name="dbunit.presetdef.noschema" unless="database.schema">
|
|
<taskdef name="dbunit" classname="org.dbunit.ant.DbUnitTask" classpathref="test.classpath" />
|
|
<presetdef name="my.dbunit">
|
|
<dbunit driver="${database.driver}" url="${database.url}"
|
|
userid="${database.username}" password="${database.password}">
|
|
<classpath>
|
|
<path refid="test.classpath" />
|
|
<pathelement location="${src.test.resources.dir}" />
|
|
</classpath>
|
|
</dbunit>
|
|
</presetdef>
|
|
</target>
|
|
|
|
<target name="db-schema-create" depends="db.task.init" description="Load the project schema (tables) into the database">
|
|
<property name="sql.src" value="${src.db.dir}/schema.sql" />
|
|
<antcall target="db-sql">
|
|
<param name="onerror" value="continue" />
|
|
<param name="autocommit" value="true" />
|
|
</antcall>
|
|
</target>
|
|
|
|
<target name="db-user-create" depends="db.task.init" description="Create the project schema tablespaces and user">
|
|
<property name="sql.src" value="${target.testclasses.dir}/create-user.sql" />
|
|
<antcall target="db-sql-admin">
|
|
<param name="onerror" value="continue" />
|
|
<param name="autocommit" value="true" />
|
|
</antcall>
|
|
</target>
|
|
|
|
<target name="db-schema-dtd" depends="db.task.init" description="Export db unit dtd for testdata file">
|
|
<mkdir dir="${target.db.dir}" />
|
|
<my.dbunit>
|
|
<export dest="${target.db.dir}/schema.dtd" format="dtd" />
|
|
</my.dbunit>
|
|
</target>
|
|
|
|
<target name="db-data-load" depends="db.task.init" description="Load all data contained in a file to the database">
|
|
<property name="db.data.file" value="${src.db.dir}/data.xml" />
|
|
<my.dbunit>
|
|
<operation type="CLEAN_INSERT" src="${db.data.file}" />
|
|
</my.dbunit>
|
|
</target>
|
|
|
|
<target name="db-sql" depends="guard.sqlsrc, db.task.init" description="Execute sql statements stored in the file defined by the ${sql.src} property">
|
|
<property name="onerror" value="stop" />
|
|
<property name="autocommit" value="false" />
|
|
<echo>User sql.src = '${sql.src}'</echo>
|
|
<my.sql src="${sql.src}" onerror="${onerror}" autocommit="${autocommit}">
|
|
<classpath>
|
|
<path refid="test.classpath" />
|
|
<pathelement location="${src.test.resources.dir}" />
|
|
</classpath>
|
|
</my.sql>
|
|
</target>
|
|
|
|
<target name="db-sql-admin" depends="guard.sqlsrc, guard.admin, db.task.init" description="Execute sql statements stored in the file defined by the ${sql.src} property">
|
|
<property name="onerror" value="stop" />
|
|
<property name="autocommit" value="false" />
|
|
<echo>Admin sql.src = '${sql.src}'</echo>
|
|
<my.sqladmin src="${sql.src}" onerror="${onerror}" autocommit="${autocommit}">
|
|
<classpath>
|
|
<path refid="test.classpath" />
|
|
<pathelement location="${src.test.resources.dir}" />
|
|
</classpath>
|
|
</my.sqladmin>
|
|
</target>
|
|
|
|
<target name="guard.sqlsrc" unless="sql.src">
|
|
<fail message="The target you are attempting to run requires the ${sql.src} property to be set, but it doesn't appear to be" />
|
|
</target>
|
|
|
|
<target name="guard.admin" unless="database.admin.username">
|
|
<fail message="The target you are attempting to run requires the ${database.admin.username} property to be set, but it doesn't appear to be. Since this is a local admin property, define it in a local (secured) build.properties file" />
|
|
</target>
|
|
|
|
</project> |