baozhalelele commented on issue #21492:
URL:
https://github.com/apache/shardingsphere/issues/21492#issuecomment-1274693328
Thank you for your kindly answer.
Finally, I used reflection to update the `ContextManager` and it seemed to
work.
For referenceļ¼
```
ShardingSphereDataSource shardingSphereDataSource =
(ShardingSphereDataSource) dataSource;
Class<ShardingSphereDataSource> shardingSphereDataSourceClass =
ShardingSphereDataSource.class;
Field field =
shardingSphereDataSourceClass.getDeclaredField("contextManager");
field.setAccessible(true);
ContextManager contextManager = (ContextManager)
field.get(shardingSphereDataSource);
HikariDataSource newHikariDataSource = new HikariDataSource();
newHikariDataSource.setDriverClassName(tenantDataSource.getDriverClassName());
// ....
Map<String, DataSource> dataSourceMap =
contextManager.getDataSourceMap(SHARDING_LOGIC_SCHEMA);
dataSourceMap.put(tenantInfo.getTenantName(), newHikariDataSource);
ShardingSphereResource newResource = new
ShardingSphereResource(dataSourceMap);
ShardingSphereDatabase shardingSphereDatabase =
contextManager.getMetaDataContexts().getMetaData().getDatabases().get(SHARDING_LOGIC_SCHEMA);
Class<ShardingSphereDatabase> shardingSphereDatabaseClass =
ShardingSphereDatabase.class;
Field resource = shardingSphereDatabaseClass.getDeclaredField("resource");
resource.setAccessible(true);
resource.set(shardingSphereDatabase, newResource);
field.set(shardingSphereDataSource, contextManager);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]