nimbus (1.2.4) | 2018-01-25 20:02 |
nimbus-sample (1.2.4) | 2018-01-26 17:06 |
jp.ossc.nimbus.service.connection.TableCreatorServiceは、サービス定義でSQLを定義し、JDBCを使ってデータベースのテーブル準備を行うサービスです。
サービス定義で定義できるSQLは以下です。
このサービスは、複合的なサービスで、以下のサービスを下位サービスとして使用します。
下位サービスインタフェース | 用途 |
jp.ossc.nimbus.service.connection.ConnectionFactory | java.sql.Connectionを取得する |
jp.ossc.nimbus.util.converter.StreamConverter | データファイルストリームとRecordListの相互変換を行う |
以下に簡単なサービス定義を示します。
- <?xml version="1.0" encoding="Shift_JIS"?>
- <!DOCTYPE server PUBLIC
- "-//Nimbus//DTD Nimbus 1.0//JA"
- "http://nimbus.sourceforge.jp/dtd/nimbus-service_1_0.dtd">
- <server>
- <manager>
- <!-- テーブルの準備をするTableCreatorサービス -->
- <service name="TableCreator"
- code="jp.ossc.nimbus.service.connection.TableCreatorService">
- <!-- JDBCコネクションを取得するConnectionFactoryサービス -->
- <attribute name="ConnectionFactoryServiceName">#ConnectionFactory</attribute>
- <!-- テーブルの存在確認をするSQL -->
- <attribute name="ExistsTableQuery">select count(1) from SYSTEM_TABLES where TABLE_NAME='MYUSER'</attribute>
- <!-- テーブルを生成するSQL -->
- <attribute name="CreateTableQuery">create table MYUSER(name varchar(100), age integer, sex char(1))</attribute>
- <!-- テーブルを削除するSQL -->
- <attribute name="DropTableQuery">drop table MYUSER</attribute>
- <!-- テーブルにレコードを挿入するSQL -->
- <attribute name="InsertQuery">insert into MYUSER(name, age, sex) values(?, ?, ?)</attribute>
- <!-- サービスの開始時にテーブルを削除するように設定 -->
- <attribute name="DropTableOnStart">true</attribute>
- <!-- サービスの開始時にテーブルを作成するように設定 -->
- <attribute name="CreateTableOnStart">true</attribute>
- <!-- サービスの開始時にテーブルにレコードを挿入するように設定 -->
- <attribute name="InsertOnStart">true</attribute>
- <!-- サービスの停止時にテーブルを削除するように設定 -->
- <attribute name="DropTableOnStop">true</attribute>
- <!-- レコード文字列を読み込むRecordListのスキーマを定義 -->
- <attribute name="RecordListSchema">
- :name,java.lang.String
- :age,int
- :sex,java.lang.String
- </attribute>
- <!-- テーブルに挿入するレコード -->
- <attribute name="InsertRecords">
- hoge,20,0
- fuga,25,1
- </attribute>
- <depends>ConnectionFactory</depends>
- </service>
- <!-- JDBCドライバ経由でConnectionを取得するConnectionFactoryサービス -->
- <service name="ConnectionFactory"
- code="jp.ossc.nimbus.service.connection.JDBCConnectionFactoryService">
- <attribute name="DriverName">org.hsqldb.jdbcDriver</attribute>
- <attribute name="ConnectionURL">jdbc:hsqldb:./localDB</attribute>
- <attribute name="UserName">sa</attribute>
- <attribute name="Password"></attribute>
- </service>
- </manager>
- </server>