HintCommandExecutorFactory { public static HintCommandExecutor newInstance(final HintCommand hintCommand, final BackendConnection backendConnection, final String sql) { if (hintCommand instanceof HintSetPrimaryOnlyCommand) { return new HintSetPrimaryOnlyExecutor(); } if (hintCommand instanceof HintSetDatabaseShardingValueCommand) { return new HintSetDatabaseShardingValueExecutor(); } if (hintCommand instanceof HintAddDatabaseShardingValueCommand) { return new HintAddDatabaseShardingValueExecutor(); } if (hintCommand instanceof HintAddTableShardingValueCommand) { return new HintAddTableShardingValueExecutor(); } if (hintCommand instanceof HintClearCommand) { return new HintClearExecutor(); } if (hintCommand instanceof HintShowStatusCommand) { return new HintShowStatusExecutor(); } if (hintCommand instanceof HintShowTableStatusCommand) { return new HintShowTableStatusExecutor(backendConnection); } return new HintErrorParameterExecutor(sql); }  static HintCommandExecutor newInstance(final HintCommand hintCommand, final BackendConnection backendConnection, final String sql);  }
@Test public void assertHintSetPrimaryOnlyExecutor() { String sql = "sctl:hint set primary_only=false"; HintCommand hintCommand = mock(HintSetPrimaryOnlyCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintSetPrimaryOnlyExecutor.class)); }
@Test public void assertHintSetDatabaseShardingValueExecutor() { String sql = "sctl:hint set DatabaseShardingValue=100"; HintCommand hintCommand = mock(HintSetDatabaseShardingValueCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintSetDatabaseShardingValueExecutor.class)); }
@Test public void assertHintAddDatabaseShardingValueExecutor() { String sql = "sctl:hint addDatabaseShardingValue user=100"; HintCommand hintCommand = mock(HintAddDatabaseShardingValueCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintAddDatabaseShardingValueExecutor.class)); }
@Test public void assertHintAddTableShardingValueExecutor() { String sql = "sctl:hint addTableShardingValue user=100"; HintCommand hintCommand = mock(HintAddTableShardingValueCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintAddTableShardingValueExecutor.class)); }
@Test public void assertHintClearExecutor() { String sql = "sctl:hint clear "; HintCommand hintCommand = mock(HintClearCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintClearExecutor.class)); }
@Test public void assertHintShowStatusExecutor() { String sql = "sctl:hint show status "; HintCommand hintCommand = mock(HintShowStatusCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintShowStatusExecutor.class)); }
@Test public void assertHintShowTableStatusExecutor() { String sql = "sctl:hint show table status "; HintCommand hintCommand = mock(HintShowTableStatusCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintShowTableStatusExecutor.class)); }
@Test public void assertHintErrorParameterExecutor() { String sql = "sctl:hint bad parameters "; HintCommand hintCommand = mock(HintErrorParameterCommand.class); assertThat(HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql), instanceOf(HintErrorParameterExecutor.class)); }