Torque:apache another O/R mapping frame

Source: Internet
Author: User

Official homepage: http://db.apache.org/torque/index.html

This paper is based on the reading http://www.blogjava.net/fanyingjie/archive/2008/05/22/202109.html of some of the supplements.

The version used is: 3.3.

The O/R mapping framework is not as powerful as hibernate, but it's easy to use in many ways.

The steps are as follows:

First: Generate PO and datasheet using Torque's generator. Suppose you want to create a new database named Torquedb.

Download generator:http://db.apache.org/torque/download.html and unzip it.

The definition Torquedb-schema.xml file is as follows (note: It looks like you must end with-schema.xml): <?xml version= "1.0"  encoding= "iso-8859-1"   Standalone= "No"?> <! Doctype database system   "HTTP://DB.APACHE.ORG/TORQUE/DTD/DATABASE_3_1.DTD" > <database  name= "Torquedb"  defaultidmethod= "Idbroker" >  <table name= "book"  description= " Book table ">     <column       name=" book_id "       required= "true"       primarykey= "true"        type= "INTEGER"       description= "Book Id"/>     <column       name= "title"        required= "true"       type= "VARCHAR"        size= "255"       description= "Book title"/>      <column       name= "ISBN"        Required= "true"       type= "VARCHAR"       size= "24"       javaname= "ISBN"       description= "ISBN  Number "/>     <column       name=" publisher_id "       required= "true"       type= "INTEGER"        description= "Foreign key publisher"/>     <column       name= "author_id"       required= "true"        type= "INTEGER"       description= "Foreign Key  author "/>     <foreign-key foreigntable=" publisher " onDelete=" Cascade "> &Nbsp;     <reference         local= " publisher_id "        foreign=" publisher_id "/>      </foreign-key>     <foreign-key foreigntable= "Author"  ondelete= " Cascade ">       <reference          Local= "author_id"         foreign= "author_id"/>      </foreign-key>  </table>  <table name= publisher " description=" Publisher table ">     <column       name=" publisher _id "      required=" true "      primarykey=" true "       type= "INTEGER"       description= Publisher  id "/> &NBSP;&NBsp;  <column       name= "Name"        Required= "true"       type= "VARCHAR"       size= "128 "     description=" Publisher name "/>  </table>  <table  Name= "Author"  description= "author table" >     <column        name= "author_id"       required= "true"        primarykey= "true"       type= "INTEGER"        description= "Author id"/>     <column        Name= "First_Name"       required= "true"       type= " VARCHAR "      size=" 128 "      description=" First&nbsp Name "/>     <column       name=" last_name "       required= "true"       type= "VARCHAR"        size= "128"       description= "Last name"/>  </ Table> </database>

Place the Torquedb-schema.xml under the Generator unzipped folder/src/schema that you just downloaded. The default should already have a id-table-schema.xml file, which is used to generate a datasheet that holds the self-added primary key for all business tables.

Modify Build.properties File: # 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. # -------------------------------------------------------------------# # t o r q  U e  c o n f i g u r a t i o n   f i l e # #  $Id: build.properties 591077 2007-11-01  16:42:56z tv $ # # -------------------------------------------------------------------# this  file contains the most commonly used properties. for a # a  complete list of build properties, please refer to: #   http://db.apache.org/torque/releases/torque-3.3/generator/ properties-reference.html # -------------------------------------------------------------------# ---- ---------------------------------------------------------------# #  p r o j e  c t # # -------------------------------------------------------------------# this is  the name of your torque project. your non-java generated #  files will be named using the project name selected below.  If your # project=killerapp then you will have a generated: # #    killerapp-schema.sql # # the custom is then to also rename  Your project xml schema from # project-schema.xml to killerapp-schema.xml.  this&Nbsp;is required # for a few targets such as datasql, datadump,  and datadtd. # -------------------------------------------------------------------torque.project = torque_tutorial#-------------------------------------------------------------------# t a R G e t D a t a B a S e # #--------------  -----------------------------------------------------# This is the target database and only considered when generating # the SQL for your Torque project.  Your possible choices are: # Axion, Cloudscape, DB2, db2400, Hypersonic, InterBase, MSAccess # MSSQL, MySQL, Oracle, PostgreSQL, Sapdb, Sybase #-------------------------------------------------------------------Torque.databaseMySQL # -------------------------------------------------------------------# #  o b j e  c t  m o d e l  i n f o r m a  t i o n # # -------------------------------------------------------------------#  These settings will allow you to customize the way your #  Peer-based object model is created. # -------------------------------------------------------------------# addgetbynamemethod #    If true, Torque adds methods to get database fields  By name/position. # # addintakeretrievable #   if true, the data objects will  Implement intake ' s retrievable #   interface # # addsavemethod #   If  true, torque adds&nbSp;tracking code to determine how to save objects. # # addtimestamp #   if true, torque true puts time stamps  in generated om files. # # baseprefix #   a string to pre-pend to the file names  of base data and peer objects. # # complexobjectmodel #   if true, torque generates data objects  with collection support and #   methods to easily retreive  foreign key relationships. # # targetpackage #   sets the java package the om files  will generated to, e.g. #    "Com.company.project.om". # # useclasspath #   if true, torque will not look in the  <code>Templatepath</code> directory, #   for templates, but instead  Load them from the classpath, allowing you to #   use  Torque without extracted it from the jar. # # usemanagers #   if true, torque will generate manager  Classes that use jcs for caching. #   still considered experimental. # # objectiscaching #   if true, torque generates data objects  that cache their foreign #   key relationships. if this  is not desired  (because the underlying objects #   can  Be manipulated from other code),  set this property to false.  this currently #   cannot&nbsP;combined with the manager setting from above. # # silentdbfetch #   if true, the getxxx ()  methods which  Retrieve associated objects #   will fetch the associated objects  silently. if false, only the #   methods where a  Connection is specified explicitly will #   fetch the associated  objects silently; the methods where no connection #   is  specified will not do a silent fetch and return null  If no previous #   explicit fetch was made. #   this setting has no effect if objectiscaching is  Set to false. # # # generatebeans #   if true,& #nbsp Torque will generate an additional bean for each data object, #    plus methods to create beans from data objects and  vice versa # # beansuffix #   a string to append to the  class name of generated beans  (if they are generated) # #  Enablejava5features #   if true, the generator will use java5  generics in the generated code. # -------------------------------------------------------------------torquetorque.targetpackage =  torque.generated torque.addgetbynamemethod = true Torque.addintakeretrievable = false Torque.addsavemethod = true torque.addtimestamp = true Torque.baseprefix = base Torque.complexobjectmodel = true TORQUE.USECLASSPATH&NBSp;= true torque.usemanagers = 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.