| 93 | | |
| 94 | | id-table-schema.xml: |
| 95 | | |
| 96 | | <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> |
| 97 | | <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd"> |
| 98 | | |
| 99 | | <database name="torque"> |
| 100 | | <table name="ID_TABLE" idMethod="idbroker"> |
| 101 | | <column name="ID_TABLE_ID" required="true" primaryKey="true" type="INTEGER"/> |
| 102 | | <column name="TABLE_NAME" required="true" size="255" type="VARCHAR"/> |
| 103 | | <column name="NEXT_ID" type="INTEGER"/> |
| 104 | | <column name="QUANTITY" type="INTEGER"/> |
| 105 | | |
| 106 | | <unique> |
| 107 | | <unique-column name="TABLE_NAME"/> |
| 108 | | </unique> |
| 109 | | |
| 110 | | </table> |
| 111 | | </database> |
| 112 | | 这个配置文件让数据库生成一个叫做ID_TABLE的表 |
| 113 | | |
| 114 | | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| 115 | | |
| 116 | | torque.properties: |
| 117 | | |
| 118 | | torque.applicationRoot = . |
| 119 | | |
| 120 | | log4j.category.org.apache.torque = ALL, org.apache.torque |
| 121 | | log4j.appender.org.apache.torque = org.apache.log4j.FileAppender |
| 122 | | log4j.appender.org.apache.torque.file = ${torque.applicationRoot}/logs/torque.log |
| 123 | | log4j.appender.org.apache.torque.layout = org.apache.log4j.PatternLayout |
| 124 | | log4j.appender.org.apache.torque.layout.conversionPattern = %d [%t] %-5p %c - %m%n |
| 125 | | log4j.appender.org.apache.torque.append = false |
| 126 | | |
| 127 | | torque.defaults.pool.maxIdle = 8 |
| 128 | | torque.defaults.pool.maxActive = 10 |
| 129 | | torque.defaults.pool.timeBetweenEvictionRunsMillis= 300000 |
| 130 | | torque.defaults.pool.minEvictableIdleTimeMillis = 3600000 |
| 131 | | //以上部分用默认的就可以了,也就是torque-3.3.zip里面自带的 |
| 132 | | |
| 133 | | //下面灰色背景部分是需要针对自己项目改动的 |
| 134 | | torque.defaults.connection.driver = com.mysql.jdbc.Driver |
| 135 | | torque.defaults.connection.url = jdbc:mysql://localhost:3306/torque |
| 136 | | torque.defaults.connection.user = root |
| 137 | | torque.defaults.connection.password = 229229 |
| 138 | | |
| 139 | | torque.database.default=torque |
| 140 | | torque.database.torque.adapter=mysql |
| 141 | | |
| 142 | | # # Using commons-dbcp |
| 143 | | torque.dsfactory.torque.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory |
| 144 | | torque.dsfactory.torque.pool.maxIdle=8 |
| 145 | | torque.dsfactory.torque.pool.maxActive=10 |
| 146 | | torque.dsfactory.torque.pool.testOnBorrow=true |
| 147 | | torque.dsfactory.torque.pool.validationQuery=SELECT 1 |
| 148 | | torque.dsfactory.torque.connection.driver = com.mysql.jdbc.Driver |
| 149 | | torque.dsfactory.torque.connection.url = jdbc:mysql://localhost:3306/torque |
| 150 | | torque.dsfactory.torque.connection.user = root |
| 151 | | torque.dsfactory.torque.connection.password = 229229 |
| 152 | | |
| 153 | | torque.idbroker.clever.quantity=true |
| 154 | | torque.manager.useCache = true |
| 155 | | |
| 156 | | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
| 157 | | |
| 158 | | defalt.properties: |
| 159 | | 我使用的是wdw.properties配置文件,需要在build.xml中改动一下,将default.properties的路径改为wdw.properties文件路径即可 |
| 160 | | |
| 161 | | torque.home = . |
| 162 | | |
| 163 | | #指定了生成Java文件的包路径 |
| 164 | | torque.targetPackage = javaTorque.wdwtest |
| 165 | | torque.runOnlyOnSchemaChange = false |
| 166 | | |
| 167 | | torque.output.dir = ${torque.home}/src |
| 168 | | torque.schema.dir = ${torque.home}/src/schema |
| 169 | | torque.templatePath = templates |
| 170 | | torque.useClasspath = true |
| 171 | | |
| 172 | | torque.doc.dir = ${torque.output.dir}/doc |
| 173 | | torque.java.dir = ${torque.output.dir} |
| 174 | | torque.java.base.dir = ${torque.java.dir} |
| 175 | | torque.javadoc.dir = ${torque.output.dir}/javadoc |
| 176 | | torque.ojb.dir = ${torque.output.dir}/ojb |
| 177 | | torque.sql.dir = ${torque.output.dir}/sql |
| 178 | | torque.omzip.dir = ${torque.output.dir} |
| 179 | | |
| 180 | | torque.database.manualCreation = false |
| 181 | | torque.saveJavaName = false |
| 182 | | |
| 183 | | torque.addGetByNameMethod = true |
| 184 | | torque.addIntakeRetrievable = false |
| 185 | | torque.retrievableInterface = org.apache.turbine.om.Retrievable |
| 186 | | torque.addSaveMethod = true |
| 187 | | torque.addTimeStamp = true |
| 188 | | torque.basePrefix = Base |
| 189 | | torque.complexObjectModel = true |
| 190 | | torque.saveException = Exception |
| 191 | | torque.useClasspath = false |
| 192 | | # Whether to generate Manager classes for JCS-based caching. |
| 193 | | torque.useManagers = false |
| 194 | | torque.objectIsCaching = true |
| 195 | | torque.silentDbFetch = true |
| 196 | | torque.generateBeans = false |
| 197 | | torque.beanSuffix = Bean |
| 198 | | |
| 199 | | torque.subpackage.base.bean = bean |
| 200 | | torque.subpackage.bean = bean |
| 201 | | torque.subpackage.map = map |
| 202 | | |
| 203 | | torque.omzip.src.base = false |
| 204 | | torque.omzip.src.extension = false |
| 205 | | torque.omzip.bin.base = false |
| 206 | | torque.omzip.bin.extension = false |
| 207 | | torque.omzip.deleteFiles = false |
| 208 | | |
| 209 | | torque.generateDeprecated = true |
| 210 | | |
| 211 | | |
| 212 | | torque.idTableXMLFile = |
| 213 | | torque.initialID = 101 |
| 214 | | torque.initialIDValue = 1000 |
| 215 | | torque.initialIDStep = 10 |
| 216 | | |
| 217 | | # Doc settings |
| 218 | | torque.doc.format = html |
| 219 | | torque.doc.html.normalFont = font-family: Verdana; font-size: 10pt; |
| 220 | | torque.doc.html.fkColor = afe295 |
| 221 | | |
| 222 | | torque.template.sql = sql/base/Control.vm |
| 223 | | torque.template.om = om/Control.vm |
| 224 | | torque.template.om.base = om/ControlBase.vm |
| 225 | | torque.template.idTable = sql/id-table/Control.vm |
| 226 | | torque.template.dataDtd = data/Control.vm |
| 227 | | torque.template.dataDump = data/dump/Control.vm |
| 228 | | torque.template.dataSql = sql/load/Control.vm |
| 229 | | torque.template.doc = doc/Control.vm |
| 230 | | torque.template.sqlDbInit = sql/db-init/Control.vm |
| 231 | | torque.template.ojb = ojb/repository/Control.vm |
| 232 | | torque.template.ojbModel = ojb/model/Control.vm |
| 233 | | |
| 234 | | torque.compile.src.dir = ${torque.java.dir} |
| 235 | | torque.compile.build.dir = bin/classes |
| 236 | | torque.compile.debug = on |
| 237 | | torque.compile.deprecation = off |
| 238 | | torque.compile.optimize = off |
| 239 | | |
| 240 | | torque.schema.sql.includes = *-schema.xml |
| 241 | | torque.schema.sql.excludes = |
| 242 | | torque.schema.doc.includes = *-schema.xml |
| 243 | | torque.schema.doc.excludes = |
| 244 | | torque.schema.create-db.includes = *-schema.xml |
| 245 | | torque.schema.create-db.excludes = |
| 246 | | torque.schema.init-sql.includes = *-schema.xml |
| 247 | | torque.schema.init-sql.excludes = id-table-schema.xml |
| 248 | | torque.schema.om.includes = *-schema.xml |
| 249 | | torque.schema.om.excludes = id-table-schema.xml |
| 250 | | torque.schema.ojb.includes = *-schema.xml |
| 251 | | torque.schema.ojb.excludes = |
| 252 | | |
| | 91 | id-table-schema.xml:[[BR]] |
| | 92 | |
| | 93 | <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>[[BR]] |
| | 94 | <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd">[[BR]] |
| | 95 | <database name="torque">[[BR]] |
| | 96 | <table name="ID_TABLE" idMethod="idbroker">[[BR]] |
| | 97 | <column name="ID_TABLE_ID" required="true" primaryKey="true" type="INTEGER"/>[[BR]] |
| | 98 | <column name="TABLE_NAME" required="true" size="255" type="VARCHAR"/>[[BR]] |
| | 99 | <column name="NEXT_ID" type="INTEGER"/>[[BR]] |
| | 100 | <column name="QUANTITY" type="INTEGER"/>[[BR]] |
| | 101 | <unique>[[BR]] |
| | 102 | <unique-column name="TABLE_NAME"/>[[BR]] |
| | 103 | </unique>[[BR]] |
| | 104 | </table>[[BR]] |
| | 105 | </database>[[BR]] |
| | 106 | 这个配置文件让数据库生成一个叫做ID_TABLE的表 |
| | 107 | |
| | 108 | |
| | 109 | ---- |
| | 110 | torque.properties:[[BR]] |
| | 111 | torque.applicationRoot = .[[BR]] |
| | 112 | log4j.category.org.apache.torque = ALL, org.apache.torque[[BR]] |
| | 113 | log4j.appender.org.apache.torque = org.apache.log4j.FileAppender[[BR]] |
| | 114 | log4j.appender.org.apache.torque.file = ${torque.applicationRoot}/logs/torque.log[[BR]] |
| | 115 | log4j.appender.org.apache.torque.layout = org.apache.log4j.PatternLayout[[BR]] |
| | 116 | log4j.appender.org.apache.torque.layout.conversionPattern = %d [%t] %-5p %c - %m%n[[BR]] |
| | 117 | log4j.appender.org.apache.torque.append = false[[BR]] |
| | 118 | torque.defaults.pool.maxIdle = 8[[BR]] |
| | 119 | torque.defaults.pool.maxActive = 10[[BR]] |
| | 120 | torque.defaults.pool.timeBetweenEvictionRunsMillis= 300000[[BR]] |
| | 121 | torque.defaults.pool.minEvictableIdleTimeMillis = 3600000[[BR]] |
| | 122 | //以上部分用默认的就可以了,也就是torque-3.3.zip里面自带的[[BR]] |
| | 123 | //下面灰色背景部分是需要针对自己项目改动的[[BR]] |
| | 124 | torque.defaults.connection.driver = com.mysql.jdbc.Driver[[BR]] |
| | 125 | torque.defaults.connection.url = jdbc:mysql://localhost:3306/torque[[BR]] |
| | 126 | torque.defaults.connection.user = root[[BR]] |
| | 127 | torque.defaults.connection.password = 229229[[BR]] |
| | 128 | |
| | 129 | torque.database.default=torque[[BR]] |
| | 130 | torque.database.torque.adapter=mysql[[BR]] |
| | 131 | |
| | 132 | # # Using commons-dbcp[[BR]] |
| | 133 | torque.dsfactory.torque.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory[[BR]] |
| | 134 | torque.dsfactory.torque.pool.maxIdle=8[[BR]] |
| | 135 | torque.dsfactory.torque.pool.maxActive=10[[BR]] |
| | 136 | torque.dsfactory.torque.pool.testOnBorrow=true[[BR]] |
| | 137 | torque.dsfactory.torque.pool.validationQuery=SELECT 1[[BR]] |
| | 138 | torque.dsfactory.torque.connection.driver = com.mysql.jdbc.Driver[[BR]] |
| | 139 | torque.dsfactory.torque.connection.url = jdbc:mysql://localhost:3306/torque[[BR]] |
| | 140 | torque.dsfactory.torque.connection.user = root[[BR]] |
| | 141 | torque.dsfactory.torque.connection.password = 229229[[BR]] |
| | 142 | |
| | 143 | torque.idbroker.clever.quantity=true[[BR]] |
| | 144 | torque.manager.useCache = true[[BR]] |
| | 145 | |
| | 146 | |
| | 147 | ---- |
| | 148 | defalt.properties:[[BR]] |
| | 149 | 我使用的是wdw.properties配置文件,需要在build.xml中改动一下,将default.properties的路径改为wdw.properties文件路径即可[[BR]] |
| | 150 | torque.home = .[[BR]] |
| | 151 | #指定了生成Java文件的包路径[[BR]] |
| | 152 | torque.targetPackage = javaTorque.wdwtest[[BR]] |
| | 153 | torque.runOnlyOnSchemaChange = false[[BR]] |
| | 154 | torque.output.dir = ${torque.home}/src[[BR]] |
| | 155 | torque.schema.dir = ${torque.home}/src/schema[[BR]] |
| | 156 | torque.templatePath = templates[[BR]] |
| | 157 | torque.useClasspath = true[[BR]] |
| | 158 | |
| | 159 | torque.doc.dir = ${torque.output.dir}/doc[[BR]] |
| | 160 | torque.java.dir = ${torque.output.dir}[[BR]] |
| | 161 | torque.java.base.dir = ${torque.java.dir}[[BR]] |
| | 162 | torque.javadoc.dir = ${torque.output.dir}/javadoc[[BR]] |
| | 163 | torque.ojb.dir = ${torque.output.dir}/ojb[[BR]] |
| | 164 | torque.sql.dir = ${torque.output.dir}/sql[[BR]] |
| | 165 | torque.omzip.dir = ${torque.output.dir}[[BR]] |
| | 166 | |
| | 167 | torque.database.manualCreation = false[[BR]] |
| | 168 | torque.saveJavaName = false[[BR]] |
| | 169 | |
| | 170 | torque.addGetByNameMethod = true[[BR]] |
| | 171 | torque.addIntakeRetrievable = false[[BR]] |
| | 172 | torque.retrievableInterface = org.apache.turbine.om.Retrievable[[BR]] |
| | 173 | torque.addSaveMethod = true[[BR]] |
| | 174 | torque.addTimeStamp = true[[BR]] |
| | 175 | torque.basePrefix = Base[[BR]] |
| | 176 | torque.complexObjectModel = true[[BR]] |
| | 177 | torque.saveException = Exception[[BR]] |
| | 178 | torque.useClasspath = false[[BR]] |
| | 179 | # Whether to generate Manager classes for JCS-based caching.[[BR]] |
| | 180 | torque.useManagers = false[[BR]] |
| | 181 | torque.objectIsCaching = true[[BR]] |
| | 182 | torque.silentDbFetch = true[[BR]] |
| | 183 | torque.generateBeans = false[[BR]] |
| | 184 | torque.beanSuffix = Bean[[BR]] |
| | 185 | |
| | 186 | torque.subpackage.base.bean = bean[[BR]] |
| | 187 | torque.subpackage.bean = bean[[BR]] |
| | 188 | torque.subpackage.map = map[[BR]] |
| | 189 | |
| | 190 | torque.omzip.src.base = false[[BR]] |
| | 191 | torque.omzip.src.extension = false[[BR]] |
| | 192 | torque.omzip.bin.base = false[[BR]] |
| | 193 | torque.omzip.bin.extension = false[[BR]] |
| | 194 | torque.omzip.deleteFiles = false[[BR]] |
| | 195 | |
| | 196 | torque.generateDeprecated = true[[BR]] |
| | 197 | |
| | 198 | |
| | 199 | torque.idTableXMLFile =[[BR]] |
| | 200 | torque.initialID = 101[[BR]] |
| | 201 | torque.initialIDValue = 1000[[BR]] |
| | 202 | torque.initialIDStep = 10[[BR]] |
| | 203 | |
| | 204 | # Doc settings[[BR]] |
| | 205 | torque.doc.format = html[[BR]] |
| | 206 | torque.doc.html.normalFont = font-family: Verdana; font-size: 10pt;[[BR]] |
| | 207 | torque.doc.html.fkColor = afe295[[BR]] |
| | 208 | |
| | 209 | torque.template.sql = sql/base/Control.vm[[BR]] |
| | 210 | torque.template.om = om/Control.vm[[BR]] |
| | 211 | torque.template.om.base = om/ControlBase.vm[[BR]] |
| | 212 | torque.template.idTable = sql/id-table/Control.vm[[BR]] |
| | 213 | torque.template.dataDtd = data/Control.vm[[BR]] |
| | 214 | torque.template.dataDump = data/dump/Control.vm[[BR]] |
| | 215 | torque.template.dataSql = sql/load/Control.vm[[BR]] |
| | 216 | torque.template.doc = doc/Control.vm[[BR]] |
| | 217 | torque.template.sqlDbInit = sql/db-init/Control.vm[[BR]] |
| | 218 | torque.template.ojb = ojb/repository/Control.vm[[BR]] |
| | 219 | torque.template.ojbModel = ojb/model/Control.vm[[BR]] |
| | 220 | |
| | 221 | torque.compile.src.dir = ${torque.java.dir}[[BR]] |
| | 222 | torque.compile.build.dir = bin/classes[[BR]] |
| | 223 | torque.compile.debug = on[[BR]] |
| | 224 | torque.compile.deprecation = off[[BR]] |
| | 225 | torque.compile.optimize = off[[BR]] |
| | 226 | |
| | 227 | torque.schema.sql.includes = *-schema.xml[[BR]] |
| | 228 | torque.schema.sql.excludes =[[BR]] |
| | 229 | torque.schema.doc.includes = *-schema.xml[[BR]] |
| | 230 | torque.schema.doc.excludes =[[BR]] |
| | 231 | torque.schema.create-db.includes = *-schema.xml[[BR]] |
| | 232 | torque.schema.create-db.excludes =[[BR]] |
| | 233 | torque.schema.init-sql.includes = *-schema.xml[[BR]] |
| | 234 | torque.schema.init-sql.excludes = id-table-schema.xml[[BR]] |
| | 235 | torque.schema.om.includes = *-schema.xml[[BR]] |
| | 236 | torque.schema.om.excludes = id-table-schema.xml[[BR]] |
| | 237 | torque.schema.ojb.includes = *-schema.xml[[BR]] |
| | 238 | torque.schema.ojb.excludes =[[BR]] |
| | 239 | |
| | 240 | [[Image(torque.png)]] |
| | 241 | |
| | 242 | javaTorque.wdwtest包里面的四个类:[[BR]] |
| | 243 | User.java就是数据表user的持久层对象[[BR]] |
| | 244 | UserPeer.java封装了持久层的操作[[BR]] |
| | 245 | sql包下面是torque生成的建表sql语句[[BR]] |
| | 246 | 所以,最常见的做法是:写好torque的配置文件*-schema.xml,然后生成其他一切东西,包括数据库[[BR]] |
| | 247 | 当然,torque也提供根据.sql文件生成xml配置文件的功能[[BR]] |
| | 248 | |
| | 249 | |