ShardingDALResultMerger implements ResultMerger { @Override public MergedResult merge(final List<QueryResult> queryResults, final SQLStatementContext<?> sqlStatementContext, final SchemaMetaData schemaMetaData) throws SQLException { SQLStatement dalStatement = sqlStatementContext.getSqlStatement(); if (dalStatement instanceof MySQLShowDatabasesStatement) { return new SingleLocalDataMergedResult(Collections.singletonList(DefaultSchema.LOGIC_NAME)); } if (dalStatement instanceof MySQLShowTablesStatement || dalStatement instanceof MySQLShowTableStatusStatement || dalStatement instanceof MySQLShowIndexStatement) { return new LogicTablesMergedResult(shardingRule, sqlStatementContext, schemaMetaData, queryResults); } if (dalStatement instanceof MySQLShowCreateTableStatement) { return new ShowCreateTableMergedResult(shardingRule, sqlStatementContext, schemaMetaData, queryResults); } return new TransparentMergedResult(queryResults.get(0)); }  @Override MergedResult merge(final List<QueryResult> queryResults, final SQLStatementContext<?> sqlStatementContext, final SchemaMetaData schemaMetaData);  }
@Test public void assertMergeForShowDatabasesStatement() throws SQLException { DALStatement dalStatement = new MySQLShowDatabasesStatement(); SQLStatementContext<?> sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(null); assertThat(resultMerger.merge(queryResults, sqlStatementContext, null), instanceOf(SingleLocalDataMergedResult.class)); }
@Test public void assertMergeForShowShowTablesStatement() throws SQLException { DALStatement dalStatement = new MySQLShowTablesStatement(); SQLStatementContext<?> sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(null); assertThat(resultMerger.merge(queryResults, sqlStatementContext, null), instanceOf(LogicTablesMergedResult.class)); }
@Test public void assertMergeForShowCreateTableStatement() throws SQLException { DALStatement dalStatement = new MySQLShowCreateTableStatement(); SQLStatementContext<?> sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(null); assertThat(resultMerger.merge(queryResults, sqlStatementContext, null), instanceOf(ShowCreateTableMergedResult.class)); }
@Test public void assertMergeForShowOtherStatement() throws SQLException { DALStatement dalStatement = new MySQLShowOtherStatement(); SQLStatementContext<?> sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(null); assertThat(resultMerger.merge(queryResults, sqlStatementContext, null), instanceOf(TransparentMergedResult.class)); }
@Test public void assertMergeForDescribeStatement() throws SQLException { DALStatement dalStatement = new MySQLDescribeStatement(); SQLStatementContext<?> sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(mock(ShardingRule.class)); assertThat(resultMerger.merge(queryResults, sqlStatementContext, null), instanceOf(TransparentMergedResult.class)); }