Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.jca.cci.connection
Class ConnectionSpecConnectionFactoryAdapter

    java.lang.Object
      org.springframework.jca.cci.connection.DelegatingConnectionFactory
          org.springframework.jca.cci.connection.ConnectionSpecConnectionFactoryAdapter

All Implemented Interfaces:
  java.io.Serializable, javax.naming.Referenceable, javax.resource.cci.ConnectionFactory, InitializingBean

    public class ConnectionSpecConnectionFactoryAdapter

extends DelegatingConnectionFactory

An adapter for a target CCI `ConnectionFactory`, applying the given ConnectionSpec to every standard `getConnection()` call, that is, implicitly invoking `getConnection(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.

Since:
  1.2
Author:
  Juergen Hoeller
See Also:
  `getConnection()`, Serialized Form

Constructor Summary
`ConnectionSpecConnectionFactoryAdapter()`

Method Summary
`protected javax.resource.cci.Connection` | `doGetConnection(javax.resource.cci.ConnectionSpec spec)` This implementation delegates to the `getConnection(ConnectionSpec)` method of the target ConnectionFactory, passing in the specified user credentials.
`javax.resource.cci.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(javax.resource.cci.ConnectionSpec connectionSpec)` Set the ConnectionSpec that this adapter should use for retrieving Connections.
`void` | `setConnectionSpecForCurrentThread(javax.resource.cci.ConnectionSpec spec)` Set a ConnectionSpec for this proxy and the current thread.

Methods inherited from class org.springframework.jca.cci.connection.DelegatingConnectionFactory
`afterPropertiesSet, getConnection, getMetaData, getRecordFactory, getReference, getTargetConnectionFactory, setReference, setTargetConnectionFactory`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ConnectionSpecConnectionFactoryAdapter

    public ConnectionSpecConnectionFactoryAdapter()

Method Detail

### setConnectionSpec

    public void setConnectionSpec(javax.resource.cci.ConnectionSpec connectionSpec)

  Set the ConnectionSpec that this adapter should use for retrieving Connections. Default is none.

### setConnectionSpecForCurrentThread

    public void setConnectionSpecForCurrentThread(javax.resource.cci.ConnectionSpec spec)

  Set a ConnectionSpec for this proxy and the current thread. The given ConnectionSpec will be applied to all subsequent `getConnection()` calls on this ConnectionFactory proxy.

  This will override any statically specified "connectionSpec" property.

  Parameters:
    `spec` - the ConnectionSpec to apply
  See Also:
    `removeConnectionSpecFromCurrentThread()`

### removeConnectionSpecFromCurrentThread

    public void removeConnectionSpecFromCurrentThread()

  Remove any ConnectionSpec for this proxy from the current thread. A statically specified ConnectionSpec applies again afterwards.

  See Also:
    `setConnectionSpecForCurrentThread(javax.resource.cci.ConnectionSpec)`

### getConnection

    public final javax.resource.cci.Connection getConnection()
                                                      throws javax.resource.ResourceException

  Determine whether there is currently a thread-bound ConnectionSpec, using it if available, falling back to the statically specified "connectionSpec" property else.

  Specified by:
    `getConnection` in interface `javax.resource.cci.ConnectionFactory`
  Overrides:
    `getConnection` in class `DelegatingConnectionFactory`
  Throws:
    `javax.resource.ResourceException`
  See Also:
    `doGetConnection(javax.resource.cci.ConnectionSpec)`

### doGetConnection

    protected javax.resource.cci.Connection doGetConnection(javax.resource.cci.ConnectionSpec spec)
                                                     throws javax.resource.ResourceException

  This implementation delegates to the `getConnection(ConnectionSpec)` method of the target ConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standard `getConnection()` method of the target ConnectionFactory.

  Parameters:
    `spec` - the ConnectionSpec to apply
  Returns:
    the Connection
  Throws:
    `javax.resource.ResourceException`
  See Also:
    `ConnectionFactory.getConnection(javax.resource.cci.ConnectionSpec)`, `ConnectionFactory.getConnection()`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD