了解jca 1.6中的@ConnectionDefinitions注释

发布于 2024-12-08 20:38:20 字数 1613 浏览 0 评论 0原文

我找不到显示在 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 覆盖注释,否则我认为无法使用配置属性作为条件。

确定 ManagedConnectionFactory 属于哪个连接定义似乎很困难,那么当您可以为每个 ConnectionFactory 拥有单独的 ManagedConnectionFactory 时为什么要这样做呢?

举个例子会很有帮助。

I cannot find an example that shows a use case for using the plural @ConnectionDefinitions on a ManagedConnectionFactory implementation. What confuses me is that the singular @ConnectionDefinition annotation does not let you provide @ConfigProperty for each definition. You can only use @ConfigProperty to set the default properties for ALL instances of the ManagedConnectionFactory, and every connection definition must use a different ConnectionFactory interface. So assuming you did something like this:

@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.
    }
}

How will createConnectionFactory() know whether or not to return ConnectionFactory1 or ConnectionFactory2? Unless someone overrides the annotation anyways through ra.xml, I see no way to use a config-property as a conditional.

It seems difficult to determine which connection definition a ManagedConnectionFactory is a part of, so why do this when you can just have seperate ManagedConnectionFactory for every ConnectionFactory?

An example would be very helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文