private static IShardingRouteEngine GetDALRoutingEngine(ShardingRule shardingRule, ISqlCommand sqlCommand, ICollection <String> tableNames) { if (sqlCommand is UseCommand) { return(new ShardingIgnoreRoutingEngine()); } if (sqlCommand is SetCommand || sqlCommand is ResetParameterCommand || sqlCommand is ShowDatabasesCommand) { return(new ShardingDatabaseBroadcastRoutingEngine()); } if (tableNames.Any() && !shardingRule.TableRuleExists(tableNames) && shardingRule.HasDefaultDataSourceName()) { return(new ShardingDefaultDatabaseRoutingEngine(tableNames)); } if (tableNames.Any()) { return(new ShardingUnicastRoutingEngine(tableNames)); } return(new ShardingDataSourceGroupBroadcastRoutingEngine()); }
public static IShardingRouteEngine NewInstance(ShardingRule shardingRule, ShardingConnectorMetaData metaData, ISqlCommandContext <ISqlCommand> sqlCommandContext, ShardingConditions shardingConditions, ConfigurationProperties properties) { var sqlStatement = sqlCommandContext.GetSqlCommand(); ICollection <String> tableNames = sqlCommandContext.GetTablesContext().GetTableNames(); if (sqlStatement is TCLCommand) { return(new ShardingDatabaseBroadcastRoutingEngine()); } if (sqlStatement is DDLCommand) { return(new ShardingTableBroadcastRoutingEngine(metaData.Schema, sqlCommandContext)); } if (sqlStatement is DALCommand) { return(GetDALRoutingEngine(shardingRule, sqlStatement, tableNames)); } if (sqlStatement is DCLCommand) { return(GetDCLRoutingEngine(sqlCommandContext, metaData)); } if (shardingRule.IsAllInDefaultDataSource(tableNames)) { return(new ShardingDefaultDatabaseRoutingEngine(tableNames)); } if (shardingRule.IsAllBroadcastTables(tableNames)) { if (sqlStatement is SelectCommand) { return(new ShardingUnicastRoutingEngine(tableNames)); } return(new ShardingDatabaseBroadcastRoutingEngine()); } if (sqlCommandContext.GetSqlCommand() is DMLCommand && tableNames.IsEmpty() && shardingRule.HasDefaultDataSourceName()) { return(new ShardingDefaultDatabaseRoutingEngine(tableNames)); } if (sqlCommandContext.GetSqlCommand() is DMLCommand && shardingConditions.IsAlwaysFalse() || tableNames.IsEmpty() || !shardingRule.TableRuleExists(tableNames)) { return(new ShardingUnicastRoutingEngine(tableNames)); } return(GetShardingRoutingEngine(shardingRule, sqlCommandContext, shardingConditions, tableNames, properties)); }