<?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>Maven Torque Plugin</title>
 </properties>

 <body>
  <section name="Usage">
    <p>
      To use the Torque Maven 2 plugin in your project, you need to configure
      it in the pom.xml of your project. Here is an example:
    </p>

<source><![CDATA[
...
<build>
  <plugins>
     <plugin>
      <groupId>org.apache.db.torque</groupId>
      <artifactId>torque-maven-plugin</artifactId>
      <configuration>
        <targetDatabase>mysql</targetDatabase>
        <targetPackage>org.apache.torque.test</targetPackage>
        <driver>org.gjt.mm.mysql.Driver</driver>
        <url>jdbc:mysql://localhost:3306/bookstore</url>
        <user>root</user>
        <password></password>
      </configuration>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals>
            <goal>om</goal>
            <goal>documentation</goal>
          </goals>
        </execution>
      </executions>
      <dependencies>
        <dependency>
          <artifactId>mysql-connector-java</artifactId>
          <groupId>mysql</groupId>
          <version>3.1.12</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>
...
]]></source>

  </section>

  <section name="Generating code">

    <p>
      In the example configuration above, the goals <code>om</code> and 
      <code>documentation</code> are specified. Therefore, the
      om java classes and the html documentation of the table structure 
      will be generated in the "generate sources" phase. This phase will be
      executed e.g. when running <code>mvn compile</code> or 
      <code>mvn package</code>.
    </p>

    <p>
      The om classes are generated in two locations: 
      <ul>
        <li>
          The base classes (which should not be modified by the user)
          are generated by default in the directory 
          <code>target/generated-sources/torque</code>.
          They will be deleted if the command <code>mvn clean</code> is run.
        </li>
        <li>
          The non-base classes (which can be modified by the user) will be
          generated ba default in the directory
          <code>src/main/generated-java</code>.
          Once generated, they will not be overwritten and will also not be
          deleted if <code>mvn clean</code> is run.
        </li>
      </ul>
      Both paths will be added to the compile source path of maven 2,
      so the jave files in these directories will be compiled along with the
      other java source.
    </p>
    
    <p>
      The documentation is generated per default in the directory
      <code>target/generated-docs/torque</code>.
    </p>
    
  </section>
  
  <section name="Talking to the database">
  
    <p>
      To allow the Torque maven 2 plugin to communicate with the database,
      the correct database url, database user and password must be given in the
      Torque Maven 2 plugin's configuration. Also, the correct database driver
      must be added as a dependency of the plugin. See the example configuration
      above how this is done.
    </p>
    
    <p>
      For example, one can use the Torque Maven 2 plugin to create the tables
      corresponding to the om classes. Usually, one does not want to do this
      every time the project is compiled or built, so specifying these goals
      in the pom.xml makes no sense. Instead, one can execute the command
    </p>
<source>
mvn torque:sql torque:sqlExec
</source>

    <p>
      in the project's home directory to generate the sql for creating the
      database table and afterwards executing the sql.
    </p>

  </section>
  
 </body>
</document>
