SAStruts(Super Agile Struts)あれこれ
MySQLからS2JDBC-Genで各種クラスを自動生成しましょう(Eclipse編)
目次
- 序
- 造
- 1.DoltengプラグインでEclipseプロジェクト"s2jdbc-gen-examples"を作成します。
- 2.MySQL Connector/J (JDBCドライバ)を配置
- 3.S2JDBC用のDICONファイルを作成
- s2jdbc.dicon
- jdbc.dicon
- 4.S2JDBC-Gen実行
- 考
- おまけ的
序
今回はDolteng+S2JDBC-Genで、各種クラス(Entity, Service, Condition, Test)ソースの自動生成を試してみます。ここでは、EclipseのAnt機能を使用します。
データベースはMySQLのインストール後の設定で構築したMySQL環境を使用します。
エンティティクラスの生成も併せて参考にして下さい。
前提:Doltengプラグインは、バージョン0.32.0以上であること。当バージョン未満では、S2JDBC-Gen関係のファイルが生成されません。
造
1.DoltengプラグインでEclipseプロジェクト"s2jdbc-gen-examples"を作成します。
設定項目を以下のようにして作成しましょう。
この時点で、S2JDBC-GenおよびS2JDBC-Genが使用するJarファイルが"s2jdbc-gen-examples\lib"フォルダにコピーされ、また、S2JDBC-Gen用のAntビルドファイルが"s2jdbc-gen-examples\s2jdbc-gen-build.xml"としてコピーされます。
2.MySQL Connector/J (JDBCドライバ)を配置
S2JDBC-GenがEntityクラスを自動生成する際には、MySQLデータベースに接続してカタログ情報を取得します。なので、実行時にはJDBCドライバが必要になります。環境・必要なモジュール準備でダウンロードした"mysql-connector-java-5.1.6-bin.jar"を "s2jdbc-gen-examples\src\main\webapp\WEB-INF\lib"フォルダにコピーします。
チェック!1.、2.を行うと以下のようなフォルダ/ファイル配置になります。
3.S2JDBC用のDICONファイルを作成
"s2jdbc-gen-examples\src\main\resources\s2jdbc.dicon"を以下の内容に変更します。<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd"> <components> <include path="jdbc.dicon"/> <include path="s2jdbc-internal.dicon"/> <component name="jdbcManager" class="org.seasar.extension.jdbc.manager.JdbcManagerImpl"> <property name="maxRows">0</property> <property name="fetchSize">0</property> <property name="queryTimeout">0</property> <property name="dialect">mysqlDialect</property> </component> </components>
"s2jdbc-gen-examples\src\main\resources\jdbc.dicon"を以下の内容に変更します。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd"> <components namespace="jdbc"> <include path="jta.dicon"/> <component name="xaDataSource" class="org.seasar.extension.dbcp.impl.XADataSourceImpl"> <property name="driverClassName"> "com.mysql.jdbc.Driver" </property> <property name="URL"> "jdbc:mysql://localhost:3306/sastruts" </property> <property name="user">"sastruts"</property> <property name="password">"sastruts"</property> </component> <component name="connectionPool" class="org.seasar.extension.dbcp.impl.ConnectionPoolImpl"> <property name="timeout">600</property> <property name="maxPoolSize">10</property> <property name="allowLocalTx">true</property> <destroyMethod name="close"/> </component>
<component name="DataSource" class="org.seasar.extension.dbcp.impl.DataSourceImpl" /> </components>
4.S2JDBC-Gen実行
S2JDBC-Genマニュアル:Antタスクの実行を参考にして以下のように作業を進めます。"s2jdbc-gen-examples\s2jdbc-gen-build.xml"ファイルをEclipseのAntエディタで開き、Eclipseメニューから「Run」-「外部ツール」-「外部ツールダイアログを開く」を選択します。外部ツールダイアログが開きます。
左側のメニューにある「Antビルド」という項目をダブルクリックすると、s2jdbc-gen-build.xmlに対する起動設定が新規作成されます。その後、引数に"gen-entity"を指定します。
※できない場合は、手動で新規作成しましょう。
実行ボタンをクリックしましょう。ずらずらとコンソールに生成処理のログを出力されます。最終的に、
~~~~ [gen-service] DEBUG 2008-09-09 18:48:06,875 [main] S2Containerを作成しました。path=jdbc.dicon [gen-service] DEBUG 2008-09-09 18:48:06,875 [main] S2Containerを作成します。path=s2jdbc-internal.dicon [gen-service] DEBUG 2008-09-09 18:48:06,875 [main] S2Containerを作成します。path=convention.dicon [gen-service] DEBUG 2008-09-09 18:48:06,890 [main] S2Containerを作成しました。path=convention.dicon [gen-service] DEBUG 2008-09-09 18:48:06,890 [main] S2Containerを作成しました。path=s2jdbc-internal.dicon [gen-service] DEBUG 2008-09-09 18:48:06,921 [main] S2Containerを作成しました。path=s2jdbc.dicon [gen-service] INFO 2008-09-09 18:48:07,031 [main] Running on [ENV]ut, [DEPLOY MODE]Warm Deploy [gen-service] DEBUG 2008-09-09 18:48:07,125 [main] コマンド(org.seasar.extension.jdbc.gen.internal.command.GenerateServiceCommand)を実行しました。 BUILD SUCCESSFUL Total time: 7 secondsと表示されればOKです。
生成したファイルは、Eclipseのパッケージエクスプローラービューにすぐに表示されませんので、パッケージエクスプローラービュー中のプロジェクトフォルダを左クリックしてF5キー(更新)を押し、ファイルシステムと同期させましょう。そうすると、パッケージエクスプローラービューに生成したファイルが表示されます。
以下のように各種クラス(Entity, Service, Condition, Test)のソースが生成されます。
考
う~ん。これはハイパー簡単ですね。さらにDoltengでここでの手順を自動的に出来てしまうと、なお良いというのは贅沢でしょうか?おまけ的
今回、初めてAntツールを使っているわけなのですが、こんな便利なコマンドがあるのですね。ビルドファイル内に記述すると、環境変数のリストがコンソールに表示されます。<echoproperties/>
アップロードしたファイル
- tomcat_eclipse.jpg
- tomcat_eclipse2.jpg
- after_import.jpg
- start_tomcat.jpg
- import_1.jpg
- create_db_user.jpg
- create_table.jpg
- employee_mod1.jpg
- er1.jpg
- joincolumnser.jpg
- employee_add1.jpg
- employee_add2.jpg
- employee_add3.jpg
- employee_add4.jpg
- employee_del1.jpg
- employee_del2.jpg
- employee_del3.jpg
- employee_token1.jpg
- employee_token2.jpg
- employee_token3.jpg
- employee_page1.jpg
- index_page.jpg
- minus_action_1.jpg
- minus_action_2.jpg
- employee_hsqldb1.jpg
- emp_blk_add1.jpg
- emp_blk_add2.jpg
- emp_blk_add3.jpg
- emp_blk_add4.jpg
- emp_blk_add5.jpg
- hello_project1.jpg
- hello_project2.jpg
- hello_project3.jpg
- hello_project4.jpg
- hello_project5.jpg
- tiles1_1.jpg
- tiles1_2.jpg
- tiles1_3.jpg
- tiles1_4.jpg
- tutorial_db_er.jpg
- mysql_entity1.jpg
- mysql_entity2.jpg
- mysql_entity3.jpg
- mysql_entity4.jpg
- mysql_entity5.jpg
- mysql_entity6.jpg
- mysql_entity7.jpg
- mysql_entity8.jpg
- mysql_entity9.jpg
- mysql_entity10.jpg
- download_file1.jpg
- up.gif
- ajax_pattern1_1.jpg
- ajax_pattern1_2.jpg
- ajax_pattern2_2.jpg
- ajax_pattern2_1.jpg
- emp_blk_upd1.jpg
- emp_blk_upd2.jpg
- emp_blk_upd3.jpg
- emp_blk_upd4.jpg
- emp_blk_upd5.jpg
- ajax_json_1.jpg
- ajax_json_2.jpg
- ajax_json_3.jpg
- ajax_json_4.jpg
- ajax_json_5.jpg
- gen_eclipse1_1.jpg
- gen_eclipse1_2.jpg
- gen_eclipse1_3.jpg
- gen_eclipse1_4.jpg
- gen_eclipse1_5.jpg
- blk_add_vali_1.jpg
- blk_add_vali_2.jpg
- blk_add_vali_3.jpg
- blk_add_vali_4.jpg
- super1_1__1.jpg
- super1_1__2.jpg
- super1_1__0.jpg
- super1_1__3.jpg
- gen_fileheader1.jpg
- super1_1__4.jpg
- supersample2-1_1.jpg
- supersample2-1_2.jpg
- supersample2-1_3.jpg
- supersample2-1_4.jpg
- previewimage.jpg
- previewimage2.jpg
- supersample2-1_5.jpg
- supersample2-2_1.jpg
- supersample2-2_4.jpg
- supersample2-2_2.jpg
- supersample2-2_3.jpg
- supersample2-2_5.jpg
- supersample2-4_1.jpg
- supersample2-4_2.jpg
- supersample2-4_3.jpg
- supersample2-4_4.jpg
- supersample2-4_5.jpg
- supersample2-5_1.jpg
- supersample2-5_2.jpg
- supersample2-5_3.jpg
- supersample2-5_4.jpg
- supersample2-5_5.jpg
- supersample2-5_6.jpg
- supersample2-6_1.jpg
- supersample2-6_2.jpg
- supersample2-6_4.jpg
- supersample2-6_5.jpg
- supersample2-6_3.jpg
- supersample2-7_1.jpg
- supersample2-7_2.jpg
- blk_upd_reset_1.jpg
- blk_upd_reset_2.jpg
- blk_upd_reset_3.jpg
- blk_upd_reset_4.jpg
- blk_upd_reset_5.jpg
- supersample1-6_1.jpg
- supersample1-6_2.jpg
- supersample1-6_3.jpg
- supersample1-6_4.jpg
- supersample1-6_5.jpg
- supersample1-6_6.jpg
- supersample1-7_1.jpg
- supersample1-7_2.jpg
- supersample1-7_3.jpg
- supersample1-7_4.jpg
- supersample1-7_5.jpg
- supersample1-7_6.jpg
- supersample1-4_1.jpg
- supersample1-4_2.jpg
- supersample1-4_3.jpg
- supersample1-4_4.jpg
- supersample1-4_6.jpg
- supersample1-4_7.jpg
- supersample1-4_5.jpg
- pre_db_sample1.jpg
- pre_db_sample2.jpg
- pre_db_sample3.jpg
- pre_db_sample4.jpg
- pre_db_sample5.jpg
- supersample1-8_1.jpg
- supersample1-8_2.jpg
- supersample1-8_3.jpg
- supersample1-8_4.jpg
- supersample1-8_6.jpg
- supersample1-8_5.jpg
- more_s2jdbc_1.jpg
- more_s2jdbc_2.jpg
- more_s2jdbc_3.jpg
- more_s2jdbc_4.jpg
- t_safe_search1_1.jpg
- t_safe_search1_2.jpg
- t_safe_search2_1.jpg
- t_safe_search2_2.jpg
- project_websrv_1.jpg
- project_websrv_3.jpg
- ws_1address_1.jpg
- flexbuilder_1.jpg
- flexbuilder_2.jpg
- flexbuilder_3.jpg
- flexbuilder_4.jpg
- flexbuilder_5.jpg
- flexbuilder_6.jpg
- flexbuilder_7.jpg
- flexbuilder_8.jpg
- flexbuilder_9.jpg
- flexbuilder_10.jpg
- flexbuilder_11.jpg
- flexbuilder_12.jpg
- flexbuilder_13.jpg
- project_flex_1.jpg
- project_flex_2.jpg
- project_flex_3.jpg
- project_flex_4.jpg
- project_flex_5.jpg
- project_flex_8.jpg
- project_flex_7.jpg
- project_flex_6.jpg
- flex_emp_list_1.jpg
- flex_emp_list_2.jpg
- flex_emp_lst_e_1.jpg
- flex_emp_add_1.jpg
- flex_emp_add_2.jpg
- flex_emp_add_3.jpg
- flex_emp_add2_1.jpg
- flex_emp_add2_2.jpg
- flex_emp_add2_3.jpg
- flex_upload_1.jpg
- flex_upload_2.jpg
- tcpmon_1.jpg
- tcpmon_2.jpg
- tcpmon_3.jpg
- tcpmon_4.jpg
- flex_upload2_1.jpg
- flex_upload2_2.jpg
- flex_upload2_3.jpg
- flex_emp_del_1.jpg
- flex_emp_del_2.jpg
- flex_emp_del_3.jpg
- flex_emp_spr_1.jpg
- flex_emp_spr_2.jpg
- flex_emp_spr_3.jpg
- flex_grid_chk1_1.jpg
- flex_grid_chk1_2.jpg
- flex_grid_chk1_3.jpg
- flex_bulk_del_1.jpg
- flex_bulk_del_2.jpg
- flex_bulk_del_3.jpg
- flex_dd_grid1_1.jpg
- flex_dd_grid1_2.jpg
- flex_dd_grid1_3.jpg
- blazeds_setup_1.jpg
- s2blaze_proj_1.jpg
- s2blaze_proj_2.jpg
- s2blaze_proj_3.jpg
- s2blaze_proj_4.jpg
- s2blaze_proj_5.jpg
- s2blaze_proj_6.jpg
- s2blaze_proj_7.jpg
- s2blaze_proj_8.jpg
- s2blaze_proj_9.jpg
- blaze_emplist1_1.jpg
- blaze_emplist2_1.jpg
- blaze_emplist2_2.jpg
- blaze_emp_add_1.jpg
- blaze_emp_add_2.jpg
- blaze_emp_add_3.jpg
- blaze_fms1_1.jpg
- blaze_fms1_2.jpg
- blaze_fms2_1.jpg
- project_batch_1.jpg
- supersample2-3_1.jpg
- supersample2-3_2.jpg
- supersample2-3_3.jpg
- supersample2-8_1.jpg
- supersample2-8_2.jpg
















