JDBC支援サービス jp.ossc.nimbus.service.connection.TableCreatorService

jp.ossc.nimbus.service.connection.TableCreatorServiceは、サービス定義でSQLを定義し、JDBCを使ってデータベースのテーブル準備を行うサービスです。

サービス定義で定義できるSQLは以下です。

  • テーブルの存在を確認するSQL
  • 現在のテーブルのレコードをバックアップする対象レコードを問い合わせるSELECT文(バックアップは、メモリまたはファイルに行います)
  • 現在のテーブルを削除するDROP文とその前後に発行するSQL
  • 現在のテーブルのレコードを削除するSQL
  • テーブルを作成するCREATE文とその前後に発行するSQL
  • テーブルにレコードを挿入するINSER文(挿入するデータは、サービス定義またはファイルで準備します)

このサービスは、複合的なサービスで、以下のサービスを下位サービスとして使用します。

下位サービスインタフェース用途
jp.ossc.nimbus.service.connection.ConnectionFactoryjava.sql.Connectionを取得する
jp.ossc.nimbus.util.converter.StreamConverterデータファイルストリームとRecordListの相互変換を行う

以下に簡単なサービス定義を示します。

  1. <?xml version="1.0" encoding="Shift_JIS"?>
  2. <!DOCTYPE server PUBLIC
  3. "-//Nimbus//DTD Nimbus 1.0//JA"
  4. "http://nimbus.sourceforge.jp/dtd/nimbus-service_1_0.dtd">
  5. <server>
  6. <manager>
  7. <!-- テーブルの準備をするTableCreatorサービス -->
  8. <service name="TableCreator"
  9. code="jp.ossc.nimbus.service.connection.TableCreatorService">
  10. <!-- JDBCコネクションを取得するConnectionFactoryサービス -->
  11. <attribute name="ConnectionFactoryServiceName">#ConnectionFactory</attribute>
  12. <!-- テーブルの存在確認をするSQL -->
  13. <attribute name="ExistsTableQuery">select count(1) from SYSTEM_TABLES where TABLE_NAME='MYUSER'</attribute>
  14. <!-- テーブルを生成するSQL -->
  15. <attribute name="CreateTableQuery">create table MYUSER(name varchar(100), age integer, sex char(1))</attribute>
  16. <!-- テーブルを削除するSQL -->
  17. <attribute name="DropTableQuery">drop table MYUSER</attribute>
  18. <!-- テーブルにレコードを挿入するSQL -->
  19. <attribute name="InsertQuery">insert into MYUSER(name, age, sex) values(?, ?, ?)</attribute>
  20. <!-- サービスの開始時にテーブルを削除するように設定 -->
  21. <attribute name="DropTableOnStart">true</attribute>
  22. <!-- サービスの開始時にテーブルを作成するように設定 -->
  23. <attribute name="CreateTableOnStart">true</attribute>
  24. <!-- サービスの開始時にテーブルにレコードを挿入するように設定 -->
  25. <attribute name="InsertOnStart">true</attribute>
  26. <!-- サービスの停止時にテーブルを削除するように設定 -->
  27. <attribute name="DropTableOnStop">true</attribute>
  28. <!-- レコード文字列を読み込むRecordListのスキーマを定義 -->
  29. <attribute name="RecordListSchema">
  30. :name,java.lang.String
  31. :age,int
  32. :sex,java.lang.String
  33. </attribute>
  34. <!-- テーブルに挿入するレコード -->
  35. <attribute name="InsertRecords">
  36. hoge,20,0
  37. fuga,25,1
  38. </attribute>
  39. <depends>ConnectionFactory</depends>
  40. </service>
  41. <!-- JDBCドライバ経由でConnectionを取得するConnectionFactoryサービス -->
  42. <service name="ConnectionFactory"
  43. code="jp.ossc.nimbus.service.connection.JDBCConnectionFactoryService">
  44. <attribute name="DriverName">org.hsqldb.jdbcDriver</attribute>
  45. <attribute name="ConnectionURL">jdbc:hsqldb:./localDB</attribute>
  46. <attribute name="UserName">sa</attribute>
  47. <attribute name="Password"></attribute>
  48. </service>
  49. </manager>
  50. </server>


JDBC