基本的な JCA ResourceAdapter の構成およびデプロイ
基本的な Java™ EE Connector Architecture (JCA) の ConnectionFactory およびリソース・アダプターを構成し、デプロイすることができます。
このタスクについて
ExampleRA.rar
という名前のサンプル・リソース・アダプターを使用します。このサンプル・リソース・アダプターは、3 つのタイプのリソース (1 つの接続ファクトリーと 2 つのタイプの管理対象オブジェクト) を提供します。手順
- server.xml ファイルで JCA フィーチャーを使用可能にします。server.xml ファイルは、 [path_to_liberty\wlp\usr\servers\server_name] にあります。
<server> <featureManager> <feature>jca-1.6</feature> <feature>servlet-3.0</feature> </featureManager> </server>
安定化されたフィーチャー:jca-1.6
フィーチャーは安定化されました。jca-1.6
フィーチャーを引き続き使用できます。 ただし、最新の JCA フィーチャーの使用を検討してください。 - リソース・アダプター RAR ファイル (ExampleRA.rar) をサーバーの dropins フォルダーに入れます。サーバーが稼働中の場合、リソース・アダプターがインストールされたことを示す次のようなメッセージがコンソール・ログに含まれます。
[AUDIT ] J2CA7001I: リソース・アダプター ExampleRA が 1.306 秒でインストールされました。
- リソース・アダプターのデプロイメント記述子、アノテーション、およびその他の資料を調べて、そのアダプターがどのようなタイプのリソースを提供しているか、および各アダプターが受け入れる構成プロパティーを判別します。サンプル・リソース・アダプター ExampleRA.rar の場合、この情報は
ra.xml
デプロイメント記述子にあります。 ra.xml ファイルは、 [path_to_ExampleRA\ExampleRA\META-INF.] にあります。デプロイメント記述子は、構成可能な 3 つのタイプのリソースを識別します。<connection-definition> <managedconnectionfactory-class>com.ibm.example.jca.adapter.ManagedConnectionFactoryImpl</managedconnectionfactory-class> <config-property> <config-property-name>tableName</config-property-name> <config-property-type>java.lang.String</config-property-type> </config-property> <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface> ... </connection-definition> <adminobject> <adminobject-interface>javax.resource.cci.ConnectionSpec</adminobject-interface> <adminobject-class>com.ibm.example.jca.adapter.ConnectionSpecImpl</adminobject-class> <config-property> <config-property-name>readOnly</config-property-name> <config-property-type>java.lang.Boolean</config-property-type> <config-property-value>false</config-property-value> </config-property> </adminobject> <adminobject> <adminobject-interface>javax.resource.cci.InteractionSpec</adminobject-interface> <adminobject-class>com.ibm.example.jca.adapter.InteractionSpecImpl</adminobject-class> <config-property> <description>Function name. Supported values are: ADD, FIND, REMOVE</description> <config-property-name>functionName</config-property-name> <config-property-type>java.lang.String</config-property-type> </config-property> </adminobject>
- server.xml ファイルで、使用可能なリソース・タイプのインスタンスを構成します。
<server> <featureManager> <feature>jca-1.6</feature> <feature>servlet-3.0</feature> </featureManager> <connectionFactory jndiName="eis/conFactory"> <properties.ExampleRA tableName="TABLE1"/> </connectionFactory> <adminObject jndiName="eis/conSpec"> <properties.ExampleRA.ConnectionSpec/> </adminObject> <adminObject jndiName="eis/iSpec_ADD"> <properties.ExampleRA.InteractionSpec functionName="ADD"/> </adminObject> <adminObject jndiName="eis/iSpec_FIND"> <properties.ExampleRA.InteractionSpec functionName="FIND"/> </adminObject> </server>
- リソース・インジェクションを使用して、サーブレット内のリソースにアクセスします。例えば、次のように指定します。
@Resource(lookup = "eis/conFactory") private ConnectionFactory conFactory; @Resource(lookup = "eis/conSpec") private ConnectionSpec conSpec; @Resource(lookup = "eis/iSpec_ADD") private InteractionSpec iSpec_ADD; @Resource(lookup = "eis/iSpec_FIND") private InteractionSpec iSpec_FIND; ... MappedRecord input = conFactory.getRecordFactory().createMappedRecord("input"); input.put("city", "Rochester"); input.put("state", "Minnesota"); input.put("population", 106769); Connection con = conFactory.getConnection(conSpec); try { Interaction interaction = con.createInteraction(); interaction.execute(iSpec_ADD, input); interaction.close(); } finally { con.close(); }
注: 注入を使用せずに名前空間からリソースを検索する場合は、 server.xml ファイルで JNDI フィーチャーを有効にする必要があります。