Apache Torque

Es un mapeador de objetos relacionales, …. blah, blah, bla Torque is an object-relational mapper for java. In other words, Torque lets you access and manipulate data in a relational database using java objects. Unlike most other object-relational mappers, Torque does not use reflection to access user-provided classes, but it generates the necessary classes (including the Data Objects) from an XML schema describing the database layout (which can either be written by hand or generated from an existing database). The XML schema can also be used to generate and execute a SQL script which creates all the tables in the database.

As Torque hides database-specific implementation details, Torque makes an application independent of a specific database if no exotic features of the database are used.

Usage of autogeneration eases the customization of the database layer, as you can override the autogenerated methods and thus easily change their behaviour.

Torque was developed as part of the Turbine Framework. It is now decoupled and can be used by itself. Starting with version 2.2 Turbine uses the decoupled Torque.

Torque consists of multiple parts:

runtime The Torque runtime contains everything to allow an application to access the database. It is the only component of Torque needed in your application and can be used standalone. generator The generator contains ant tasks which do all the work for the Maven plugin. If you use the Maven plugin, you do not need to use the generator directly. However, the generator can also be invoked directly using ant. maven-plugin The Maven plugin creates the O/R peer and object classes for accessing and storing data from the database. It can also generate the XML description of an existing database and (in reverse) create an SQL script to create the tables in the database. Internally, the Maven plugin uses the generator to accomplish these tasks. templates The templates contain the building blocks used by the generator to create the O/R peer and object classes, SQL scripts and the like. You can change the templates if you want to customize the output of the generator (this is only necessary in very special circumstances). Up to release 3.1.x, the templates were a part of the generator. Starting with the 3.2 release of Torque, the templates have been separated into their own jar archive. village Village is a 100% Pure Java API that sits on top of the JDBC API. The purpose of this API is to make it easier to interact with a JDBC compliant relational database.


Descarga ‘'’maven 1.0.2’’’ desde los archivios de apache, [[http://archive.apache.org/dist/maven/binaries/]]

Descomprime maven en un directorio de tu preferencia y agrega la ruta de este directorio a la variable de entorno MAVEN_HOME, también es necesario definir JAVA_HOME con la ruta donde esta instalado el ‘'’JDK’’’, no el JRE.

Ejemplo de .profile en unix

… JAVA_HOME=/usr/java MAVEN_HOME=$HOME/local/maven-1.0.2 … PATH=”$MAVEN_HOME/bin:$EC2_HOME/bin:$GROOVY_HOME/bin:/var/ruby/1.8/gem_home/bin:$HOME/local/bin:/usr/gnu/bin:/usr/bin:/usr/X11/bin:/usr/sbin:/sbin:/usr/ucb:/etc:/opt/csw/bin:/usr/local/bin … export JAVA_HOME MAVEN_HOME PATH }}}

Comprueba que maven este correctamente instalado

$ maven -v __ __ | \/ |__ Apache__ _ | |\/| / _’’ \ V / -_) ‘ \ ~ intelligent projects ~ |_| |___,_|_/_|||_| v. 1.0.2 }}}

Crea el archivo ‘‘project.properties’’ con la siguiente línea en el directorio ‘'’HOME’’’ del usuario a trabajar con maven y torque.

maven.repo.remote=http://repo1.maven.org/maven }}}

Para descargar el generador de torque ejecuta la siguiente tarea de maven:

maven plugin:download -DartifactId=maven-torque-plugin -DgroupId=torque -Dversion=3.3


plugin:download-artifact: [mkdir] Created dir: /export/home/ecelis/.maven/repository/torque/plugins [echo] repo is ‘http://repo1.maven.org/maven’ [echo] trying to download http://repo1.maven.org/maven/torque/plugins/maven-torque-plugin-3.3.jar 15K downloaded

plugin:download: [delete] /export/home/ecelis/.maven/plugins not found. [copy] Copying 1 file to /export/home/ecelis/local/maven-1.0.2/plugins BUILD SUCCESSFUL Total time: 32 seconds Finished at: Mon Jan 11 16:28:58 CST 2010 }}}


’'’PROJECT_HOME’’’ se refiere al directorio de proyecto de NetBeans, donde debemos crear algunos directorios y archivos extra para trabajar con Torque.

PROJECT_HOME/ | src/ | | | schema/ | extlib/ }}}

  • '’PROJECT_HOME/src/schema/project-schema.xml’’
  • '’PROJECT_HOME/src/schema/table-id-schema.xml’’
  • '’PROJECT_HOME/extlib/mysql-connector-java-5.1.10-bin.jar’’
  • '’PROJECT_HOME/extlib/torque-3.3.jar’’

Desde NetBeans es necesario agregar los siguientes jars a nuestras ‘'’Libraries’’’

  • mysql-connector-java-5.1.10-bin.jar
  • torque-3.3.jar
  • commons-lang-2.3.jar
  • village-3.3.jar

'’commons-lang-2.3.jar’’ y ‘‘village-3.3.jar’’ se encuentran en el repositorio local de maven en ‘‘HOME/.maven’’


maven.repo.remote=http://repo1.maven.org/maven torque.project










torque.java.dir }}}


<!DOCTYPE database SYSTEM “http://db.apache.org/torque/dtd/database_3_3.dtd”>



<!DOCTYPE database SYSTEM “http://db.apache.org/torque/dtd/database_3_2.dtd”>


Crea el directorio ‘’~/.maven/repository/mysql/jars’’ y copia ahí ‘‘mysql-java-connector-5.1.jar’’ y crea el archivo ‘‘PROJECT_HOME/project.xml’’

3 torque PoloNorte Torque 3.3 mysql-connector-java mysql 5.1.10


Ejecuta torque para generar el código.

$ maven torque }}}



[[[http://db.apache.org/torque|Sitio|web]]] —- CategoryProgramacion