Example usage for org.springframework.jdbc.datasource TransactionAwareDataSourceProxy TransactionAwareDataSourceProxy

List of usage examples for org.springframework.jdbc.datasource TransactionAwareDataSourceProxy TransactionAwareDataSourceProxy

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource TransactionAwareDataSourceProxy TransactionAwareDataSourceProxy.

Prototype

public TransactionAwareDataSourceProxy(DataSource targetDataSource) 

Source Link

Document

Create a new TransactionAwareDataSourceProxy.

Usage

From source file:hub.config.connectors.PanAuditConfig.java

@Bean
public TransactionAwareDataSourceProxy panAuditTransactionAwareDataSource() {
    return new TransactionAwareDataSourceProxy(panAuditLazyConnectionDataSource());
}

From source file:hub.config.connectors.ProjectDbConfig.java

@Bean
public TransactionAwareDataSourceProxy projectDbTransactionAwareDataSource() {
    return new TransactionAwareDataSourceProxy(projectDbLazyConnectionDataSource());
}

From source file:moviemanager.backend.SpringConfig.java

@Bean
public MovieManager movieManager() {
    return new MovieManagerImpl(new TransactionAwareDataSourceProxy(dataSource()));
}

From source file:com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBeanTest.java

@Test
public void shouldNotWrapCreateTransactionAwareConnection() throws Exception {
    DataSource dataSource = new TransactionAwareDataSourceProxy(mock(DataSource.class));
    this.factoryBean.setDataSource(dataSource);
    DatabaseDataSourceConnection dataSourceConnection = this.factoryBean.getObject();
    Connection connection = dataSourceConnection.getConnection();
    assertTrue(connection.toString() + " is not transaction aware", connection.toString()
            .startsWith("Transaction-aware proxy for target Connection  from DataSource [Mock for DataSource"));
}

From source file:com.gopivotal.cloudfoundry.test.core.DataSourceUtilsTest.java

@Test
public void transactionAwareUrl() {
    BoneCPDataSource targetDataSource = new BoneCPDataSource();
    targetDataSource.setJdbcUrl(TEST_URL);
    TransactionAwareDataSourceProxy dataSource = new TransactionAwareDataSourceProxy(targetDataSource);
    assertEquals(TEST_URL, this.dataSourceUtils.getUrl(dataSource));
}

From source file:org.activiti.spring.SpringProcessEngineConfiguration.java

@Override
public ProcessEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return super.setDataSource(dataSource);
    } else {// ww w .ja  va 2 s.  com
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return super.setDataSource(proxiedDataSource);
    }
}

From source file:com.apdplat.platform.compass.APDPlatLocalCompassBean.java

/**
 * Sets a <code>DataSource</code> to be used when the index is stored within a database.
 * The data source must be used with {@link org.compass.core.lucene.engine.store.jdbc.ExternalDataSourceProvider}
 * for externally configured data sources (such is the case some of the time with spring). If set, Compass data source provider
 * does not have to be set, since it will automatically default to <code>ExternalDataSourceProvider</code>. If the
 * compass data source provider is set as a compass setting, it will be used.
 * <p/>/*www .ja v  a  2  s  .  c o m*/
 * Note, that it will be automatically wrapped with Spring's <literal>TransactionAwareDataSourceProxy</literal> if not
 * already wrapped by one.
 * {@link org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy}.
 * <p/>
 * Also note that setting the data source is not enough to configure Compass to store the index
 * within the database, the Compass connection string should also be set to <code>jdbc://</code>.
 */
public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
    if (!(dataSource instanceof TransactionAwareDataSourceProxy)) {
        this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
    }
}

From source file:org.sakaiproject.orm.ibatis.SqlMapClientFactoryBean.java

public void afterPropertiesSet() throws Exception {
    if (this.configLocation == null) {
        throw new IllegalArgumentException("configLocation is required");
    }//from   ww w . jav  a 2s.  co  m

    if (this.lobHandler != null) {
        // Make given LobHandler available for SqlMapClient configuration.
        // Do early because because mapping resource might refer to custom types.
        configTimeLobHandlerHolder.set(this.lobHandler);
    }

    try {
        Resources.setDefaultClassLoader(getClass().getClassLoader());
        // Build the SqlMapClient.
        InputStream is = this.configLocation.getInputStream();
        this.sqlMapClient = (this.sqlMapClientProperties != null)
                ? SqlMapClientBuilder.buildSqlMapClient(new InputStreamReader(is), this.sqlMapClientProperties)
                : SqlMapClientBuilder.buildSqlMapClient(new InputStreamReader(is));

        // Tell the SqlMapClient to use the given DataSource, if any.
        if (this.dataSource != null) {
            TransactionConfig transactionConfig = (TransactionConfig) this.transactionConfigClass.newInstance();
            DataSource dataSourceToUse = this.dataSource;
            if (this.useTransactionAwareDataSource
                    && !(this.dataSource instanceof TransactionAwareDataSourceProxy)) {
                dataSourceToUse = new TransactionAwareDataSourceProxy(this.dataSource);
            }
            transactionConfig.setDataSource(dataSourceToUse);
            transactionConfig.initialize(this.transactionConfigProperties);
            applyTransactionConfig(this.sqlMapClient, transactionConfig);
        }
    }

    finally {
        if (this.lobHandler != null) {
            // Reset LobHandler holder.
            configTimeLobHandlerHolder.set(null);
        }
    }
}

From source file:org.kuali.rice.kew.docsearch.dao.impl.DocumentSearchDAOJdbcImpl.java

public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}

From source file:org.pssframework.dao.SqlSessionFactoryFactoryBean.java

private SqlSessionFactory createSqlSessionFactory() throws IOException {
    Reader reader = new InputStreamReader(getConfigLocation().getInputStream());
    try {//w w w  .j a  va2  s .c o m
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        Configuration conf = sqlSessionFactory.getConfiguration();
        if (dataSource != null) {
            DataSource dataSourceToUse = this.dataSource;
            if (this.useTransactionAwareDataSource
                    && !(this.dataSource instanceof TransactionAwareDataSourceProxy)) {
                dataSourceToUse = new TransactionAwareDataSourceProxy(this.dataSource);
            }

            conf.setEnvironment(
                    new Environment("development", new ManagedTransactionFactory(), dataSourceToUse));
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(conf);
        }

        if (mapperLocations != null) {
            Map<String, XNode> sqlFragments = new HashMap<String, XNode>();
            for (Resource r : mapperLocations) {
                logger.info("Loading iBatis3 mapper xml from file[" + r.getFile().getAbsolutePath() + "]");

                Reader mapperReader = new InputStreamReader(r.getInputStream());
                try {
                    XMLMapperBuilder mapperBuilder = new XMLMapperBuilder(mapperReader, conf,
                            r.getFile().getAbsolutePath(), sqlFragments);
                    mapperBuilder.parse();
                } finally {
                    mapperReader.close();
                }
            }
        }
        return sqlSessionFactory;
    } finally {
        reader.close();
    }
}