开发者

Understanding the @ConnectionDefinitions annotation in jca 1.6

开发者 https://www.devze.com 2023-04-11 06:41 出处:网络
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 @ConnectionDefin开发者_如何

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 @ConnectionDefin开发者_如何学编程ition 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号