public static RoutingEngine newInstance ( final ShardingRule shardingRule , final ShardingDataSourceMetaData shardingDataSourceMetaData , final SQLStatement sqlStatement , final OptimizeResult optimizeResult ) { Collection < String > tableNames = sqlStatement . getTables ( ) . getTableNames ( ) ; if ( SQLType . TCL == sqlStatement . getType ( ) ) { return new DatabaseBroadcastRoutingEngine ( shardingRule ) ; } if ( SQLType . DDL == sqlStatement . getType ( ) ) { return new TableBroadcastRoutingEngine ( shardingRule , sqlStatement ) ; } if ( SQLType . DAL == sqlStatement . getType ( ) ) { return getDALRoutingEngine ( shardingRule , sqlStatement , tableNames ) ; } if ( SQLType . DCL == sqlStatement . getType ( ) ) { return getDCLRoutingEngine ( shardingRule , sqlStatement , shardingDataSourceMetaData ) ; } if ( shardingRule . isAllInDefaultDataSource ( tableNames ) ) { return new DefaultDatabaseRoutingEngine ( shardingRule , tableNames ) ; } if ( shardingRule . isAllBroadcastTables ( tableNames ) ) { return SQLType . DQL == sqlStatement . getType ( ) ? new UnicastRoutingEngine ( shardingRule , tableNames ) : new DatabaseBroadcastRoutingEngine ( shardingRule ) ; } if ( optimizeResult . getShardingConditions ( ) . isAlwaysFalse ( ) || tableNames . isEmpty ( ) ) { return new UnicastRoutingEngine ( shardingRule , tableNames ) ; } Collection < String > shardingTableNames = shardingRule . getShardingLogicTableNames ( tableNames ) ; if ( 1 == shardingTableNames . size ( ) || shardingRule . isAllBindingTables ( shardingTableNames ) ) { return new StandardRoutingEngine ( sqlStatement , shardingRule , shardingTableNames . iterator ( ) . next ( ) , optimizeResult ) ; } // TODO config for cartesian set return new ComplexRoutingEngine ( sqlStatement , shardingRule , tableNames , optimizeResult ) ; }
Create new instance of routing engine .