<?xml version="1.0"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you 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.
-->

<document>
 <properties>
  <title>Generator Overview</title>
  <author email="fischer@seitenbau.de">Thomas Fischer</author>
 </properties>

 <body>
  <section name="Introduction">
    
    <p>
      The Torque generator consists of a collection of ant tasks. The core tasks
      generate java classes and sql scripts from an xml description of
      the database, but there are other tasks available. See the 
      <a href="schema-reference.html">Schema Reference</a> for the format of
      the xml file, and the
      <a href="tasks-reference.html">Tasks reference</a> for a complete list
      of available tasks. 
    </p>
    
    <p>
      The generator can be configured using a properties file, 
      <code>build.properties</code>. See the 
      <a href="properties-reference.html">Properties reference</a> for a 
      list of available properties and their purposes.
    </p>
  </section>
  
  <section name="Usage">
    <p>
      This section will give a short introduction of how to use the 
      Torque generator using ant. For using the generator with maven, see the
      <a href="../maven-plugin/index.html">Maven plugin docs</a>.
    </p>
    
    <p>
      The following is just a suggestion to get you started using the generator.
      Once you found out how it is working, feel free to change the suggestion
      to fit your specific needs.
    </p>
  
    <p>
      To use the generator, download the tar.gz or zip binary distribution
      of the Torque generator from the
      <a href="../../../download.html">Torque download page</a>. Unpack it in
      the root directory of your project. This will create a directory called
      <code>torque-gen-3.3</code> in the root directory of your project.
      You also need to have <a href="http://ant.apache.org">ant</a> 
      installed and available in your path.
    </p>
    
    <p>
      Change into the <code>torque-gen-3.3</code> directory and edit the file
      <code>build.properties</code>. Look through the properties and 
      modify them to fit your specific set-up.
      Afterwards, assuming you want to keep your schema
      files in the <code>src/schema</code> subdirectory of the project
      root directory, and generate your java
      classes in the <code>target/java</code> and the sql scripts in the 
      <code>target/sql</code> subdirectories of the project root directory, add
      the following properties:
<source>
torque.output.dir = ../target
torque.schema.dir = ../src/schema
</source>
    </p>
    
    <p>
      Now create the <code>src/schema</code> subdirectory of your project
      root directory. Create a schema.xml file describing your database in the
      newly create directory (for example you might use the 
      <code>bookstore-schema.xml</code> file from the 
      <a href="../tutorial/step2.html">Tutorial</a>) for a start. 
      Note that the names of the schema file(s) needs to end with 
      <code>schema.xml</code>.
    </p>
    
    <p>
      If you want to use the id broker (a Torque runtime service which creates
      primary keys in a database independent manner), also copy the file
      <code>torque-gen-3.3/src/schema/id-table-schema.xml</code> to the 
      <code>src/schema</code> subdirectory of your project root.
    </p>

    <p>
      Now change into the <code>torque-gen-3.3</code> directory, and type
      the command
    </p>
    
<source>
ant -f build-torque.xml
</source>

    <p>
      This will create the <code>target/java</code> subdirectory in your
      project root directory containing the generated java classes,
      and the <code>target/sql</code> directory containing the generated
      sql scripts.
    </p>

    <p>
      If you want to create your database using torque (this does not work for
      all databases), you first need to copy the database driver jar 
      into the <code>torque-gen-3.3/lib</code> directory.
      Then make sure that the database user you have configured in the 
      build.properties has sufficient rights to create a database.
      When everything is ready, type the command
    </p>
    
<source>
ant -f build-torque.xml create-db
</source>
    
    <p>
      To create the tables in your database, you also need the database driver 
      jar in the <code>torque-gen-3.3/lib</code> directory. Type the command
    </p>
    
<source>
ant -f build-torque.xml insert-sql
</source>
    
    <p>
      You can repeat the steps above if you have changed your 
      <code>schema.xml</code>. However, be aware that the insert-sql task drops
      all table and creates them anew, so all data in the tables is lost.
    </p>
    
    <p>
      Now you have finished the short course in using the generator.
      To learn about how to use your generated java classes, you can 
      either look at the <a href="../runtime/index.html">Torque Runtime Docs</a>
      or continue with the Tutorial at 
      <a href="../tutorial/step4.html">Step 4</a>, ignoring all
      maven-specific parts, especially the bits about a file called
      <code>project.xml</code>. (As you use ant, you need to set up your own 
      project build tasks.)
    </p>
  </section>
 </body>
</document>
