org.springframework.jms.connection

## Class JmsResourceHolder

- java.lang.Object
- - org.springframework.transaction.support.ResourceHolderSupport
  - - org.springframework.jms.connection.JmsResourceHolder

All Implemented Interfaces:
  org.springframework.transaction.support.ResourceHolder

    public class JmsResourceHolder
    extends org.springframework.transaction.support.ResourceHolderSupport

Resource holder wrapping a JMS `Connection` and a JMS `Session`. `JmsTransactionManager` binds instances of this class to the thread, for a given JMS `ConnectionFactory`.

Note: This is an SPI class, not intended to be used by applications.

Since:
  1.1
Author:
  Juergen Hoeller
See Also:
  `JmsTransactionManager`, `JmsTemplate`

### Constructor Summary

Constructors
Constructor and Description
`JmsResourceHolder()` Create a new JmsResourceHolder that is open for resources to be added.
`JmsResourceHolder(ConnectionFactory connectionFactory)` Create a new JmsResourceHolder that is open for resources to be added.
`JmsResourceHolder(ConnectionFactory connectionFactory, Connection connection, Session session)` Create a new JmsResourceHolder for the given JMS resources.
`JmsResourceHolder(Connection connection, Session session)` Create a new JmsResourceHolder for the given JMS resources.
`JmsResourceHolder(Session session)` Create a new JmsResourceHolder for the given JMS Session.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addConnection(Connection connection)` Add the given Connection to this resource holder.
`void` `addSession(Session session)` Add the given Session to this resource holder.
`void` `addSession(Session session, Connection connection)` Add the given Session to this resource holder, registered for a specific Connection.
`void` `closeAll()` Close all of this resource holder's Sessions and clear its state.
`void` `commitAll()` Commit all of this resource holder's Sessions.
`boolean` `containsSession(Session session)` Determine whether the given Session is registered with this resource holder.
`Connection` `getConnection()` Return this resource holder's default Connection, or `null` if none.
`<C extends Connection> C` `getConnection(Class<C> connectionType)` Return this resource holder's Connection of the given type, or `null` if none.
`Session` `getSession()` Return this resource holder's default Session, or `null` if none.
`<S extends Session> S` `getSession(Class<S> sessionType)` Return this resource holder's Session of the given type, or `null` if none.
`<S extends Session> S` `getSession(Class<S> sessionType, Connection connection)` Return this resource holder's Session of the given type for the given connection, or `null` if none.
`boolean` `isFrozen()` Return whether this resource holder is frozen, i.e.

### Methods inherited from class org.springframework.transaction.support.ResourceHolderSupport

`clear, getDeadline, getTimeToLiveInMillis, getTimeToLiveInSeconds, hasTimeout, isOpen, isRollbackOnly, isSynchronizedWithTransaction, isVoid, released, requested, reset, resetRollbackOnly, setRollbackOnly, setSynchronizedWithTransaction, setTimeoutInMillis, setTimeoutInSeconds, unbound`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### JmsResourceHolder

    public JmsResourceHolder()

Create a new JmsResourceHolder that is open for resources to be added.

See Also:
  `addConnection(javax.jms.Connection)`, `addSession(javax.jms.Session)`

#### JmsResourceHolder

    public JmsResourceHolder(@Nullable
                             ConnectionFactory connectionFactory)

Create a new JmsResourceHolder that is open for resources to be added.

Parameters:
  `connectionFactory` - the JMS ConnectionFactory that this resource holder is associated with (may be `null`)

#### JmsResourceHolder

    public JmsResourceHolder(Session session)

Create a new JmsResourceHolder for the given JMS Session.

Parameters:
  `session` - the JMS Session

#### JmsResourceHolder

    public JmsResourceHolder(Connection connection,
                             Session session)

Create a new JmsResourceHolder for the given JMS resources.

Parameters:
  `connection` - the JMS Connection
  `session` - the JMS Session

#### JmsResourceHolder

    public JmsResourceHolder(@Nullable
                             ConnectionFactory connectionFactory,
                             Connection connection,
                             Session session)

Create a new JmsResourceHolder for the given JMS resources.

Parameters:
  `connectionFactory` - the JMS ConnectionFactory that this resource holder is associated with (may be `null`)
  `connection` - the JMS Connection
  `session` - the JMS Session

### Method Detail

#### isFrozen

    public final boolean isFrozen()

Return whether this resource holder is frozen, i.e. does not allow for adding further Connections and Sessions to it.

See Also:
  `addConnection(javax.jms.Connection)`, `addSession(javax.jms.Session)`

#### addConnection

    public final void addConnection(Connection connection)

Add the given Connection to this resource holder.

#### addSession

    public final void addSession(Session session)

Add the given Session to this resource holder.

#### addSession

    public final void addSession(Session session,
                                 @Nullable
                                 Connection connection)

Add the given Session to this resource holder, registered for a specific Connection.

#### containsSession

    public boolean containsSession(Session session)

Determine whether the given Session is registered with this resource holder.

#### getConnection

    @Nullable
    public Connection getConnection()

Return this resource holder's default Connection, or `null` if none.

#### getConnection

    @Nullable
    public <C extends Connection> C getConnection(Class<C> connectionType)

Return this resource holder's Connection of the given type, or `null` if none.

#### getSession

    @Nullable
    public Session getSession()

Return this resource holder's default Session, or `null` if none.

#### getSession

    @Nullable
    public <S extends Session> S getSession(Class<S> sessionType)

Return this resource holder's Session of the given type, or `null` if none.

#### getSession

    @Nullable
    public <S extends Session> S getSession(Class<S> sessionType,
                                                      @Nullable
                                                      Connection connection)

Return this resource holder's Session of the given type for the given connection, or `null` if none.

#### commitAll

    public void commitAll()
                   throws JMSException

Commit all of this resource holder's Sessions.

Throws:
  `JMSException` - if thrown from a Session commit attempt
See Also:
  `Session.commit()`

#### closeAll

    public void closeAll()

Close all of this resource holder's Sessions and clear its state.

See Also:
  `Session.close()`