类 ConnectionSpecConnectionFactoryAdapter
- java.lang.Object
- org.springframework.jca.cci.connection.DelegatingConnectionFactory
- org.springframework.jca.cci.connection.ConnectionSpecConnectionFactoryAdapter
public class ConnectionSpecConnectionFactoryAdapter extends DelegatingConnectionFactory
An adapter for a target CCIConnectionFactory
, applying the given ConnectionSpec to every standardgetConnection()
call, that is, implicitly invokinggetConnection(ConnectionSpec)
on the target. All other methods simply delegate to the corresponding methods of the target ConnectionFactory.Can be used to proxy a target JNDI ConnectionFactory that does not have a ConnectionSpec configured. Client code can work with the ConnectionFactory without passing in a ConnectionSpec on every
getConnection()
call.In the following example, client code can simply transparently work with the preconfigured "myConnectionFactory", implicitly accessing "myTargetConnectionFactory" with the specified user credentials.
<bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/cci/mycf"/> </bean> <bean id="myConnectionFactory" class="org.springframework.jca.cci.connection.ConnectionSpecConnectionFactoryAdapter"> <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/> <property name="connectionSpec"> <bean class="your.resource.adapter.ConnectionSpecImpl"> <property name="username" value="myusername"/> <property name="password" value="mypassword"/> </bean> </property> </bean>
If the "connectionSpec" is empty, this proxy will simply delegate to the standard
getConnection()
method of the target ConnectionFactory. This can be used to keep a UserCredentialsConnectionFactoryAdapter bean definition just for the option of implicitly passing in a ConnectionSpec if the particular target ConnectionFactory requires it.- 从以下版本开始:
- 1.2
- 作者:
- Juergen Hoeller
- 另请参阅:
getConnection()
, 序列化表格
构造器概要
构造器 构造器 说明 ConnectionSpecConnectionFactoryAdapter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Connection
doGetConnection(ConnectionSpec spec)
This implementation delegates to thegetConnection(ConnectionSpec)
method of the target ConnectionFactory, passing in the specified user credentials.Connection
getConnection()
Determine whether there is currently a thread-bound ConnectionSpec, using it if available, falling back to the statically specified "connectionSpec" property else.void
removeConnectionSpecFromCurrentThread()
Remove any ConnectionSpec for this proxy from the current thread.void
setConnectionSpec(ConnectionSpec connectionSpec)
Set the ConnectionSpec that this adapter should use for retrieving Connections.void
setConnectionSpecForCurrentThread(ConnectionSpec spec)
Set a ConnectionSpec for this proxy and the current thread.从类继承的方法 org.springframework.jca.cci.connection.DelegatingConnectionFactory
afterPropertiesSet, getConnection, getMetaData, getRecordFactory, getReference, getTargetConnectionFactory, setReference, setTargetConnectionFactory
构造器详细资料
ConnectionSpecConnectionFactoryAdapter
public ConnectionSpecConnectionFactoryAdapter()
方法详细资料
setConnectionSpec
public void setConnectionSpec(ConnectionSpec connectionSpec)
Set the ConnectionSpec that this adapter should use for retrieving Connections. Default is none.
setConnectionSpecForCurrentThread
public void setConnectionSpecForCurrentThread(ConnectionSpec spec)
Set a ConnectionSpec for this proxy and the current thread. The given ConnectionSpec will be applied to all subsequentgetConnection()
calls on this ConnectionFactory proxy.This will override any statically specified "connectionSpec" property.
- 参数:
spec
- the ConnectionSpec to apply- 另请参阅:
removeConnectionSpecFromCurrentThread()
removeConnectionSpecFromCurrentThread
public void removeConnectionSpecFromCurrentThread()
Remove any ConnectionSpec for this proxy from the current thread. A statically specified ConnectionSpec applies again afterwards.
getConnection
public final Connection getConnection() throws ResourceException
Determine whether there is currently a thread-bound ConnectionSpec, using it if available, falling back to the statically specified "connectionSpec" property else.
doGetConnection
protected Connection doGetConnection(ConnectionSpec spec) throws ResourceException
This implementation delegates to thegetConnection(ConnectionSpec)
method of the target ConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standardgetConnection()
method of the target ConnectionFactory.- 参数:
spec
- the ConnectionSpec to apply- 返回:
- the Connection
- 抛出:
ResourceException
- 另请参阅:
ConnectionFactory.getConnection(javax.resource.cci.ConnectionSpec)
,ConnectionFactory.getConnection()