Java Code Examples for org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy

The following are top voted examples for showing how to use org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gorm-hibernate5   File: HibernateDatastore.java   Source Code and License 6 votes vote down vote up
@Override
public void addTenantForSchema(String schemaName) {
    addTenantForSchemaInternal(schemaName);
    registerAllEntitiesWithEnhancer();
    HibernateConnectionSource defaultConnectionSource = (HibernateConnectionSource) connectionSources.getDefaultConnectionSource();
    DataSource dataSource = defaultConnectionSource.getDataSource();
    if(dataSource instanceof TransactionAwareDataSourceProxy) {
        dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
    }
    Object existing = TransactionSynchronizationManager.getResource(dataSource);
    if(existing instanceof ConnectionHolder) {
        ConnectionHolder connectionHolder = (ConnectionHolder) existing;
        Connection connection = connectionHolder.getConnection();
        try {
            if(!connection.isClosed() && !connection.isReadOnly()) {
                schemaHandler.useDefaultSchema(connection);
            }
        } catch (SQLException e) {
            throw new DatastoreConfigurationException("Failed to reset to default schema: " + e.getMessage(), e);
        }
    }

}
 
Example 2
Project: gorm-hibernate5   File: GrailsHibernateTemplate.java   Source Code and License 6 votes vote down vote up
public GrailsHibernateTemplate(SessionFactory sessionFactory) {
    Assert.notNull(sessionFactory, "Property 'sessionFactory' is required");
    this.sessionFactory = sessionFactory;

    ConnectionProvider connectionProvider = ((SessionFactoryImplementor) sessionFactory).getServiceRegistry().getService(ConnectionProvider.class);
    if(connectionProvider instanceof DatasourceConnectionProviderImpl) {
        this.dataSource = ((DatasourceConnectionProviderImpl) connectionProvider).getDataSource();
        if(dataSource instanceof TransactionAwareDataSourceProxy) {
            this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
        }
        jdbcExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource);
    }
    else {
        // must be in unit test mode, setup default translator
        SQLErrorCodeSQLExceptionTranslator sqlErrorCodeSQLExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator();
        sqlErrorCodeSQLExceptionTranslator.setDatabaseProductName("H2");
        jdbcExceptionTranslator = sqlErrorCodeSQLExceptionTranslator;
    }
}
 
Example 3
Project: kc-rice   File: RiceDataSourceConnectionFactory.java   Source Code and License 6 votes vote down vote up
/**
 * Return the DataSource to use for the given JCD alias.
 * <p>This implementation fetches looks for a bean with the
 * JCD alias name in the provided Spring BeanFactory.
 * @param jcdAlias the JCD alias to retrieve a DataSource for
 * @return the DataSource to use
 */

protected DataSource getDataSource(String jcdAlias) throws LookupException {
	DataSource dataSource = null;
	for (BeanFactory beanFactory : beanFactories) {
		if (beanFactory.containsBean(jcdAlias)) {
			dataSource = (DataSource) beanFactory.getBean(jcdAlias, DataSource.class);
			break;
		}
	}
	if (dataSource == null) {
		throw new LookupException("Could not lookup datasource with alias " + jcdAlias);
	} else if (dataSource instanceof TransactionAwareDataSourceProxy) {
		return dataSource;
	} else {
		return new TransactionAwareDataSourceProxy(dataSource);
	}
}
 
Example 4
Project: rice   File: RiceDataSourceConnectionFactory.java   Source Code and License 6 votes vote down vote up
/**
 * Return the DataSource to use for the given JCD alias.
 * <p>This implementation fetches looks for a bean with the
 * JCD alias name in the provided Spring BeanFactory.
 * @param jcdAlias the JCD alias to retrieve a DataSource for
 * @return the DataSource to use
 */

protected DataSource getDataSource(String jcdAlias) throws LookupException {
	DataSource dataSource = null;
	for (BeanFactory beanFactory : beanFactories) {
		if (beanFactory.containsBean(jcdAlias)) {
			dataSource = (DataSource) beanFactory.getBean(jcdAlias, DataSource.class);
			break;
		}
	}
	if (dataSource == null) {
		throw new LookupException("Could not lookup datasource with alias " + jcdAlias);
	} else if (dataSource instanceof TransactionAwareDataSourceProxy) {
		return dataSource;
	} else {
		return new TransactionAwareDataSourceProxy(dataSource);
	}
}
 
Example 5
Project: cobarclient   File: DefaultConcurrentRequestProcessor.java   Source Code and License 6 votes vote down vote up
private List<RequestDepository> fetchConnectionsAndDepositForLaterUse(
                                                                      List<ConcurrentRequest> requests) {
    List<RequestDepository> depos = new ArrayList<RequestDepository>();
    for (ConcurrentRequest request : requests) {
        DataSource dataSource = request.getDataSource();

        Connection springCon = null;
        boolean transactionAware = (dataSource instanceof TransactionAwareDataSourceProxy);
        try {
            springCon = (transactionAware ? dataSource.getConnection() : DataSourceUtils
                    .doGetConnection(dataSource));
        } catch (SQLException ex) {
            throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", ex);
        }

        RequestDepository depo = new RequestDepository();
        depo.setOriginalRequest(request);
        depo.setConnectionToUse(springCon);
        depo.setTransactionAware(transactionAware);
        depos.add(depo);
    }

    return depos;
}
 
Example 6
Project: kuali_rice   File: RiceDataSourceConnectionFactory.java   Source Code and License 6 votes vote down vote up
/**
 * Return the DataSource to use for the given JCD alias.
 * <p>This implementation fetches looks for a bean with the
 * JCD alias name in the provided Spring BeanFactory.
 * @param jcdAlias the JCD alias to retrieve a DataSource for
 * @return the DataSource to use
 */

protected DataSource getDataSource(String jcdAlias) throws LookupException {
	DataSource dataSource = null;
	for (BeanFactory beanFactory : beanFactories) {
		if (beanFactory.containsBean(jcdAlias)) {
			dataSource = (DataSource) beanFactory.getBean(jcdAlias, DataSource.class);
			break;
		}
	}
	if (dataSource == null) {
		throw new LookupException("Could not lookup datasource with alias " + jcdAlias);
	} else if (dataSource instanceof TransactionAwareDataSourceProxy) {
		return dataSource;
	} else {
		return new TransactionAwareDataSourceProxy(dataSource);
	}
}
 
Example 7
Project: lams   File: TransactionAwareDataSourceConnectionProvider.java   Source Code and License 5 votes vote down vote up
/**
 * Return a TransactionAwareDataSourceProxy for the given DataSource,
 * provided that it isn't a TransactionAwareDataSourceProxy already.
 */
@Override
protected DataSource getDataSourceToUse(DataSource originalDataSource) {
	if (originalDataSource instanceof TransactionAwareDataSourceProxy) {
		return originalDataSource;
	}
	return new TransactionAwareDataSourceProxy(originalDataSource);
}
 
Example 8
Project: mirage-integration   File: SpringConnectionProvider.java   Source Code and License 5 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        // If we got a TransactionAwareDataSourceProxy, we need to perform transactions
        // for its underlying target DataSource, else data access code won't see
        // properly exposed transactions (i.e. transactions for the target DataSource).
        this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
    }
    else {
        this.dataSource = dataSource;
    }
}
 
Example 9
Project: spring4-understanding   File: TransactionAwareDataSourceConnectionProvider.java   Source Code and License 5 votes vote down vote up
/**
 * Return a TransactionAwareDataSourceProxy for the given DataSource,
 * provided that it isn't a TransactionAwareDataSourceProxy already.
 */
@Override
protected DataSource getDataSourceToUse(DataSource originalDataSource) {
	if (originalDataSource instanceof TransactionAwareDataSourceProxy) {
		return originalDataSource;
	}
	return new TransactionAwareDataSourceProxy(originalDataSource);
}
 
Example 10
Project: TJWmybatis   File: MySQLSessionFactoryBean.java   Source Code and License 5 votes vote down vote up
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource)
				.getTargetDataSource();
	} else {
		this.dataSource = dataSource;
	}
}
 
Example 11
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: JooqAutoConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(DataSourceConnectionProvider.class)
public DataSourceConnectionProvider dataSourceConnectionProvider(
		DataSource dataSource) {
	return new DataSourceConnectionProvider(
			new TransactionAwareDataSourceProxy(dataSource));
}
 
Example 12
Project: java-persistence-frameworks-comparison   File: DbTestsApplication.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("SpringJavaAutowiringInspection")
@Bean
public DBI jdbiFactory(DataSource dataSource) {
    // note that for JDBI we have to wrap datasource with TransactionAwareDataSourceProxy otherwise JDBI won't respect
    // transactions created by spring
    TransactionAwareDataSourceProxy transactionAwareDataSourceProxy = new TransactionAwareDataSourceProxy(dataSource);
    DBI dbi = new DBI(transactionAwareDataSourceProxy);
    dbi.setSQLLog(new SLF4JLog());  // to enable SLF4J logging
    return dbi;
}
 
Example 13
Project: flowable-engine   File: SpringContentEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public ContentEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return super.setDataSource(proxiedDataSource);
    }
}
 
Example 14
Project: flowable-engine   File: SpringFormEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public FormEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return (FormEngineConfiguration) super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return (FormEngineConfiguration) super.setDataSource(proxiedDataSource);
    }
}
 
Example 15
Project: flowable-engine   File: SpringDmnEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public DmnEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return super.setDataSource(proxiedDataSource);
    }
}
 
Example 16
Project: flowable-engine   File: SpringProcessEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public ProcessEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return super.setDataSource(proxiedDataSource);
    }
}
 
Example 17
Project: flowable-engine   File: SpringCmmnEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public CmmnEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return super.setDataSource(proxiedDataSource);
    }
}
 
Example 18
Project: flowable-engine   File: SpringProcessEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public ProcessEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return super.setDataSource(proxiedDataSource);
    }
}
 
Example 19
Project: flowable-engine   File: SpringIdmEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public IdmEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return (IdmEngineConfiguration) super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return (IdmEngineConfiguration) super.setDataSource(proxiedDataSource);
    }
}
 
Example 20
Project: spring-boot-concourse   File: JooqAutoConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(DataSourceConnectionProvider.class)
public DataSourceConnectionProvider dataSourceConnectionProvider(
		DataSource dataSource) {
	return new DataSourceConnectionProvider(
			new TransactionAwareDataSourceProxy(dataSource));
}
 
Example 21
Project: contestparser   File: JooqAutoConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(DataSourceConnectionProvider.class)
public DataSourceConnectionProvider dataSourceConnectionProvider(
		DataSource dataSource) {
	return new DataSourceConnectionProvider(
			new TransactionAwareDataSourceProxy(dataSource));
}
 
Example 22
Project: SecureBPMN   File: SpringProcessEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public ProcessEngineConfigurationImpl setDataSource(DataSource dataSource) {
  if(dataSource instanceof TransactionAwareDataSourceProxy) {
    return super.setDataSource(dataSource);
  } else {
    // Wrap datasource in Transaction-aware proxy
    DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
    return super.setDataSource(proxiedDataSource);
  }
}
 
Example 23
Project: FoxBPM   File: ProcessEngineConfigurationSpring.java   Source Code and License 5 votes vote down vote up
public ProcessEngineConfiguration setDataSource(DataSource dataSource) {
  if (dataSource instanceof TransactionAwareDataSourceProxy) {
    return super.setDataSource(dataSource);
  } else {
    DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
    return super.setDataSource(proxiedDataSource);
  }
}
 
Example 24
Project: class-guard   File: TransactionAwareDataSourceConnectionProvider.java   Source Code and License 5 votes vote down vote up
/**
 * Return a TransactionAwareDataSourceProxy for the given DataSource,
 * provided that it isn't a TransactionAwareDataSourceProxy already.
 */
@Override
protected DataSource getDataSourceToUse(DataSource originalDataSource) {
	if (originalDataSource instanceof TransactionAwareDataSourceProxy) {
		return originalDataSource;
	}
	return new TransactionAwareDataSourceProxy(originalDataSource);
}
 
Example 25
Project: spring-doma-junit4-dbunit-sample   File: AppConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public Config domaConfig() {
    return new DomaAbstractConfig() {
        @Override
        public Dialect getDialect() {
            return dialect();
        }

        @Override
        public DataSource getDataSource() {
            return new TransactionAwareDataSourceProxy(dataSource());
        }
    };
}
 
Example 26
Project: score   File: PartitionTemplateWithEmfTest.java   Source Code and License 5 votes vote down vote up
@Bean
DataSource dataSource() {
	BasicDataSource ds = new BasicDataSource();
	ds.setDriverClassName("org.h2.Driver");
	ds.setUrl("jdbc:h2:mem:test");
	ds.setUsername("sa");
	ds.setPassword("sa");
	ds.setDefaultAutoCommit(false);
	return new TransactionAwareDataSourceProxy(ds);
}
 
Example 27
Project: score   File: VersionRepositoryTest.java   Source Code and License 5 votes vote down vote up
@Bean
DataSource dataSource() {
	BasicDataSource ds = new BasicDataSource();
	ds.setDriverClassName("org.h2.Driver");
	ds.setUrl("jdbc:h2:mem:test");
	ds.setUsername("sa");
	ds.setPassword("sa");
	ds.setDefaultAutoCommit(false);
	return new TransactionAwareDataSourceProxy(ds);
}
 
Example 28
Project: score   File: ExecutionQueueRepositoryTest.java   Source Code and License 5 votes vote down vote up
@Bean
DataSource dataSource(){
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.h2.Driver");
    ds.setUrl("jdbc:h2:mem:test");
    ds.setUsername("sa");
    ds.setPassword("sa");
    ds.setDefaultAutoCommit(false);
    return new TransactionAwareDataSourceProxy(ds);
}
 
Example 29
Project: score   File: WorkerNodeServiceTest.java   Source Code and License 5 votes vote down vote up
@Bean
DataSource dataSource() {
	BasicDataSource ds = new BasicDataSource();
	ds.setDriverClassName("org.h2.Driver");
	ds.setUrl("jdbc:h2:mem:test");
	ds.setUsername("sa");
	ds.setPassword("sa");
	ds.setDefaultAutoCommit(false);
	return new TransactionAwareDataSourceProxy(ds);
}
 
Example 30
Project: FiWare-Template-Handler   File: SpringProcessEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public ProcessEngineConfigurationImpl setDataSource(DataSource dataSource) {
  if(dataSource instanceof TransactionAwareDataSourceProxy) {
    return super.setDataSource(dataSource);
  } else {
    // Wrap datasource in Transaction-aware proxy
    DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
    return super.setDataSource(proxiedDataSource);
  }
}
 
Example 31
Project: javaconfig-ftw   File: SpringProcessEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public ProcessEngineConfiguration setDataSource(DataSource dataSource) {
  if(dataSource instanceof TransactionAwareDataSourceProxy) {
    return super.setDataSource(dataSource);
  } else {
    // Wrap datasource in Transaction-aware proxy
    DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
    return super.setDataSource(proxiedDataSource);
  }
}
 
Example 32
Project: javaconfig-ftw   File: DefaultActivitiConfigurer.java   Source Code and License 5 votes vote down vote up
private void setup(ApplicationContext context, DataSource d) {
    this.applicationContext = context;
    Assert.notNull(d, "the dataSource can't be null");
    if (d instanceof TransactionAwareDataSourceProxy) {
        this.dataSource = d;
    } else {
        TransactionAwareDataSourceProxy transactionAwareDataSourceProxy =
                new TransactionAwareDataSourceProxy(d);
        transactionAwareDataSourceProxy.afterPropertiesSet();
        this.dataSource = transactionAwareDataSourceProxy;
    }
    this.platformTransactionManager = new DataSourceTransactionManager(d);
}
 
Example 33
Project: camunda-bpm-platform   File: SpringTransactionsProcessEngineConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public ProcessEngineConfigurationImpl setDataSource(DataSource dataSource) {
  if(dataSource instanceof TransactionAwareDataSourceProxy) {
    return super.setDataSource(dataSource);
  } else {
    // Wrap datasource in Transaction-aware proxy
    DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
    return super.setDataSource(proxiedDataSource);
  }
}
 
Example 34
Project: cmc-claim-store   File: DbConfiguration.java   Source Code and License 4 votes vote down vote up
@Bean
public TransactionAwareDataSourceProxy transactionAwareDataSourceProxy(DataSource dataSource) {
    return new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 35
Project: cmc-claim-store   File: DbConfiguration.java   Source Code and License 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager(TransactionAwareDataSourceProxy dataSource) {
    return new DataSourceTransactionManager(dataSource);
}
 
Example 36
Project: unitils   File: ProfilesModuleSpringApplicationContextIntegrationTest.java   Source Code and License 4 votes vote down vote up
@Test
public void test() {
    Assert.assertTrue(dataSource instanceof TransactionAwareDataSourceProxy);
}
 
Example 37
Project: kc-rice   File: RoleDaoJdbc.java   Source Code and License 4 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 38
Project: kc-rice   File: DocumentSearchDAOJdbcImpl.java   Source Code and License 4 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 39
Project: camunda-bpm-spring-boot-starter   File: DefaultDatasourceConfigurationTest.java   Source Code and License 4 votes vote down vote up
private DataSource getDataSourceFromConfiguration() {
  return ((TransactionAwareDataSourceProxy) configuration.getDataSource()).getTargetDataSource();
}
 
Example 40
Project: rice   File: RoleDaoJdbc.java   Source Code and License 4 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 41
Project: rice   File: DocumentSearchDAOJdbcImpl.java   Source Code and License 4 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 42
Project: mev   File: PresetPersistenceConfiguration.java   Source Code and License 4 votes vote down vote up
@Bean(name="presets-transaction-aware-datasrouce") @Inject
public TransactionAwareDataSourceProxy transactionAwareDataSource(@Named("presets-lazy-connection-datasource") LazyConnectionDataSourceProxy lazyProxy) {
    return new TransactionAwareDataSourceProxy(lazyProxy);
}
 
Example 43
Project: mev   File: PresetPersistenceConfiguration.java   Source Code and License 4 votes vote down vote up
@Bean(name="presets-connection-provider") @Inject
public DataSourceConnectionProvider connectionProvider(@Named("presets-transaction-aware-datasrouce") TransactionAwareDataSourceProxy proxy) {
    return new DataSourceConnectionProvider(proxy);
}
 
Example 44
Project: mev   File: ProbeAnnotationsPersistenceConfiguration.java   Source Code and License 4 votes vote down vote up
@Bean
public TransactionAwareDataSourceProxy transactionAwareDataSource() {
    return new TransactionAwareDataSourceProxy(lazyConnectionDataSource());
}
 
Example 45
Project: kuali_rice   File: RoleDaoOjb.java   Source Code and License 4 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 46
Project: kuali_rice   File: DocumentSearchDAOJdbcImpl.java   Source Code and License 4 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 47
Project: kuali_rice   File: UiDocumentServiceDAOJdbcImpl.java   Source Code and License 4 votes vote down vote up
public void setDataSource(DataSource dataSource) {
    this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
}
 
Example 48
Project: mybatis-plus-mini   File: MybatisSqlSessionFactoryBean.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC {@code DataSource} that this instance should manage transactions for. The {@code DataSource}
 * should match the one used by the {@code SqlSessionFactory}: for example, you could specify the same
 * JNDI DataSource for both.
 * <p>
 * A transactional JDBC {@code Connection} for this {@code DataSource} will be provided to application code
 * accessing this {@code DataSource} directly via {@code DataSourceUtils} or {@code DataSourceTransactionManager}.
 * <p>
 * The {@code DataSource} specified here should be the target {@code DataSource} to manage transactions for, not
 * a {@code TransactionAwareDataSourceProxy}. Only data access code may work with
 * {@code TransactionAwareDataSourceProxy}, while the transaction manager needs to work on the
 * underlying target {@code DataSource}. If there's nevertheless a {@code TransactionAwareDataSourceProxy}
 * passed in, it will be unwrapped to extract its target {@code DataSource}.
 */
public void setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        // If we got a TransactionAwareDataSourceProxy, we need to perform
        // transactions for its underlying target DataSource, else data
        // access code won't see properly exposed transactions (i.e.
        // transactions for the target DataSource).
        this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
    } else {
        this.dataSource = dataSource;
    }
}
 
Example 49
Project: alfresco-core   File: HierarchicalSqlSessionFactoryBean.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC {@code DataSource} that this instance should manage transactions for. The {@code DataSource}
 * should match the one used by the {@code SqlSessionFactory}: for example, you could specify the same
 * JNDI DataSource for both.
 *
 * A transactional JDBC {@code Connection} for this {@code DataSource} will be provided to application code
 * accessing this {@code DataSource} directly via {@code DataSourceUtils} or {@code DataSourceTransactionManager}.
 *
 * The {@code DataSource} specified here should be the target {@code DataSource} to manage transactions for, not
 * a {@code TransactionAwareDataSourceProxy}. Only data access code may work with
 * {@code TransactionAwareDataSourceProxy}, while the transaction manager needs to work on the
 * underlying target {@code DataSource}. If there's nevertheless a {@code TransactionAwareDataSourceProxy}
 * passed in, it will be unwrapped to extract its target {@code DataSource}.
 *
 */
public void setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        // If we got a TransactionAwareDataSourceProxy, we need to perform
        // transactions for its underlying target DataSource, else data
        // access code won't see properly exposed transactions (i.e.
        // transactions for the target DataSource).
        this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
    } else {
        this.dataSource = dataSource;
    }
}
 
Example 50
Project: lams   File: JpaTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
 * The DataSource should match the one used by the JPA EntityManagerFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the EntityManagerFactory uses a known DataSource as connection factory,
 * the DataSource will be autodetected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the JPA EntityManager.
 * <p>Note that you need to use a JPA dialect for a specific JPA implementation
 * to allow for exposing JPA transactions as JDBC transactions.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see EntityManagerFactoryInfo#getDataSource()
 * @see #setJpaDialect
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 51
Project: lams   File: JdoTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
  * The DataSource should match the one used by the JDO PersistenceManagerFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the PersistenceManagerFactory uses a DataSource as connection factory,
 * the DataSource will be autodetected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the JDO PersistenceManager.
 * <p>Note that you need to use a JDO dialect for a specific JDO provider to
 * allow for exposing JDO transactions as JDBC transactions.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see #setAutodetectDataSource
 * @see #setJdoDialect
 * @see javax.jdo.PersistenceManagerFactory#getConnectionFactory
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 52
Project: lams   File: HibernateTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
 * The DataSource should match the one used by the Hibernate SessionFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the SessionFactory was configured with LocalDataSourceConnectionProvider,
 * i.e. by Spring's LocalSessionFactoryBean with a specified "dataSource",
 * the DataSource will be auto-detected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the Hibernate Session.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see #setAutodetectDataSource
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 53
Project: lams   File: HibernateTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
 * The DataSource should match the one used by the Hibernate SessionFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the SessionFactory was configured with LocalDataSourceConnectionProvider,
 * i.e. by Spring's LocalSessionFactoryBean with a specified "dataSource",
 * the DataSource will be auto-detected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the Hibernate Session.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see #setAutodetectDataSource
 * @see LocalDataSourceConnectionProvider
 * @see LocalSessionFactoryBean#setDataSource
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 54
Project: spring4-understanding   File: JpaTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
 * The DataSource should match the one used by the JPA EntityManagerFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the EntityManagerFactory uses a known DataSource as its connection factory,
 * the DataSource will be autodetected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the JPA EntityManager.
 * <p>Note that you need to use a JPA dialect for a specific JPA implementation
 * to allow for exposing JPA transactions as JDBC transactions.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see EntityManagerFactoryInfo#getDataSource()
 * @see #setJpaDialect
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 55
Project: spring4-understanding   File: JdoTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
  * The DataSource should match the one used by the JDO PersistenceManagerFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the PersistenceManagerFactory uses a DataSource as connection factory,
 * the DataSource will be autodetected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the JDO PersistenceManager.
 * <p>Note that you need to use a JDO dialect for a specific JDO provider to
 * allow for exposing JDO transactions as JDBC transactions.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see #setAutodetectDataSource
 * @see #setJdoDialect
 * @see javax.jdo.PersistenceManagerFactory#getConnectionFactory
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 56
Project: spring4-understanding   File: HibernateTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
 * The DataSource should match the one used by the Hibernate SessionFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the SessionFactory was configured with LocalDataSourceConnectionProvider,
 * i.e. by Spring's LocalSessionFactoryBean with a specified "dataSource",
 * the DataSource will be auto-detected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the Hibernate Session.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see #setAutodetectDataSource
 * @see LocalDataSourceConnectionProvider
 * @see LocalSessionFactoryBean#setDataSource
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 57
Project: spring4-understanding   File: HibernateTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
 * The DataSource should match the one used by the Hibernate SessionFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the SessionFactory was configured with LocalDataSourceConnectionProvider,
 * i.e. by Spring's LocalSessionFactoryBean with a specified "dataSource",
 * the DataSource will be auto-detected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the Hibernate Session.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see #setAutodetectDataSource
 * @see TransactionAwareDataSourceProxy
 * @see DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 58
Project: spring4-understanding   File: HibernateTransactionManager.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC DataSource that this instance should manage transactions for.
 * The DataSource should match the one used by the Hibernate SessionFactory:
 * for example, you could specify the same JNDI DataSource for both.
 * <p>If the SessionFactory was configured with LocalDataSourceConnectionProvider,
 * i.e. by Spring's LocalSessionFactoryBean with a specified "dataSource",
 * the DataSource will be auto-detected: You can still explicitly specify the
 * DataSource, but you don't need to in this case.
 * <p>A transactional JDBC Connection for this DataSource will be provided to
 * application code accessing this DataSource directly via DataSourceUtils
 * or JdbcTemplate. The Connection will be taken from the Hibernate Session.
 * <p>The DataSource specified here should be the target DataSource to manage
 * transactions for, not a TransactionAwareDataSourceProxy. Only data access
 * code may work with TransactionAwareDataSourceProxy, while the transaction
 * manager needs to work on the underlying target DataSource. If there's
 * nevertheless a TransactionAwareDataSourceProxy passed in, it will be
 * unwrapped to extract its target DataSource.
 * @see #setAutodetectDataSource
 * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
 * @see org.springframework.jdbc.datasource.DataSourceUtils
 * @see org.springframework.jdbc.core.JdbcTemplate
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
		// for its underlying target DataSource, else data access code won't see
		// properly exposed transactions (i.e. transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
	}
	else {
		this.dataSource = dataSource;
	}
}
 
Example 59
Project: Shop-for-JavaWeb   File: SqlSessionFactoryBean.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC {@code DataSource} that this instance should manage
 * transactions for. The {@code DataSource} should match the one used by the
 * {@code SqlSessionFactory}: for example, you could specify the same JNDI
 * DataSource for both.
 * 
 * A transactional JDBC {@code Connection} for this {@code DataSource} will
 * be provided to application code accessing this {@code DataSource}
 * directly via {@code DataSourceUtils} or
 * {@code DataSourceTransactionManager}.
 * 
 * The {@code DataSource} specified here should be the target
 * {@code DataSource} to manage transactions for, not a
 * {@code TransactionAwareDataSourceProxy}. Only data access code may work
 * with {@code TransactionAwareDataSourceProxy}, while the transaction
 * manager needs to work on the underlying target {@code DataSource}. If
 * there's nevertheless a {@code TransactionAwareDataSourceProxy} passed in,
 * it will be unwrapped to extract its target {@code DataSource}.
 * 
 */
public void setDataSource(DataSource dataSource) {
	if (dataSource instanceof TransactionAwareDataSourceProxy) {
		// If we got a TransactionAwareDataSourceProxy, we need to perform
		// transactions for its underlying target DataSource, else data
		// access code won't see properly exposed transactions (i.e.
		// transactions for the target DataSource).
		this.dataSource = ((TransactionAwareDataSourceProxy) dataSource)
				.getTargetDataSource();
	} else {
		this.dataSource = dataSource;
	}
}
 
Example 60
Project: mybatis-plus   File: MybatisSqlSessionFactoryBean.java   Source Code and License 3 votes vote down vote up
/**
 * Set the JDBC {@code DataSource} that this instance should manage transactions for. The {@code DataSource}
 * should match the one used by the {@code SqlSessionFactory}: for example, you could specify the same
 * JNDI DataSource for both.
 * <p>
 * A transactional JDBC {@code Connection} for this {@code DataSource} will be provided to application code
 * accessing this {@code DataSource} directly via {@code DataSourceUtils} or {@code DataSourceTransactionManager}.
 * <p>
 * The {@code DataSource} specified here should be the target {@code DataSource} to manage transactions for, not
 * a {@code TransactionAwareDataSourceProxy}. Only data access code may work with
 * {@code TransactionAwareDataSourceProxy}, while the transaction manager needs to work on the
 * underlying target {@code DataSource}. If there's nevertheless a {@code TransactionAwareDataSourceProxy}
 * passed in, it will be unwrapped to extract its target {@code DataSource}.
 */
public void setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        // If we got a TransactionAwareDataSourceProxy, we need to perform
        // transactions for its underlying target DataSource, else data
        // access code won't see properly exposed transactions (i.e.
        // transactions for the target DataSource).
        this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
    } else {
        this.dataSource = dataSource;
    }
}