126 lines
5.4 KiB
XML
126 lines
5.4 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 hibernate. These
|
|
include targets to generate hibernate mappings from xdoclet attributes, as well as
|
|
export a database schema from the mappings.
|
|
|
|
This ant XML fragment is meant to be imported into a project build file, along with
|
|
common-targets.xml. 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="hibernate-targets" xmlns:ivy="antlib:fr.jayasoft.ivy.ant">
|
|
|
|
<import file="common-targets.xml" />
|
|
|
|
<!-- hooks: these are not optional! -->
|
|
|
|
<!-- you must hook build.prepare -->
|
|
<target name="build.prepare" depends="common-targets.build.prepare">
|
|
<!-- Make sure hibernatedoclet is necessary -->
|
|
<uptodate property="hibernatedoclet.unnecessary">
|
|
<srcfiles dir="${src.java.main.dir}" includes="**/*.java" />
|
|
<srcfiles dir="${target.gen.java.dir}" includes="**/*.java" />
|
|
<mapper type="glob" from="*.java" to="${target.classes.dir}/*.class" />
|
|
</uptodate>
|
|
|
|
<propertyfile file="${target.filter.file}">
|
|
<entry key="HIBERNATE_DIALECT" value="${hibernate.dialect}" />
|
|
<entry key="HIBERNATE_SHOW_SQL" value="${hibernate.show.sql}" />
|
|
</propertyfile>
|
|
|
|
<path id="xdoclet.classpath">
|
|
<path refid="test.classpath" />
|
|
</path>
|
|
|
|
<path id="hibernate.classpath">
|
|
<path refid="test.classpath" />
|
|
<path location="${target.classes.dir}" />
|
|
<pathelement location="${target.testclasses.dir}" />
|
|
</path>
|
|
</target>
|
|
|
|
<!-- you must hook statics! -->
|
|
<target name="statics" depends="common-targets.statics">
|
|
<antcall target="hibernatedoclet" />
|
|
</target>
|
|
|
|
<!-- end of hooks -->
|
|
|
|
<!-- hibernatedoclet: generates Hibernate mapping files based on XDoclet marked-up Plain Old Java Object (POJO) -->
|
|
<target name="hibernatedoclet" depends="hibernate.task.init" if="use.hibernatedoclet" unless="hibernatedoclet.unnecessary" description="Generate Persistence and form classes">
|
|
|
|
<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask" classpathref="xdoclet.classpath" />
|
|
|
|
<!-- generate hibernate files -->
|
|
<hibernatedoclet destdir="${target.gen.java.dir}" mergedir="${src.etc.dir}/merge" excludedtags="@version,@author" addedtags="@xdoclet-generated at ${TODAY}" force="${xdoclet.force}">
|
|
<fileset dir="${src.java.main.dir}" />
|
|
<hibernate validatexml="true" version="3.0" />
|
|
</hibernatedoclet>
|
|
</target>
|
|
|
|
<target name="hibernate.task.init" depends="retrieve">
|
|
<taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
|
|
<classpath>
|
|
<path refid="xdoclet.classpath" />
|
|
<path refid="hibernate.classpath" />
|
|
</classpath>
|
|
</taskdef>
|
|
</target>
|
|
|
|
<!-- db-init: generates the database schema and creates tables based on the mapping files -->
|
|
<target name="hibernate-schema-create" depends="hibernate.task.init, statics" description="Creates database tables from hibernate mapping files">
|
|
<mkdir dir="${target.dir}/db" />
|
|
<antcall target="generate.hibernate.properties" />
|
|
<schemaexport quiet="no" text="no" drop="no" delimiter=";" properties="${target.dir}/db/database.properties" output="${target.dir}/db/hib-schema.sql">
|
|
<fileset dir="${target.classes.dir}" includes="**/*.hbm.xml" />
|
|
</schemaexport>
|
|
</target>
|
|
|
|
<!-- db-init: drops the database tables -->
|
|
<target name="hibernate-schema-drop" depends="hibernate.task.init, statics" description="Drop database tables created by Hibernate's schema export">
|
|
<mkdir dir="${target.dir}/db" />
|
|
<antcall target="generate.hibernate.properties" />
|
|
<schemaexport quiet="no" text="no" drop="yes" delimiter=";" properties="${target.dir}/db/database.properties" output="${target.dir}/db/hib-drop-tables.sql">
|
|
<fileset dir="${target.classes.dir}" includes="**/*.hbm.xml" />
|
|
</schemaexport>
|
|
</target>
|
|
|
|
<!-- this task is called by tasks that need it in build.xml -->
|
|
<target name="generate.hibernate.properties">
|
|
<echo>generating database.properties from build.properties</echo>
|
|
<propertyfile comment="Hibernate Configuration for targets from db-targets.xml" file="${target.dir}/db/database.properties">
|
|
<entry key="hibernate.connection.driver_class" value="${database.driver}" />
|
|
<entry key="hibernate.connection.url" value="${database.url}" />
|
|
<entry key="hibernate.connection.username" value="${database.username}" />
|
|
<entry key="hibernate.connection.password" value="${database.password}" />
|
|
<entry key="hibernate.dialect" value="${hibernate.dialect}" />
|
|
<entry key="hibernate.connection.show_sql" value="${hibernate.show.sql}" />
|
|
</propertyfile>
|
|
<property file="database.properties" />
|
|
</target>
|
|
|
|
</project> |