About this Example

この例について

This example shows an example configuration for using Torque from it's jar and not having it extracted into the source tree. It also illustrates how to tie in to Maven's callback functionality.

この例は、TorqueのJARや、Torqueをソースツリーへ格納せずにTorqueを使用するための設定例です。 また、Mavenのコールバックの仕組みにどのように接続するかを説明します。

Due note that currently this is setup to run Torque on every build. This will get very slow, but in the short future, the build-torque.xml will be updated to check that the XML schema has changed from the last time the SQL/om code was generated so as to save reduplicating the work and greatly improving build time.

現在、このセットアップはTorqueをビルドする度に実行されることに注意してください。 これは非常に遅いですが、近い将来、前回のSQL/omコード生成時からを、XMLスキーマが変更されているかどうかをチェックして、無駄な処理を抑え、ビルド時間が改善されるようにbuild-torque.xmlはアップデートされるでしょう。

build.xml

build.xml

The build.xml file is based on Maven's delegator style of operation. Basically, we had simple targets that forward on to the build-torque.xml.

build.xmlファイルはMavenのオペレーションの委譲スタイルに基づきます。 基本的には、build.xmlからフォワードされるbuild-torque.xml上にシンプルなターゲットを作成します。

<?xml version="1.0"?>
<project name="yourproject" default="maven:war" basedir=".">
  <property file="${user.home}/build.properties"/>
  <property file="build.properties"/>
  <property file="project.properties"/>

  <!-- Tie Torque into Maven -->
  <property name="maven.core.callback.pre-compile.buildFile" value="build.xml"/>
  <property name="maven.core.callback.pre-compile.buildTarget" value="torque:main"/>
  
  ...

  <!-- Maven Delegators -->

  ...

  <!-- torque:start -->

  <target name="torque:main">
    <ant antfile="build-torque.xml" target="main"/>
  </target>

  <target name="torque:sql">
    <ant antfile="build-torque.xml" target="sql"/>
  </target>

  <target name="torque:doc">
    <ant antfile="build-torque.xml" target="doc"/>
  </target>

  <target name="torque:create-db">
    <ant antfile="build-torque.xml" target="create-db"/>
  </target>

  <target name="torque:insert-sql">
    <ant antfile="build-torque.xml" target="insert-sql"/>
  </target>

  <target name="torque:jdbc">
    <ant antfile="build-torque.xml" target="jdbc"/>
  </target>

  <target name="torque:datasql">
    <ant antfile="build-torque.xml" target="datasql"/>
  </target>

  <target name="torque:id-table-init-sql">
    <ant antfile="build-torque.xml" target="id-table-init-sql"/>
  </target>

  <target name="torque:datadump">
    <ant antfile="build-torque.xml" target="datadump"/>
  </target>

  <target name="torque:datadtd">
    <ant antfile="build-torque.xml" target="datadtd"/>
  </target>

  <target name="torque:om">
    <ant antfile="build-torque.xml" target="om"/>
  </target>

  <target name="torque:sql2xml">
    <ant antfile="build-torque.xml" target="sql2xml"/>
  </target>

  <target name="torque:ojb-repository">
    <ant antfile="build-torque.xml" target="ojb-repository"/>
  </target>

  <target name="torque:ojb-model">
    <ant antfile="build-torque.xml" target="ojb-model"/>
  </target>

  <!-- torque:end -->

build-torque.xml

build-torque.xml

build-torque.xml actually requires no editting. You merely have to extract it from the Torque jar and put it in the project directory. All of the other jar contents can be ignored as they'll be read from the jar in the ${lib.repo}.

build-torque.xmlは、実際には編集を必要としません。 ただ、Torqueのjarからそれを抽出し、プロジェクトディレクトリに入れなければなりません。 ${lib.repo}からjarが読み出さたときに、他のjarの内容をすべて無視することができます。

project.properties

project.properties

Instead of relying on the typical build.properties, it works well in Maven to store project-wide settings in the project.properties. Maven will handle loading these properties for us, so all that has to be done is over-ride any default Torque behavior and also tell Torque to use this project.properties file instead of it's usual build.properties file via the torque.contextProperties property.

一般的なbuild.propertiesへの依存の代わりとして、Mavenではproject.propertiesにプロジェクト全体に渡るセッティングを格納します。 Mavenはこれらのプロパティをロードし処理を行います。 したがって、されなければならないことは、Torqueの標準の振る舞いのオーバーライドや、build.propertiesの代わりにこのproject.propertiesファイルを使用するようtorque.contextPropertiesプロパティによって、Torqueに伝えることです。

... other project settings...

# -------------------------------------------------------------------
#
#  T O R Q U E   S E T T I N G S
#
# -------------------------------------------------------------------

torque.project = yourproject
torque.database = mysql
torque.contextProperties = project.properties

torque.schema.dir = src/schema
torque.sql.dir = target/sql
torque.java.dir = src/java
torque.doc.dir = target/sql
torque.lib.dir = ${lib.repo}
torque.doc.format = html

# Hypothetical configuration...only need to set properties
# when we don't want the default value
torque.targetPackage = com.company.yourproject.om
torque.addGetByNameMethod = false
torque.addTimeStamp = false
torque.addIntakeRetrievable = true
torque.useManagers = true
torque.useClasspath = true

torque.database.createUrl = jdbc:mysql://localhost:3306/
torque.database.buildUrl = jdbc:mysql://localhost:3306/yourprojectdb
torque.database.url = jdbc:mysql://localhost:3306/yourprojectdb
torque.database.driver = org.gjt.mm.mysql.Driver
torque.database.user = user
torque.database.password = password
torque.database.host = localhost

torque.initialID = 1001

project.xml

project.xml

Currently in Maven b4, you have to list all of the Torque dependencies within your project.xml for the jars to be included in the classpath. Currently this list is:

現在のMaven b4では、Torqueの依存関係(クラスパスに含まれるべきjar群)を全てproject.xmlにリストしなければなりません。 現在のリストはこうなっています:

<dependencies>
  <dependency>
    <id>ant</id>
    <version>1.4.1</version>
  </dependency>
  <dependency>
    <id>commons-beanutils</id>
    <version>1.4-dev-20020724</version>
  </dependency>
  <dependency>
    <id>commons-collections</id>
    <version>2.0</version>
    <url>http://jakarta.apache.org/commons/collections.html</url>
  </dependency>
  <dependency>
    <id>commons-configuration</id>
    <version>1.0-dev</version>
    <url>http://jakarta.apache.org/commons/</url>
  </dependency>
  <dependency>
    <id>commons-dbcp</id>
    <version>1.0-dev-20020806</version>
    <url>http://jakarta.apache.org/commons/</url>
  </dependency>
  <dependency>
    <id>commons-lang</id>
    <version>1.0-dev-20020716</version>
    <url>http://jakarta.apache.org/commons/</url>
  </dependency>
  <dependency>
    <id>commons-logging</id>
    <version>1.0</version>
    <url>http://jakarta.apache.org/commons/</url>
  </dependency>
  <dependency>
    <id>commons-pool</id>
    <version>1.0</version>
    <url>http://jakarta.apache.org/commons/pool/</url>
  </dependency>
  <dependency>
    <id>jcs</id>
    <version>1.0-dev</version>
    <url>http://jakarta.apache.org/turbine/jcs/</url>
  </dependency>
  <dependency>
    <id>jdbc</id>
    <version>2.0</version>
    <url>http://java.sun.com/products/jdbc/download.html#spec</url>
  </dependency>
  <dependency>
    <id>jndi</id>
    <version>1.2.1</version>
    <url>http://java.sun.com/products/jndi/</url>
  </dependency>
  <dependency>
    <id>log4j</id>
    <version>1.1.3</version>
    <url>http://jakarta.apache.org/log4j/</url>
  </dependency>
  <dependency>
    <id>stratum</id>
    <version>1.0-b3-dev</version>
    <url>http://jakarta.apache.org/turbine/stratum/</url>
  </dependency>
  <dependency>
    <id>tomcat-naming</id>
    <version>1.0</version>
    <url>http://jakarta.apache.org/tomcat/</url>
  </dependency>
  <dependency>
    <id>velocity</id>
    <version>1.3</version>
    <url>http://jakarta.apache.org/velocity/</url>
  </dependency>
  <dependency>
    <id>village</id>
    <version>1.5.3</version>
    <url>http://share.whichever.com/index.php?SCREEN=village</url>
  </dependency>
  <dependency>
    <id>xerces</id>
    <type>required</type>
    <version>2.0.2</version>
    <jar>xercesImpl-2.0.2.jar</jar>
    <url>http://xml.apache.org/xerces2-j/</url>
  </dependency>
  <dependency>
    <id>xml-apis</id>
    <type>required</type>
    <version>2.0.2</version>
    <jar>xmlParserAPIs-2.0.2.jar</jar>
    <url>http://xml.apache.org/xerces2-j/</url>
  </dependency>
</dependencies>