public void switchDataSource ( BoneCPConfig newConfig ) throws SQLException { logger . info ( "Switch to new datasource requested. New Config: " + newConfig ) ; DataSource oldDS = getTargetDataSource ( ) ; if ( ! ( oldDS instanceof BoneCPDataSource ) ) { throw new SQLException ( "Unknown datasource type! Was expecting BoneCPDataSource but received " + oldDS . getClass ( ) + ". Not switching datasource!" ) ; } BoneCPDataSource newDS = new BoneCPDataSource ( newConfig ) ; newDS . getConnection ( ) . close ( ) ; // initialize a connection (+ throw it away) to force the datasource to initialize the pool // force application to start using the new one setTargetDataSource ( newDS ) ; logger . info ( "Shutting down old datasource slowly. Old Config: " + oldDS ) ; // tell the old datasource to terminate. This terminates the pool lazily so existing checked out connections can still be used. ( ( BoneCPDataSource ) oldDS ) . close ( ) ; }
Switch to a new DataSource using the given configuration .