final DataSource dsToUse = (lazyConnection ? new LazyConnectionDataSourceProxy(ds) : ds); tm = new DataSourceTransactionManager(dsToUse); TransactionTemplate tt = new TransactionTemplate(tm);
final DataSource dsToUse = (lazyConnection ? new LazyConnectionDataSourceProxy(ds) : ds); tm = new DataSourceTransactionManager(dsToUse); TransactionTemplate tt = new TransactionTemplate(tm);
/** * Primary data source. * * @return the primary data source */ @Bean @Primary public DataSource dataSource() throws SQLException { DataSource dataSourceTarget = new HikariDataSource(getHikariConfig()); return new LazyConnectionDataSourceProxy(dataSourceTarget); }
@Override protected LazyConnectionDataSourceProxy createDataSource(Properties props) throws Exception { return new LazyConnectionDataSourceProxy(createBoneCPDataSource(props)); }
@Override protected LazyConnectionDataSourceProxy createDataSource(Properties props) { return new LazyConnectionDataSourceProxy(createViburDataSource(props)); }
public ReplicationRoutingDataSource(DataSource master, List<DataSource> slaves) { Assert.notNull(master, "master datasource can not be null."); Map<Object, Object> targetDataSources = new HashMap<>(); targetDataSources.put(MASTER_KEY, new LazyConnectionDataSourceProxy(master)); if (!CollectionUtils.isEmpty(slaves)) { slaveSize = slaves.size(); for (int i = 0; i < slaveSize; i++) { targetDataSources.put(SLAVE_PREFIX + i, new LazyConnectionDataSourceProxy(slaves.get(i))); } } else { this.onlyMaster = true; } setTargetDataSources(targetDataSources); setDefaultTargetDataSource(targetDataSources.get(MASTER_KEY)); }
@Override public void afterPropertiesSet() throws Exception { if (this.shardsDataSources == null) { throw new IllegalArgumentException("Property 'shardsDataSources' is required"); } this.resolvedShardsDataSources = new HashMap<Object, DataSource>(this.shardsDataSources.size()); for (Map.Entry<Object, Object> entry : this.shardsDataSources.entrySet()) { DataSource dataSource = resolveSpecifiedDataSource(entry.getValue()); LazyConnectionDataSourceProxy lazyDataSourceProxy = new LazyConnectionDataSourceProxy(); lazyDataSourceProxy.setTargetDataSource(dataSource); this.resolvedShardsDataSources.put(entry.getKey(), lazyDataSourceProxy); } if (this.defaultDataSource == null) { throw new IllegalArgumentException("Property 'defaultDataSource' is required"); } if(this.defaultDataSource != null){ resolvedDefaultDataSource = this.resolveSpecifiedDataSource(defaultDataSource); } }
@Bean public DataSource dataSource() { DataSource mainDataSource = mainDataSource(); if (multipleDataSource) { Map<Object, Object> targetDataSources = new HashMap<>(); targetDataSources.put("main", mainDataSource); ThreadLocalDynamicDataSource dynamicDataSource = new ThreadLocalDynamicDataSource(); dynamicDataSource.setTargetDataSources(targetDataSources); dynamicDataSource.setDefaultTargetDataSource(mainDataSource); return dynamicDataSource; } return new LazyConnectionDataSourceProxy(mainDataSource); }
protected DataSource proxy(DataSource dataSource, DataSourceSettings settings) { if(settings.isLazy()) { dataSource = new LazyConnectionDataSourceProxy(dataSource); } if(settings.isTransactionAware()) { dataSource = new TransactionAwareDataSourceProxy(dataSource); } return dataSource; }
return new LazyConnectionDataSourceProxy(dataSource);
return new LazyConnectionDataSourceProxy(dataSource);
return new LazyConnectionDataSourceProxy(source());
public void afterPropertiesSet() throws Exception { if (getHaDataSourceCreator() == null) { setHaDataSourceCreator(new NonHADataSourceCreator()); } if (CollectionUtils.isEmpty(dataSourceDescriptors)) { return; } for (CobarDataSourceDescriptor descriptor : getDataSourceDescriptors()) { Validate.notEmpty(descriptor.getIdentity()); Validate.notNull(descriptor.getTargetDataSource()); DataSource dataSourceToUse = descriptor.getTargetDataSource(); if (descriptor.getStandbyDataSource() != null) { dataSourceToUse = getHaDataSourceCreator().createHADataSource(descriptor); if (CollectionUtils.isNotEmpty(dataSourcePostProcessor)) { for (IDataSourcePostProcessor pp : dataSourcePostProcessor) { dataSourceToUse = pp.postProcess(dataSourceToUse); } } } dataSources.put(descriptor.getIdentity(), new LazyConnectionDataSourceProxy( dataSourceToUse)); } }