org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy Java Examples

The following examples show how to use org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultConcurrentRequestProcessor.java    From cobarclient with Apache License 2.0 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 #2
Source File: GrailsHibernateTemplate.java    From gorm-hibernate5 with Apache License 2.0 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
Source File: HibernateDatastore.java    From gorm-hibernate5 with Apache License 2.0 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 #4
Source File: SpringIdmEngineConfiguration.java    From flowable-engine with Apache License 2.0 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 #5
Source File: DbTestsApplication.java    From java-persistence-frameworks-comparison with MIT 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 #6
Source File: SpringEventRegistryEngineConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public EventRegistryEngineConfiguration setDataSource(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return (EventRegistryEngineConfiguration) super.setDataSource(dataSource);
    } else {
        // Wrap datasource in Transaction-aware proxy
        DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
        return (EventRegistryEngineConfiguration) super.setDataSource(proxiedDataSource);
    }
}
 
Example #7
Source File: JooqPersistenceModule.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
DataSourceTransactionManager provideDataSourceTransactionManager(
    DataSource dataSource) {
  return new DataSourceTransactionManager(
      new TransactionAwareDataSourceProxy(dataSource));
}
 
Example #8
Source File: SpringFormEngineConfiguration.java    From flowable-engine with Apache License 2.0 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 #9
Source File: SpringDmnEngineConfiguration.java    From flowable-engine with Apache License 2.0 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 #10
Source File: SpringProcessEngineConfiguration.java    From flowable-engine with Apache License 2.0 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 #11
Source File: SpringCmmnEngineConfiguration.java    From flowable-engine with Apache License 2.0 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 #12
Source File: SpringProcessEngineConfiguration.java    From flowable-engine with Apache License 2.0 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 #13
Source File: SpringAppEngineConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public AppEngineConfiguration 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
Source File: SpringContentEngineConfiguration.java    From flowable-engine with Apache License 2.0 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 #15
Source File: ProcessEngineConfigurationSpring.java    From FoxBPM with Apache License 2.0 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 #16
Source File: PartitionTemplateWithEmfTest.java    From score with Apache License 2.0 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 #17
Source File: VersionRepositoryTest.java    From score with Apache License 2.0 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 #18
Source File: ExecutionQueueRepositoryTest.java    From score with Apache License 2.0 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 #19
Source File: WorkerNodeServiceTest.java    From score with Apache License 2.0 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 #20
Source File: SpringTransactionsProcessEngineConfiguration.java    From camunda-bpm-platform with Apache License 2.0 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 #21
Source File: TransactionAwareDataSourceConnectionProvider.java    From lams with GNU General Public License v2.0 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 #22
Source File: SpringProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 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 #23
Source File: SpringProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 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 #24
Source File: TeiidServer.java    From teiid-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Object getConnectionFactory() throws TranslatorException {
    if (this.bean instanceof DataSource) {
        return new TransactionAwareDataSourceProxy((DataSource) bean);
    }
    return bean;
}
 
Example #25
Source File: DataSourceTransactionManagerFactory.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource onCreated(BeanCreatedEvent<DataSource> event) {
    DataSource dataSource = event.getBean();
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return dataSource;
    } else {
        return new TransactionAwareDataSourceProxy(dataSource);
    }
}
 
Example #26
Source File: UserDataSources.java    From secrets-proxy with Apache License 2.0 5 votes vote down vote up
private DSLContext getDslContext(PlatformTransactionManager txManager, DataSource dataSource) {
  DefaultConfiguration config = new DefaultConfiguration();
  config.set(new DataSourceConnectionProvider(new TransactionAwareDataSourceProxy(dataSource)));
  config.set(new DefaultExecuteListenerProvider(new JooqExceptionTranslator()));
  config.set(new SpringTransactionProvider(txManager));
  return new DefaultDSLContext(config);
}
 
Example #27
Source File: SpringRiderTestContext.java    From database-rider with Apache License 2.0 5 votes vote down vote up
private static DataSource wrapInTransactionAwareProxy(DataSource dataSource) {
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return dataSource;
    } else {
        return new TransactionAwareDataSourceProxy(dataSource);
    }
}
 
Example #28
Source File: TransactionAwareDataSourceConnectionProvider.java    From spring4-understanding with Apache License 2.0 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 #29
Source File: Application.java    From blog-examples with Apache License 2.0 4 votes vote down vote up
@Bean
public TransactionAwareDataSourceProxy transactionAwareDataSource() {
	return new TransactionAwareDataSourceProxy(dataSource());
}
 
Example #30
Source File: SqlSessionFactoryBean.java    From gocd with Apache License 2.0 4 votes vote down vote up
@Autowired
public SqlSessionFactoryBean(DataSource dataSource, @Value("classpath:/sql-map-config.xml") Resource configLocation) {
    this.dataSource = dataSource instanceof TransactionAwareDataSourceProxy ? dataSource : new TransactionAwareDataSourceProxy(dataSource);
    this.configLocation = configLocation;
}