UnicastBackendHandler implements TextProtocolBackendHandler { @Override public BackendResponse execute() throws SQLException { if (null == backendConnection.getSchemaName()) { Map<String, ShardingSphereSchema> schemas = ProxyContext.getInstance().getSchemaContexts().getSchemas(); if (schemas.isEmpty()) { throw new NoDatabaseSelectedException(); } if (!schemas.values().iterator().next().isComplete()) { throw new RuleNotExistsException(); } backendConnection.setCurrentSchema(schemas.keySet().iterator().next()); } databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatement, sql, backendConnection); return databaseCommunicationEngine.execute(); }  @Override BackendResponse execute(); @Override boolean next(); @Override QueryData getQueryData();  }
@Test public void assertExecuteWhileSchemaIsNull() throws SQLException { UnicastBackendHandler backendHandler = new UnicastBackendHandler("show variable like %s", mock(SQLStatement.class), backendConnection); backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 8)); setDatabaseCommunicationEngine(backendHandler); BackendResponse actual = backendHandler.execute(); assertThat(actual, instanceOf(UpdateResponse.class)); backendHandler.execute(); }
@Test public void assertExecuteWhileSchemaNotNull() throws SQLException { backendConnection.setCurrentSchema(String.format(SCHEMA_PATTERN, 0)); UnicastBackendHandler backendHandler = new UnicastBackendHandler("show variable like %s", mock(SQLStatement.class), backendConnection); setDatabaseCommunicationEngine(backendHandler); BackendResponse actual = backendHandler.execute(); assertThat(actual, instanceOf(UpdateResponse.class)); backendHandler.execute(); }