Changes between Version 1 and Version 2 of torque


Ignore:
Timestamp:
12/15/2011 05:51:33 PM (14 years ago)
Author:
xiejing
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • torque

    v1 v2  
    11== '''torque详细配置''' == 
    2  Torque是Apache的公开源代码项目,最开始是Turbine框架的组成部分,后面被独立出来作为一个单独的组件,归入了Apache的DB项目下。Torque的主要功能是实现对数据库的访问,Torque 主要包含两部分:一部分是 Generator,它通过使用xml配置文件,产生应用程序访问数据库的资源,包括创建数据库、表和初始化sql 语句和 java 文件;另外一部分是 Runtime,提供使用这些代码访问数据库的运行时环境。 
    3         ORM(Object Relational Mapping,对象角色建模 
     2 Torque是Apache的公开源代码项目,最开始是Turbine框架的组成部分,后面被独立出来作为一个单独的组件,归入了Apache的DB项目下。Torque的主要功能是实现对数据库的访问,Torque 主要包含两部分:一部分 是 Generator,它通过使用xml配置文件,产生应用程序访问数据库的资源,包括创建数据库、表和初始化sql 语句和 java 文件;另外一部分是 Runtime,提供使用这些代码访问数据库的运行时环境。[[BR]] 
     3 
     4        ORM(Object Relational Mapping,对象角色建模[[BR]] 
    45        torque各版本之间的差距还是挺大的,本文以torque3.3的配置为例 
    56        http://db.apache.org/torque/download.html下载torque-gen-3.3.zip,torque-3.3.zip。 
     
    89        torque-3.3.zip解压后有torque-3.3.jar和Torque.properties,torque-3.3.jar提供torque运行时的包支持,Torque.properties是toorque访问数据库时初始化环境需要用到的一些配置内容。 
    910 
    10         综上,核心的配置文件为: 
    11         A. build.properties 
    12         B. *-schema.xml、id-table-schema.xml 
    13         C. Torque.properties  
    14         D. 一般还会有一个defalt.properties 
    15  
    16         E. build-torque.xml 这个是ant的配置文件,参照这个就可了解到以上四个配置文件的作用 
    17  
    18         id-table-schema.xml是Torque的IDBroker服务调用,用于指导Torque生成id_table表,他保存了project-schema.xml中相关ID自动增长的相关内容,实现类似于Oracle中的Sequence的功能。 
    19  
    20         torque Genarator的核心任务,可以详细参照build-torque.xml的配置,列举默认常用的如下: 
    21 (1).sql 解析%Torque_home%/schema/*.xml,生成对应的$Torque_home/src/sql/*.sql文件;    
    22 (2).doc 解析%Torque_home%/schema/*.xml,生成对应的$Torque_home/src/sql/*.html文件,描述数据库结构;    
    23 (3).create-db 生成不同平台上产生数据库系统的脚本;    
    24 (4).insert-sql 执行%Torque_home%/schema/*-schema.sql文件到指定数据库;    
    25 (5).sql2xml 解析%Torque_home%/schema/schema.sql文件,产生Torque对应的数据库文件%Torque_home%/schema/schema.xml;    
    26 (5).id-table-init-sql 根据%Torque_home%/schema/id-table-schema.xml文件产生id表的初始化脚本文件; 
    27  
    28 ANT的运行命令为%Torque_home%/ant -f build-torque.xml $taskname 
    29  
    30 ant -f build-torque.xml    
    31 ant -f build-torque.xml create-db    
    32 ant -f build-torque.xml id-table-init-sql    
    33 ant -f build-torque.xml insert-sql 
    34  
    35 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    36  
    37          实际使用过程中,实际上没必要一定使用torque默认的文件夹结构(即:%Torque%\src\schema),因为所有工作都是有Ant完成的,文件夹的位置也都是在build-torque.xml值指定的。当然,如果你不打算修改build-torque.xml的话,就要使用torque默认的结构和要求的文件名格式。 
    38  
    39          Torque 3.3 为例: 
    40  
    41 build.properties文件: 
    42 #工程名称 
    43 torque.project = torque 
    44 #数据库类型 
    45 torque.database = mysql 
    46  
    47 torque.addGetByNameMethod = true 
    48 torque.addIntakeRetrievable = false 
    49 torque.addSaveMethod = true 
    50 torque.addTimeStamp = true 
    51 torque.basePrefix = Base 
    52 torque.complexObjectModel = true 
    53 torque.useClasspath = true 
    54 torque.useManagers = false 
    55 torque.objectIsCaching = true 
    56 torque.silentDbFetch = true 
    57 torque.generateBeans = false 
    58 torque.beanSuffix = Bean 
    59 torque.enableJava5Features = false 
    60  
    61 #数据库URL,注意数据库名应该和工程名保持一致 
    62 torque.database.createUrl = jdbc:mysql://localhost:3306/mydb 
    63 torque.database.buildUrl = jdbc:mysql://localhost:3306/torque 
    64 torque.database.url = jdbc:mysql://localhost:3306/torque 
    65 #数据库驱动类 
    66 torque.database.driver = com.mysql.jdbc.Driver 
    67 #连接数据库使用的用户名 
    68 torque.database.user = root 
    69 #连接数据库使用的密码 
    70 torque.database.password = 229229 
    71 #数据库的主机IP 
    72 torque.database.host = 127.0.0.1 
    73 torque.sameJavaName = false 
    74  
    75 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 
    76  
    77 project-schema.xml: 
    78 随便建了一个最简单的表为例: 
    79  
    80 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    81 <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd"> 
    82  
    83 <database name="torque" defaultIdMethod="idbroker"> 
    84     <table name="user" description="User Table"> 
    85         <column name="id" required="true" primaryKey="true" type="INTEGER" description="User ID"/> 
    86         <column name="name" required="true" type="VARCHAR" size="40" description="User Name"/> 
    87     </table> 
    88 </database> 
    89  
    90 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 
     11        综上,核心的配置文件为:[[BR]] 
     12         A. build.properties[[BR]] 
     13        B. *-schema.xml、id-table-schema.xml[[BR]] 
     14        C. Torque.properties [[BR]] 
     15        D. 一般还会有一个defalt.properties[[BR]] 
     16        E. build-torque.xml 这个是ant的配置文件,参照这个就可了解到以上四个配置文件的作用[[BR]] 
     17 
     18        id-table-schema.xml是Torque的IDBroker服务调用,用于指导Torque生成id_table表,他保存了project-schema.xml中相关ID自动增长的相关内容,实现类似于Oracle中的Sequence的功能。[[BR]] 
     19 
     20        torque Genarator的核心任务,可以详细参照build-torque.xml的配置,列举默认常用的如下:[[BR]] 
     21           (1).sql 解析%Torque_home%/schema/*.xml,生成对应的$Torque_home/src/sql/*.sql文件;[[BR]]    
     22           (2).doc 解析%Torque_home%/schema/*.xml,生成对应的$Torque_home/src/sql/*.html文件,描述数据库结构;[[BR]]   
     23           (3).create-db 生成不同平台上产生数据库系统的脚本;[[BR]]    
     24           (4).insert-sql 执行%Torque_home%/schema/*-schema.sql文件到指定数据库;  [[BR]]  
     25           (5).sql2xml 解析%Torque_home%/schema/schema.sql文件,产生Torque对应的数据库文件%Torque_home%/schema/schema.xml; [[BR]]   
     26           (6).id-table-init-sql 根据%Torque_home%/schema/id-table-schema.xml文件产生id表的初始化脚本文件;[[BR]] 
     27 
     28       ANT的运行命令为%Torque_home%/ant -f build-torque.xml $taskname[[BR]] 
     29 
     30        ant -f build-torque.xml [[BR]]   
     31        ant -f build-torque.xml create-db  [[BR]]   
     32        ant -f build-torque.xml id-table-init-sql   [[BR]]  
     33        ant -f build-torque.xml insert-sql[[BR]]  
     34 
     35 
     36---- 
     37 
     38  实际使用过程中,实际上没必要一定使用torque默认的文件夹结构(即:%Torque%\src\schema),因为所有工作都是有Ant完成的,文件夹的位置也都是在build-torque.xml值指定的。当然,如果你不打算修改build-torque.xml的话,就要使用torque默认的结构和要求的文件名格式。[[BR]]  
     39 
     40         Torque 3.3 为例:[[BR]]  
     41 
     42           build.properties文件:[[BR]]  
     43           #工程名称[[BR]]  
     44          torque.project = torque[[BR]]  
     45         #数据库类型[[BR]]  
     46          torque.database = mysql[[BR]]  
     47 
     48         torque.addGetByNameMethod = true[[BR]]  
     49         torque.addIntakeRetrievable = false[[BR]]  
     50         torque.addSaveMethod = true[[BR]]  
     51         torque.addTimeStamp = true[[BR]]  
     52         torque.basePrefix = Base[[BR]]  
     53         torque.complexObjectModel = true[[BR]]  
     54         torque.useClasspath = true[[BR]]  
     55         torque.useManagers = false[[BR]]  
     56         torque.objectIsCaching = true[[BR]]  
     57         torque.silentDbFetch = true[[BR]]  
     58         torque.generateBeans = false[[BR]]  
     59         torque.beanSuffix = Bean[[BR]]  
     60         torque.enableJava5Features = false[[BR]]  
     61 
     62         #数据库URL,注意数据库名应该和工程名保持一致[[BR]]  
     63           torque.database.createUrl = jdbc:mysql://localhost:3306/mydb[[BR]]  
     64         torque.database.buildUrl = jdbc:mysql://localhost:3306/torque[[BR]]  
     65         torque.database.url = jdbc:mysql://localhost:3306/torque[[BR]]  
     66         #数据库驱动类[[BR]]  
     67          torque.database.driver = com.mysql.jdbc.Driver[[BR]]  
     68         #连接数据库使用的用户名[[BR]]  
     69           torque.database.user = root[[BR]]  
     70         #连接数据库使用的密码[[BR]]  
     71           torque.database.password = 229229[[BR]]  
     72         #数据库的主机IP[[BR]]  
     73         torque.database.host = 127.0.0.1[[BR]]  
     74         torque.sameJavaName = false[[BR]]  
     75 
     76 
     77---- 
     78      project-schema.xml:[[BR]]  
     79      随便建了一个最简单的表为例:[[BR]]  
     80 
     81           <?xml version="1.0" encoding="UTF-8" standalone="no"?>[[BR]]  
     82         <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd">[[BR]]  
     83 
     84         <database name="torque" defaultIdMethod="idbroker">[[BR]]  
     85           <table name="user" description="User Table">[[BR]]  
     86               <column name="id" required="true" primaryKey="true" type="INTEGER" description="User ID"/>[[BR]]  
     87               <column name="name" required="true" type="VARCHAR" size="40" description="User Name"/>[[BR]]  
     88          </table>[[BR]]  
     89        </database>[[BR]]  
     90 
     91 
     92---- 
    9193 
    9294id-table-schema.xml: