Example usage for org.springframework.orm.jpa JpaTransactionManager setDataSource

List of usage examples for org.springframework.orm.jpa JpaTransactionManager setDataSource

Introduction

In this page you can find the example usage for org.springframework.orm.jpa JpaTransactionManager setDataSource.

Prototype

public void setDataSource(@Nullable DataSource dataSource) 

Source Link

Document

Set the JDBC DataSource that this instance should manage transactions for.

Usage

From source file:org.finra.herd.dao.config.DaoSpringModuleConfig.java

/**
 * Our Spring JPA transaction manager that will manage the JPA transactions.
 *
 * @return the JPA transaction manager./*ww w .  j  a  v a2  s.co m*/
 */
@Bean
public JpaTransactionManager herdTransactionManager() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setDataSource(getHerdDataSource());
    transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
    return transactionManager;
}

From source file:org.unitils.orm.jpa.JpaModule.java

public void registerTransactionManagementConfiguration() {
    // Make sure that a spring JpaTransactionManager is used for transaction management in the database module, if the
    // current test object defines a JPA EntityManagerFactory
    for (final DataSourceWrapper wrapper : wrappers) {
        getDatabaseModule()//from  w  w  w.  j a  v a2 s. c  o m
                .registerTransactionManagementConfiguration(new UnitilsTransactionManagementConfiguration() {

                    public boolean isApplicableFor(Object testObject) {
                        return isPersistenceUnitConfiguredFor(testObject);
                    }

                    public PlatformTransactionManager getSpringPlatformTransactionManager(Object testObject) {
                        EntityManagerFactory entityManagerFactory = getPersistenceUnit(testObject);
                        JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(
                                entityManagerFactory);
                        jpaTransactionManager.setDataSource(getDataSource());
                        jpaTransactionManager
                                .setJpaDialect(jpaProviderSupport.getSpringJpaVendorAdaptor().getJpaDialect());
                        return jpaTransactionManager;
                    }

                    public boolean isTransactionalResourceAvailable(Object testObject) {
                        return wrapper.isDataSourceLoaded();
                    }

                    public Integer getPreference() {
                        return 10;
                    }

                });
    }

}