@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); } } }
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; } }
/** * 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); } }
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; }
/** * 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); }
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; } }
public void setDataSource(DataSource dataSource) { if (dataSource instanceof TransactionAwareDataSourceProxy) { this.dataSource = ((TransactionAwareDataSourceProxy) dataSource) .getTargetDataSource(); } else { this.dataSource = dataSource; } }
@Bean @ConditionalOnMissingBean(DataSourceConnectionProvider.class) public DataSourceConnectionProvider dataSourceConnectionProvider( DataSource dataSource) { return new DataSourceConnectionProvider( new TransactionAwareDataSourceProxy(dataSource)); }
@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; }
@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); } }
@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); } }
@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); } }
@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); } }
@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); } }
@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); } }
@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); } }
public ProcessEngineConfiguration setDataSource(DataSource dataSource) { if (dataSource instanceof TransactionAwareDataSourceProxy) { return super.setDataSource(dataSource); } else { DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource); return super.setDataSource(proxiedDataSource); } }
@Bean public Config domaConfig() { return new DomaAbstractConfig() { @Override public Dialect getDialect() { return dialect(); } @Override public DataSource getDataSource() { return new TransactionAwareDataSourceProxy(dataSource()); } }; }
@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); }
@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); }
@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); } }
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); }
@Bean public TransactionAwareDataSourceProxy transactionAwareDataSourceProxy(DataSource dataSource) { return new TransactionAwareDataSourceProxy(dataSource); }
@Bean public PlatformTransactionManager transactionManager(TransactionAwareDataSourceProxy dataSource) { return new DataSourceTransactionManager(dataSource); }
@Test public void test() { Assert.assertTrue(dataSource instanceof TransactionAwareDataSourceProxy); }
public void setDataSource(DataSource dataSource) { this.dataSource = new TransactionAwareDataSourceProxy(dataSource); }
private DataSource getDataSourceFromConfiguration() { return ((TransactionAwareDataSourceProxy) configuration.getDataSource()).getTargetDataSource(); }