• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

 Spring Rooの最もベーシックな使い方はroo shell上でentityコマンドを使ってEntityを作成していくやり方ですが、既にDB上にテーブルが存在していて、そのテーブルをEntityとして使用するアプリケーションを作ることもできます。

 Rooのインストール、プロジェクトの作成、DBの接続設定までは同様の手順で行います。

Spring Roo Install

[Spring Roo]プロジェクト作成, Logging&DB接続設定

 これ以降の手順は下記ページを参考に実施していきます。

Chapter 9. Incremental Database Reverse Engineering (DBRE) Add-On

 Database Reverse Engineering(DBRE)アドオンには database introspect と database reverse engineer の2つのコマンドがありますが、いずれかを初めて実行した場合にはJDBCドライバのインストールを促すプロンプトが表示されます。

sh>>
com.example roo> database introspect --schema no-schema-required
Located add-ons that may offer this JDBC driver
2 found, sorted by rank; T = trusted developer; R = Roo 1.1 compatible
ID T R DESCRIPTION -------------------------------------------------------------
01 - Y 9.0.0.801_jdbc4_0001 PostgreSQL #jdbcdriver...
02 Y Y 9.0.801.0001 Postgres #jdbcdriver driverclass:org.postgresql.Driver....

[HINT] use 'addon info id --searchResultId ..' to see details about a search result
[HINT] use 'addon install id --searchResultId ..' to install a specific search result, or
[HINT] use 'addon install bundle --bundleSymbolicName TAB' to install a specific add-on version
JDBC driver not available for 'org.postgresql.Driver'
<<--

 ここで addon info コマンドを使うことで検出されたドライバの詳細情報を見ることが出来ます。

sh>>
com.example roo> addon info id --searchResultId 01
Name.........: spring-roo-postgres-jdbc4-wrapper
BSN..........: org.postgresql.roo.wrapper.postgresql
Version......: 9.0.0.801_jdbc4_0001
Roo Version..: 1.1
Ranking......: 0.0
JAR Size.....: 546943 bytes
PGP Signature: 0x36673F56 signed by Ingo Thierack (ingothierack@googlemail.com)
OBR URL......: http://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/repo/
repository.xml
JAR URL......: httppgp://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/re
po/org/postgresql/roo/wrapper/org.postgresql.roo.wrapper.postgres
ql/9.0-801.jdbc4.0001/org.postgresql.roo.wrapper.postgresql-9.0-8
01.jdbc4.0001.jar
Description..: PostgreSQL #jdbcdriver driverclass:org.postgresql.Driver. This
bundle wraps the standard Maven artifact:
postgresql-9.0-801.jdbc4.
<<--

 最新のドライバをインストールするために、下記コマンドを実行します。

sh>>
com.example roo> addon install id --searchResultId 01
Download URL 'http://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/repo/org/postgresql/roo/wrapper/org.postgresql
.roo.wrapper.postgresql/9.0-801.jdbc4.0001/org.postgresql.roo.wrapper.postgresql-9.0-801.jdbc4.0001.jar' failed
This resource was signed with PGP key ID '0x36673F56', which is not currently trusted
Use 'pgp key view' to view this key, 'pgp trust' to trust it, or 'pgp automatic trust' to trust any keys
Target resource(s):

spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)

Deploying...done.

Unable to install add-on: spring-roo-postgres-jdbc4-wrapper [version: 9.0.0.801_jdbc4_0001]
<<--

 おや、インストールに失敗してしまいました。どうやらドライバのダウンロードURLのKeyが信頼されていないということのようです。pgp key view コマンドを使用してkeyの情報を表示します。

sh>>
com.example roo> pgp key view --keyId 0x36673F56

KEY ID: 0x36673F56 <<<<
More Info: http://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=index&search=0x36673F56
Created: 2011-1-30 18:36:08 +0000
Fingerprint: dc1a2679fc6a938d6681a61389a2afd036673f56
Algorithm: RSA_GENERAL
User ID: Ingo Thierack ingothierack@googlemail.com
Signed By: Key 0x36673F56 - not locally trusted
Subkey ID: 0x1A2EDAED [RSA_GENERAL]
<<--

 このKeyを信頼してダウンロードを可能にするために、下記コマンドを実行します。

sh>>
com.example roo> pgp trust --keyId 0x36673F56
Added trust for key:

KEY ID: 0x36673F56 <<<<
More Info: http://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=index&search=0x36673F56
Created: 2011-1-30 18:36:08 +0000
Fingerprint: dc1a2679fc6a938d6681a61389a2afd036673f56
Algorithm: RSA_GENERAL
User ID: Ingo Thierack ingothierack@googlemail.com
Signed By: Key 0x36673F56 (Ingo Thierack ingothierack@googlemail.com)
Subkey ID: 0x1A2EDAED [RSA_GENERAL]
<<--

 そして再度インストールコマンドを実行します。

sh>>
com.example roo> addon install id --searchResultId 01
Target resource(s):

spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)

Deploying...done.

Successfully installed add-on: spring-roo-postgres-jdbc4-wrapper [version: 9.0.0.801_jdbc4_0001]
[Hint] Please consider rating this add-on with the following command:
[Hint] addon feedback bundle --bundleSymbolicName org.postgresql.roo.wrapper.postgresql --rating ... --comment "..."
<<--

 無事にインストールできました。次にDBREアドオンのdatabase introspectコマンドでテーブルの情報を表示します。

sh>>
com.example roo> database introspect --schema public --file --enableViews
<<--

 出力内容は割愛しますが、XML形式でスキーマの情報が表示されます。

 そして実際にテーブル情報からEntityを作成するためにdatabase reverse engineerコマンドを実行します。

sh>>
com.example roo> database reverse engineer --schema public --package ~.domain --testAutomatically
Created SRC_MAIN_RESOURCES\dbre.xml
Updated ROOT\pom.xml
Updated SRC_MAIN_RESOURCES\META-INF\persistence.xml
Created SRC_MAIN_JAVA\com\example\domain
Created SRC_MAIN_JAVA\com\example\domain\Access.java
Created SRC_MAIN_JAVA\com\example\domain\Content.java
Created SRC_TEST_JAVA\com\example\domain
Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand.java
Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest.java
Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand.java
Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest.java
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_Configurable.aj
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_Entity.aj
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_DbManaged.aj
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_ToString.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_Configurable.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_Entity.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_DbManaged.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_ToString.aj
Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest_Roo_IntegrationTest.aj
Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest_Roo_IntegrationTest.aj
<<--

 --schemaオプションで対象のDBスキーマを、--packageオプションでEntityを作成するパッケージを指定します。--testAutomaticallyを指定することでEntityのインテグレーションテストが自動的に作成されます。

 また、--excludeTablesオプションや--includeTablesオプションで対象のテーブルを特定のテーブルに限定することも出来ます。

 これ以降の手順は、roo shellからEntityを作成したあとと同じ手順でWebアプリケーションのセットアップなどを行うことが出来ます。

posted by akanuma akanuma on Tue 20 Dec 2011 at 08:54 with 0 comments
Contents rssrss
[Rails]to_travel は DateTime.now に対応してない
[Rails]RailsアプリにPassengerから環境変数を渡す
[Rails]Rails4 で datetimepicker を使う
[Vagrant] VM上のUbuntuから名前解決できない
[Rails]Passengerがgitからinstallしたgemを認識しない
[Rails][MessagePack] APIレスポンスとしてのMessagePack検証
[mongodb][couchbase] MongoDBとCouchbaseを比べてみました
[Rails][MySQL] RailsでMySQLを使う
[MySQL] MacにMySQLをインストール
[Rails] APサーバの比較検証(Puma, Unicorn, Passenger)
Tags
railsPassengermysqlRails,Ruby,bootstrapChefCouchbasedatetimepickerMessagePackMongoDBnginxPuma,RSpecrubyubuntuUnicorn,Vagrant
Comments rssrss
yoku0825 yoku0825: nkfの方が使いやすいですが、glibcに含まれているiconvの方が 確実にどの環境にも入っている... 06/11 07:03
Hiroaki Akanuma Hiroaki Akanuma: ご指摘ありがとうございます。「嗜好度は大きい値がより嗜好度が強いことを意味すればどのような値でもよい... 11/08 12:50
akr akr: 初めての推薦エンジンのところ 「属性データはどんなものでも可能。」 は preference val... 11/08 11:18
Services from s21g
YOMU Web小説リーダー
小説投稿サイトの公式ページを開き、WebView表示と読み上げ向け表示を切り替えて、移動中や作業中にもWeb小説の続きを聴きやすくするiPhoneアプリです。
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン