了解jca 1.6中的@ConnectionDefinitions注释

时间:2011-10-07 18:01:42

标签: java java-ee annotations integration jca

我找不到一个示例,它显示了在ManagedConnectionFactory实现上使用复数@ConnectionDefinitions的用例。令我困惑的是,单个@ConnectionDefinition批注不允许您为每个定义提供@ConfigProperty。您只能使用@ConfigProperty为ManagedConnectionFactory的所有实例设置默认属性,并且每个连接定义必须使用不同的ConnectionFactory接口。所以假设你做了这样的事情:

@ConnectionDefinitions(value = { 
    @ConnectionDefinition(
            connection = com.company.product.connector.MyConnection.class, 
            connectionFactory = com.company.product.connector.ConnectionFactory1.class, 
            connectionFactoryImpl = com.company.product.connector.ConnectionFactory1Impl.class, 
            connectionImpl = com.company.product.connector.MyConnectionImpl.class
    )

    @ConnectionDefinition(
            connection = com.company.product.connector.MyConnection.class, 
            connectionFactory = com.company.product.connector.ConnectionFactory2.class, 
            connectionFactoryImpl = com.company.product.connector.ConnectionFactory2Impl.class, 
            connectionImpl = com.company.product.connector.MyConnectionImpl.class
    )
})
public class MyManagedConnectionFactory implements
    ManagedConnectionFactory, ResourceAdapterAssociation {

@Override
public Object createConnectionFactory(ConnectionManager connectionManager)
        throws ResourceException {
        //Return the connection factory.
    }
}

createConnectionFactory()如何知道是否返回ConnectionFactory1或ConnectionFactory2?除非有人通过ra.xml覆盖注释,否则我认为无法使用config-property作为条件。

似乎很难确定ManagedConnectionFactory属于哪个连接定义,那么为什么要为每个ConnectionFactory分别拥有ManagedConnectionFactory呢?

一个例子非常有帮助。

0 个答案:

没有答案