public DatabaseAccessConfiguration swap ( final DataSource dataSource ) { DataSourcePropertyProvider provider = DataSourcePropertyProviderLoader . getProvider ( dataSource ) ; try { String url = ( String ) findGetterMethod ( dataSource , provider . getURLPropertyName ( ) ) . invoke ( dataSource ) ; String username = ( String ) findGetterMethod ( dataSource , provider . getUsernamePropertyName ( ) ) . invoke ( dataSource ) ; String password = ( String ) findGetterMethod ( dataSource , provider . getPasswordPropertyName ( ) ) . invoke ( dataSource ) ; return new DatabaseAccessConfiguration ( url , username , password ) ; } catch ( final ReflectiveOperationException ex ) { throw new ShardingException ( "Cannot swap data source type: `%s`, please provide an implementation from SPI `%s`" , dataSource . getClass ( ) . getName ( ) , DataSourcePropertyProvider . class . getName ( ) ) ; } }
Swap data source to database access configuration .