Example usage for javax.jms XAConnectionFactory createXAConnection

List of usage examples for javax.jms XAConnectionFactory createXAConnection

Introduction

In this page you can find the example usage for javax.jms XAConnectionFactory createXAConnection.

Prototype


XAConnection createXAConnection() throws JMSException;

Source Link

Document

Creates an XAConnection with the default user identity.

Usage

From source file:org.bytesoft.bytejta.supports.serialize.XAResourceDeserializerImpl.java

private XAResource deserializeResource(String identifier, Object bean) throws Exception {
    if (DataSourceHolder.class.isInstance(bean)) {
        DataSourceHolder holder = (DataSourceHolder) bean;
        RecoveredResource xares = new RecoveredResource();
        xares.setDataSource(holder.getDataSource());
        return xares;
    } else if (javax.sql.DataSource.class.isInstance(bean)) {
        javax.sql.DataSource dataSource = (javax.sql.DataSource) bean;
        RecoveredResource xares = new RecoveredResource();
        xares.setDataSource(dataSource);
        return xares;
    } else if (XADataSource.class.isInstance(bean)) {
        XADataSource xaDataSource = (XADataSource) bean;
        XAConnection xaConnection = null;
        try {//from ww  w .  j a v a2  s  . c o  m
            xaConnection = xaDataSource.getXAConnection();
            return xaConnection.getXAResource();
        } finally {
            this.closeQuietly(xaConnection);
        }
    } else if (XAConnectionFactory.class.isInstance(bean)) {
        XAConnectionFactory connectionFactory = (XAConnectionFactory) bean;
        javax.jms.XAConnection xaConnection = null;
        XASession xaSession = null;
        try {
            xaConnection = connectionFactory.createXAConnection();
            xaSession = xaConnection.createXASession();
            return xaSession.getXAResource();
        } finally {
            this.closeQuietly(xaSession);
            this.closeQuietly(xaConnection);
        }
    } else if (ManagedConnectionFactory.class.isInstance(bean)) {
        ManagedConnectionFactory connectionFactory = (ManagedConnectionFactory) bean;
        ManagedConnection managedConnection = null;
        try {
            managedConnection = connectionFactory.createManagedConnection(null, null);
            return managedConnection.getXAResource();
        } finally {
            this.closeQuietly(managedConnection);
        }
    } else {
        return null;
    }

}