com.jolbox.bonecp.spring
Class DynamicDataSourceProxy

java.lang.Object
  extended by org.springframework.jdbc.datasource.DelegatingDataSource
      extended by com.jolbox.bonecp.spring.DynamicDataSourceProxy
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource, org.springframework.beans.factory.InitializingBean

public class DynamicDataSourceProxy
extends org.springframework.jdbc.datasource.DelegatingDataSource

Like a normal datasource except it supports an extra method: switchDataSource to slowly migrate to a new datasource. Simply call switchDataSource with your new BoneCP configuration: the existing pool will be shutdown gracefully (checkout out connections are unaffected) and a new one will take it's place. A typical use case would be to transparently instruct your application to use a new database without restarting the application.

Author:
Wallace

Constructor Summary
DynamicDataSourceProxy()
          Default constructor.
DynamicDataSourceProxy(DataSource targetDataSource)
          Create a new DynamicDataSourceProxy.
 
Method Summary
 void switchDataSource(BoneCPConfig newConfig)
          Switch to a new DataSource using the given configuration.
 
Methods inherited from class org.springframework.jdbc.datasource.DelegatingDataSource
afterPropertiesSet, getConnection, getConnection, getLoginTimeout, getLogWriter, getTargetDataSource, isWrapperFor, setLoginTimeout, setLogWriter, setTargetDataSource, unwrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicDataSourceProxy

public DynamicDataSourceProxy(DataSource targetDataSource)
Create a new DynamicDataSourceProxy.

Parameters:
targetDataSource - the target DataSource

DynamicDataSourceProxy

public DynamicDataSourceProxy()
Default constructor.

Method Detail

switchDataSource

public void switchDataSource(BoneCPConfig newConfig)
                      throws SQLException
Switch to a new DataSource using the given configuration.

Parameters:
newConfig - BoneCP DataSource to use.
Throws:
SQLException


Copyright © 2009-2011 JolBox. All Rights Reserved.