PostgresでXAの設定
どうやらあれとこれのDBを分けるのがベスト、難しかったら仕方ないので1個でもいい、と云われたので、データソースの設定をちゃんとしたXAでやってみる。
S2JDBCで複数データソースを扱うdiconの書き方はグーグル先生に聞くといくつかひっかかるのでよいとして、JBoss側でどう書けばいいのかな。
JBOSS_HOME/docs/examples/jca の中には Oracle はあるけど、Postgres のがないので、探してみたもののなかなかない。JBossのコミュニティにそれらしいのがやっと見つかったので、それを戴いて来てやってみた。
xatest1 と xatest2 の2つのデータベースにつないで、それぞれJNDI名を PostgresDS_1 と PostgresDS_2 とする場合、JBOSS_SERVER_CONF/deploy/postgres-ds.xml をこう書き替える。
<datasources> <xa-datasource> <jndi-name>PostgresDS_1</jndi-name> <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class> <xa-datasource-property name="ServerName">localhost</xa-datasource-property> <xa-datasource-property name="PortNumber">5432</xa-datasource-property> <xa-datasource-property name="DatabaseName">xatest1</xa-datasource-property> <xa-datasource-property name="User">postgres</xa-datasource-property> <xa-datasource-property name="Password">postgres</xa-datasource-property> <track-connection-by-tx></track-connection-by-tx> </xa-datasource> <xa-datasource> <jndi-name>PostgresDS_2</jndi-name> <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class> <xa-datasource-property name="ServerName">localhost</xa-datasource-property> <xa-datasource-property name="PortNumber">5432</xa-datasource-property> <xa-datasource-property name="DatabaseName">xatest2</xa-datasource-property> <xa-datasource-property name="User">postgres</xa-datasource-property> <xa-datasource-property name="Password">postgres</xa-datasource-property> <track-connection-by-tx></track-connection-by-tx> </xa-datasource> </datasources>
取り敢えずこの設定で双方のDBに問題なくつながって更新もかかるのを確認した後、両方にupdateかけた直後に例外を投げるようにしたらちゃんとロールバックしました。
これは素朴に嬉しい。
これでいいのかな・・・・。