ShardingResultMergerEngine implements ResultMergerEngine<ShardingRule> { @Override public ResultMerger newInstance(final DatabaseType databaseType, final ShardingRule shardingRule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext) { if (sqlStatementContext instanceof SelectStatementContext) { return new ShardingDQLResultMerger(databaseType); } if (sqlStatementContext.getSqlStatement() instanceof DALStatement) { return new ShardingDALResultMerger(shardingRule); } return new TransparentResultMerger(); }  @Override ResultMerger newInstance(final DatabaseType databaseType, final ShardingRule shardingRule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext); @Override int getOrder(); @Override Class<ShardingRule> getTypeClass();  }
@Test public void assertNewInstanceWithDALStatement() { ConfigurationProperties props = new ConfigurationProperties(new Properties()); CommonSQLStatementContext<PostgreSQLShowStatement> sqlStatementContext = new CommonSQLStatementContext<>(new PostgreSQLShowStatement()); assertThat(new ShardingResultMergerEngine().newInstance(DatabaseTypes.getActualDatabaseType("MySQL"), null, props, sqlStatementContext), instanceOf(ShardingDALResultMerger.class)); }
@Test public void assertNewInstanceWithOtherStatement() { InsertStatement insertStatement = new MySQLInsertStatement(); InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0, Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("col")))); insertStatement.setTable(new SimpleTableSegment(0, 0, new IdentifierValue("tbl"))); insertStatement.setInsertColumns(insertColumnsSegment); InsertStatementContext sqlStatementContext = new InsertStatementContext(mock(SchemaMetaData.class), Collections.emptyList(), insertStatement); ConfigurationProperties props = new ConfigurationProperties(new Properties()); assertThat(new ShardingResultMergerEngine().newInstance(DatabaseTypes.getActualDatabaseType("MySQL"), null, props, sqlStatementContext), instanceOf(TransparentResultMerger.class)); }