Java プログラムメモ


トップ

Torque でクラスの自動生成

Jakarta から torque-gen-3.1.zip(ソース作成用) をダウンロードする。(その他 Ant が必要です)

torque-gen-3.1.zip を解凍して、ホームディレクトリの build.properties を編集する。

build.properties 記述例

# ------------------------------------------------------------------- # # 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 is required # for a few targets such as datasql, datadump, and datadtd. # ------------------------------------------------------------------- torque.project = プロジェクト名# ------------------------------------------------------------------- # # T A R G E T D A T A B A S E # # ------------------------------------------------------------------- # This is the target database, only considered when generating # the SQL for your Torque project. Your possible choices are: # # axion, cloudscape, db2, db2400, hypersonic, interbase, mssql, # mysql, oracle, postgresql, sapdb, sybase # ------------------------------------------------------------------- torque.database = DB名 torque.targetPackage = 生成するクラスの package 名# ------------------------------------------------------------------- # # D A T A B A S E S E T T I N G S # # ------------------------------------------------------------------- # JDBC connection settings. This is used by the JDBCToXML task that # will create an XML database schema from JDBC metadata. These # settings are also used by the SQL Ant task to initialize your # Torque system with the generated SQL. # # sameJavaName # If true, the JDBC task will set the javaName attribute for the tables # and columns to be the same as SQL name. # ------------------------------------------------------------------- torque.database.createUrl = jdbc:oracle:thin:@127.0.0.1:1521:test torque.database.buildUrl = jdbc:oracle:thin:@127.0.0.1:1521:test torque.database.url = jdbc:oracle:thin:@127.0.0.1:1521:test torque.database.driver = oracle.jdbc.driver.OracleDriver torque.database.user = scott torque.database.password = tiger torque.database.host = 127.0.0.1 torque.sameJavaName = false

次に、ホームディレクトリ/schema にある schema 設定ファイルを編集する。ファイル名は プロジェクト名-schema.xml に修正する。
※ Default は id-table-schema.xml になっています。

schema 設定ファイル 記述例

<?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="test"> <table name="CODE_MST"> <column name="CODE" required="true" primaryKey="true" type="VARCHAR"/> <column name="NAME" type="VARCHAR"/> <column name="DESCRIPTION" type="VARCHAR"/> </table> <table name="DATE_MST"> <column name="YYYYMMDD" required="true" primaryKey="true" type="DATE"/> <column name="YEAR" type="VARCHAR"/> <column name="MONTH" type="VARCHAR"/> <column name="DAY" type="VARCHAR"/> <column name="WEEK" type="VARCHAR"/> </table> </database>

ホームディレクトリにて ant を実行する。

ant -f build-torque.xml

実行が正常終了すると、/src/java,/src/sql にファイルが生成されています。


プログラムメモ アフリカ雑貨・珈琲豆・アールブリュット作品 マゴソスクール クラウドファンディング
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送