Example usage for org.springframework.jms.connection JmsResourceHolder getSession

List of usage examples for org.springframework.jms.connection JmsResourceHolder getSession

Introduction

In this page you can find the example usage for org.springframework.jms.connection JmsResourceHolder getSession.

Prototype

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

Source Link

Document

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

Usage

From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java

/**
 * Obtain a JMS Session that is synchronized with the current transaction, if any.
 * @param cf the ConnectionFactory to obtain a Session for
 * @param existingCon the existing JMS Connection to obtain a Session for
 * (may be {@code null})/*  w ww .  j a  v  a 2  s. co m*/
 * @param synchedLocalTransactionAllowed whether to allow for a local JMS transaction
 * that is synchronized with a Spring-managed transaction (where the main transaction
 * might be a JDBC-based one for a specific DataSource, for example), with the JMS
 * transaction committing right after the main transaction. If not allowed, the given
 * ConnectionFactory needs to handle transaction enlistment underneath the covers.
 * @return the transactional Session, or {@code null} if none found
 * @throws JMSException in case of JMS failure
 */
@Nullable
public static Session getTransactionalSession(final ConnectionFactory cf,
        @Nullable final Connection existingCon, final boolean synchedLocalTransactionAllowed)
        throws JMSException {

    return doGetTransactionalSession(cf, new ResourceFactory() {
        @Override
        @Nullable
        public Session getSession(JmsResourceHolder holder) {
            return holder.getSession(Session.class, existingCon);
        }

        @Override
        @Nullable
        public Connection getConnection(JmsResourceHolder holder) {
            return (existingCon != null ? existingCon : holder.getConnection());
        }

        @Override
        public Connection createConnection() throws JMSException {
            return cf.createConnection();
        }

        @Override
        public Session createSession(Connection con) throws JMSException {
            return con.createSession(synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE);
        }

        @Override
        public boolean isSynchedLocalTransactionAllowed() {
            return synchedLocalTransactionAllowed;
        }
    }, true);
}

From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java

/**
 * Obtain a JMS QueueSession that is synchronized with the current transaction, if any.
 * <p>Mainly intended for use with the JMS 1.0.2 API.
 * @param cf the ConnectionFactory to obtain a Session for
 * @param existingCon the existing JMS Connection to obtain a Session for
 * (may be {@code null})//from w  w w  .  j  a v a  2 s . c o m
 * @param synchedLocalTransactionAllowed whether to allow for a local JMS transaction
 * that is synchronized with a Spring-managed transaction (where the main transaction
 * might be a JDBC-based one for a specific DataSource, for example), with the JMS
 * transaction committing right after the main transaction. If not allowed, the given
 * ConnectionFactory needs to handle transaction enlistment underneath the covers.
 * @return the transactional Session, or {@code null} if none found
 * @throws JMSException in case of JMS failure
 */
@Nullable
public static QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf,
        @Nullable final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed)
        throws JMSException {

    return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() {
        @Override
        @Nullable
        public Session getSession(JmsResourceHolder holder) {
            return holder.getSession(QueueSession.class, existingCon);
        }

        @Override
        @Nullable
        public Connection getConnection(JmsResourceHolder holder) {
            return (existingCon != null ? existingCon : holder.getConnection(QueueConnection.class));
        }

        @Override
        public Connection createConnection() throws JMSException {
            return cf.createQueueConnection();
        }

        @Override
        public Session createSession(Connection con) throws JMSException {
            return ((QueueConnection) con).createQueueSession(synchedLocalTransactionAllowed,
                    Session.AUTO_ACKNOWLEDGE);
        }

        @Override
        public boolean isSynchedLocalTransactionAllowed() {
            return synchedLocalTransactionAllowed;
        }
    }, true);
}

From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java

/**
 * Obtain a JMS TopicSession that is synchronized with the current transaction, if any.
 * <p>Mainly intended for use with the JMS 1.0.2 API.
 * @param cf the ConnectionFactory to obtain a Session for
 * @param existingCon the existing JMS Connection to obtain a Session for
 * (may be {@code null})/*w  w  w  .  ja  v a2  s .c  om*/
 * @param synchedLocalTransactionAllowed whether to allow for a local JMS transaction
 * that is synchronized with a Spring-managed transaction (where the main transaction
 * might be a JDBC-based one for a specific DataSource, for example), with the JMS
 * transaction committing right after the main transaction. If not allowed, the given
 * ConnectionFactory needs to handle transaction enlistment underneath the covers.
 * @return the transactional Session, or {@code null} if none found
 * @throws JMSException in case of JMS failure
 */
@Nullable
public static TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf,
        @Nullable final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed)
        throws JMSException {

    return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() {
        @Override
        @Nullable
        public Session getSession(JmsResourceHolder holder) {
            return holder.getSession(TopicSession.class, existingCon);
        }

        @Override
        @Nullable
        public Connection getConnection(JmsResourceHolder holder) {
            return (existingCon != null ? existingCon : holder.getConnection(TopicConnection.class));
        }

        @Override
        public Connection createConnection() throws JMSException {
            return cf.createTopicConnection();
        }

        @Override
        public Session createSession(Connection con) throws JMSException {
            return ((TopicConnection) con).createTopicSession(synchedLocalTransactionAllowed,
                    Session.AUTO_ACKNOWLEDGE);
        }

        @Override
        public boolean isSynchedLocalTransactionAllowed() {
            return synchedLocalTransactionAllowed;
        }
    }, true);
}