编写部署描述符
下面的任务就是在部署描述符里指定资源适配器的相关接口和实现类。具体需要指定以下的接口和类:
ManagedConnectionFactory,这里是DemoManagedConnectionFactory;
Connectionfactory的接口,这里是javax..resource.cci.ConnectionFactory;
Connectionfactory的实现类,这里是DemoConnectionFactoryImpl;
连接的接口,这里是DemoConnection;
连接的实现类,这里是DemoConnectionImpl。
另外,还需要指定以下的属性:
是否支持事务,这里是NoTransaction;
安全认证的支持,这里是false;
DemoManagedConnectionFactory中使用的属性,其中Server的值为localhost,Port的值为2008。
例程9是资源适配器的具体内容,它要保存为ra.xml放在资源适配器打包文件RAR的META-INF目录下。
例程9 资源适配器的具体内容
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE connector PUBLIC '-//Sun Microsystems, Inc.//DTD Connector 1.0//EN'
3 'http://java.sun.com/dtd/connector_1_0.dtd'>
4 <connector>
5 <display-name>DemoRA</display-name>
6 <vendor-name>HELLKING</vendor-name>
7 <spec-version>1.0</spec-version>
8 <eis-type>NO TRANS</eis-type>
9 <version>1.2</version>
10 <resourceadapter>
11 <managedconnectionfactory-class>com.hellking.jca.DemoManagedConnectionFactory
12 </managedconnectionfactory-class>
13 <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
14 <connectionfactory-impl-class>com.hellking.jca.DemoConnectionFactoryImpl
15 </connectionfactory-impl-class>
16 <connection-interface>com.hellking.jca.DemoConnection</connection-interface>
17 <connection-impl-class>com.hellking.jca.DemoConnectionImpl</connection-impl-class>
18 <transaction-support>NoTransaction</transaction-support>
19 <config-property>
20 <config-property-name>Server</config-property-name>
21 <config-property-type>java.lang.String</config-property-type>
22 <config-property-value>localhost</config-property-value>
23 </config-property>
24 <config-property>
25 <config-property-name>Port</config-property-name>
26 <config-property-type>java.lang.Integer</config-property-type>
27 <config-property-value>2008</config-property-value>
28 </config-property>
29 <reauthentication-support>false</reauthentication-support>
30 </resourceadapter>
31 </connector>
32
2 <!DOCTYPE connector PUBLIC '-//Sun Microsystems, Inc.//DTD Connector 1.0//EN'
3 'http://java.sun.com/dtd/connector_1_0.dtd'>
4 <connector>
5 <display-name>DemoRA</display-name>
6 <vendor-name>HELLKING</vendor-name>
7 <spec-version>1.0</spec-version>
8 <eis-type>NO TRANS</eis-type>
9 <version>1.2</version>
10 <resourceadapter>
11 <managedconnectionfactory-class>com.hellking.jca.DemoManagedConnectionFactory
12 </managedconnectionfactory-class>
13 <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
14 <connectionfactory-impl-class>com.hellking.jca.DemoConnectionFactoryImpl
15 </connectionfactory-impl-class>
16 <connection-interface>com.hellking.jca.DemoConnection</connection-interface>
17 <connection-impl-class>com.hellking.jca.DemoConnectionImpl</connection-impl-class>
18 <transaction-support>NoTransaction</transaction-support>
19 <config-property>
20 <config-property-name>Server</config-property-name>
21 <config-property-type>java.lang.String</config-property-type>
22 <config-property-value>localhost</config-property-value>
23 </config-property>
24 <config-property>
25 <config-property-name>Port</config-property-name>
26 <config-property-type>java.lang.Integer</config-property-type>
27 <config-property-value>2008</config-property-value>
28 </config-property>
29 <reauthentication-support>false</reauthentication-support>
30 </resourceadapter>
31 </connector>
32