Example usage for org.hibernate.engine.transaction.jta.platform.internal WebSphereExtendedJtaPlatform WebSphereExtendedJtaPlatform

List of usage examples for org.hibernate.engine.transaction.jta.platform.internal WebSphereExtendedJtaPlatform WebSphereExtendedJtaPlatform

Introduction

In this page you can find the example usage for org.hibernate.engine.transaction.jta.platform.internal WebSphereExtendedJtaPlatform WebSphereExtendedJtaPlatform.

Prototype

WebSphereExtendedJtaPlatform

Source Link

Usage

From source file:org.babyfish.springframework.orm.hibernate.LocalXSessionFactoryBuilder.java

License:Open Source License

/**
 * Set the Spring {@link JtaTransactionManager} or the JTA {@link TransactionManager}
 * to be used with Hibernate, if any. Allows for using a Spring-managed transaction
 * manager for Hibernate 4's session and cache synchronization, with the
 * "hibernate.transaction.jta.platform" automatically set to it. Also sets
 * "hibernate.transaction.factory_class" to {@link CMTTransactionFactory},
 * instructing Hibernate to interact with externally managed transactions.
 * <p>A passed-in Spring {@link JtaTransactionManager} needs to contain a JTA
 * {@link TransactionManager} reference to be usable here, except for the WebSphere
 * case where we'll automatically set {@link WebSphereExtendedJtaPlatform} accordingly.
 * <p>Note: If this is set, the Hibernate settings should not contain a JTA platform
 * setting to avoid meaningless double configuration.
 *///from   www. j av a2 s.co m
public LocalXSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager) {
    Assert.notNull(jtaTransactionManager, "Transaction manager reference must not be null");
    if (jtaTransactionManager instanceof JtaTransactionManager) {
        boolean webspherePresent = ClassUtils.isPresent("com.ibm.wsspi.uow.UOWManager",
                getClass().getClassLoader());
        if (webspherePresent) {
            getProperties().put(AvailableSettings.JTA_PLATFORM, new WebSphereExtendedJtaPlatform());
        } else {
            JtaTransactionManager jtaTm = (JtaTransactionManager) jtaTransactionManager;
            if (jtaTm.getTransactionManager() == null) {
                throw new IllegalArgumentException(
                        "Can only apply JtaTransactionManager which has a TransactionManager reference set");
            }
            getProperties().put(AvailableSettings.JTA_PLATFORM,
                    new ConfigurableJtaPlatform(jtaTm.getTransactionManager(), jtaTm.getUserTransaction()));
        }
    } else if (jtaTransactionManager instanceof TransactionManager) {
        getProperties().put(AvailableSettings.JTA_PLATFORM,
                new ConfigurableJtaPlatform((TransactionManager) jtaTransactionManager, null));
    } else {
        throw new IllegalArgumentException(
                "Unknown transaction manager type: " + jtaTransactionManager.getClass().getName());
    }
    getProperties().put(AvailableSettings.TRANSACTION_STRATEGY, new CMTTransactionFactory());
    return this;
}

From source file:org.springframework.orm.hibernate43.LocalSessionFactoryBuilder.java

License:Apache License

/**
 * Set the Spring {@link JtaTransactionManager} or the JTA {@link TransactionManager}
 * to be used with Hibernate, if any. Allows for using a Spring-managed transaction
 * manager for Hibernate 4's session and cache synchronization, with the
 * "hibernate.transaction.jta.platform" automatically set to it. Also sets
 * "hibernate.transaction.factory_class" to {@link CMTTransactionFactory},
 * instructing Hibernate to interact with externally managed transactions.
 * <p>A passed-in Spring {@link JtaTransactionManager} needs to contain a JTA
 * {@link TransactionManager} reference to be usable here, except for the WebSphere
 * case where we'll automatically set {@link WebSphereExtendedJtaPlatform} accordingly.
 * <p>Note: If this is set, the Hibernate settings should not contain a JTA platform
 * setting to avoid meaningless double configuration.
 *//*from   w  ww .  j ava 2s.  c o  m*/
public LocalSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager) {
    Assert.notNull(jtaTransactionManager, "Transaction manager reference must not be null");
    if (jtaTransactionManager instanceof JtaTransactionManager) {
        boolean webspherePresent = ClassUtils.isPresent("com.ibm.wsspi.uow.UOWManager",
                getClass().getClassLoader());
        if (webspherePresent) {
            getProperties().put(AvailableSettings.JTA_PLATFORM, new WebSphereExtendedJtaPlatform());
        } else {
            JtaTransactionManager jtaTm = (JtaTransactionManager) jtaTransactionManager;
            if (jtaTm.getTransactionManager() == null) {
                throw new IllegalArgumentException(
                        "Can only apply JtaTransactionManager which has a TransactionManager reference set");
            }
            getProperties().put(AvailableSettings.JTA_PLATFORM,
                    new ConfigurableJtaPlatform(jtaTm.getTransactionManager(), jtaTm.getUserTransaction()));
        }
    } else if (jtaTransactionManager instanceof TransactionManager) {
        getProperties().put(AvailableSettings.JTA_PLATFORM,
                new ConfigurableJtaPlatform((TransactionManager) jtaTransactionManager, null));
    } else {
        throw new IllegalArgumentException(
                "Unknown transaction manager type: " + jtaTransactionManager.getClass().getName());
    }
    getProperties().put(AvailableSettings.TRANSACTION_STRATEGY, new CMTTransactionFactory());
    return this;
}