zdmwww commented on issue #3119: HintManager Of Version 4.0.0.RC2 Can‘t Work Under Multi DataSource Scenes URL: https://github.com/apache/incubator-shardingsphere/issues/3119#issuecomment-535466780 from the source code, In version 3.1.0, ShardingPreparedStatement.getResultSet() has the code: ``` if (this.routeResult.getSqlStatement() instanceof **SelectStatement** || this.routeResult.getSqlStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance(this.connection.getShardingContext().getDatabaseType(), this.connection.getShardingContext().getShardingRule(), this.routeResult.getSqlStatement(), this.connection.getShardingContext().getMetaData().getTable(), queryResults); this.currentResultSet = new ShardingResultSet(resultSets, mergeEngine.merge(), this); } ``` But in version 4.0.0-RC2, the code is like this: ``` if (this.sqlRouteResult.getOptimizedStatement() instanceof **ShardingSelectOptimizedStatement** || this.sqlRouteResult.getOptimizedStatement().getSQLStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance(this.connection.getRuntimeContext().getDatabaseType(), (ShardingRule)this.connection.getRuntimeContext().getRule(), this.sqlRouteResult, this.connection.getRuntimeContext().getMetaData().getTable(), queryResults); this.currentResultSet = this.getCurrentResultSet(resultSets, mergeEngine); } ``` ShardingSelectOptimizedStatement in 4.0.0-RC2 is different from SelectStatement In version 3.1.0, May be this is problem. In version 4.0.0-RC2, The ShardingRouterFactory is Like this: ``` public final class ShardingRouterFactory { public static ShardingRouter newInstance(ShardingRule shardingRule, ShardingMetaData shardingMetaData, DatabaseType databaseType, boolean showSQL) { return (ShardingRouter)(HintManagerHolder.isDatabaseShardingOnly() ? new DatabaseHintSQLRouter(shardingRule, showSQL) : new ParsingSQLRouter(shardingRule, shardingMetaData, databaseType, showSQL)); } private ShardingRouterFactory() { } } ``` When use the HintManager set shardingvalue, the isDatabaseShardingOnly has been set to true, So will create DatabaseHintSQLRouter and the sqlStatement is TransparentOptimizedStatement ,So the result can't be merged ,So HintManger can't support multi datasource In version 4.0.0-RC2。 DatabaseHintSQLRouter.Java: ``` public SQLRouteResult route(String logicSQL, List<Object> parameters, SQLStatement sqlStatement) { SQLRouteResult result = new SQLRouteResult(new **TransparentOptimizedStatement**(sqlStatement)); RoutingResult routingResult = (new DatabaseHintRoutingEngine(this.shardingRule.getShardingDataSourceNames().getDataSourceNames(), (HintShardingStrategy)this.shardingRule.getDefaultDatabaseShardingStrategy())).route(); result.setRoutingResult(routingResult); return result; } ```
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
