未验证 提交 4b144e3e 编写于 作者: J Juan Pan(Trista) 提交者: GitHub

Add gitignore and optimize proxy backend interface. (#6618)

* Add gitignore and optimize proxy backend interface.

* remove gen
上级 41ab41dd
......@@ -54,12 +54,12 @@ public final class DatabaseCommunicationEngineFactory {
/**
* Create new instance of text protocol backend handler.
*
* @param schema ShardingSphere schema
* @param sql SQL to be executed
* @param backendConnection backend connection
* @return instance of text protocol backend handler
*/
public DatabaseCommunicationEngine newTextProtocolInstance(final SchemaContext schema, final String sql, final BackendConnection backendConnection) {
public DatabaseCommunicationEngine newTextProtocolInstance(final String sql, final BackendConnection backendConnection) {
SchemaContext schema = backendConnection.getSchema();
SQLStatement sqlStatement = schema.getRuntimeContext().getSqlParserEngine().parse(sql, false);
return new JDBCDatabaseCommunicationEngine(sql, backendConnection, createSQLExecuteEngine(schema, sqlStatement, backendConnection, new StatementExecutorWrapper(schema, sqlStatement)));
}
......@@ -67,13 +67,13 @@ public final class DatabaseCommunicationEngineFactory {
/**
* Create new instance of text protocol backend handler.
*
* @param schema ShardingSphere schema
* @param sql SQL to be executed
* @param parameters SQL parameters
* @param backendConnection backend connection
* @return instance of text protocol backend handler
*/
public DatabaseCommunicationEngine newBinaryProtocolInstance(final SchemaContext schema, final String sql, final List<Object> parameters, final BackendConnection backendConnection) {
public DatabaseCommunicationEngine newBinaryProtocolInstance(final String sql, final List<Object> parameters, final BackendConnection backendConnection) {
SchemaContext schema = backendConnection.getSchema();
SQLStatement sqlStatement = schema.getRuntimeContext().getSqlParserEngine().parse(sql, true);
return new JDBCDatabaseCommunicationEngine(sql,
backendConnection, createSQLExecuteEngine(schema, sqlStatement, backendConnection, new PreparedStatementExecutorWrapper(schema, sqlStatement, parameters)));
......
......@@ -48,7 +48,7 @@ public final class BroadcastBackendHandler implements TextProtocolBackendHandler
String originalSchema = backendConnection.getSchema().getName();
for (String each : ProxySchemaContexts.getInstance().getSchemaNames()) {
backendConnection.setCurrentSchema(each);
responses.add(databaseCommunicationEngineFactory.newTextProtocolInstance(ProxySchemaContexts.getInstance().getSchema(each), sql, backendConnection).execute());
responses.add(databaseCommunicationEngineFactory.newTextProtocolInstance(sql, backendConnection).execute());
}
backendConnection.setCurrentSchema(originalSchema);
for (BackendResponse each : responses) {
......
......@@ -49,7 +49,7 @@ public final class UnicastBackendHandler implements TextProtocolBackendHandler {
if (null == backendConnection.getSchema()) {
return new ErrorResponse(new NoDatabaseSelectedException());
}
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(backendConnection.getSchema(), sql, backendConnection);
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sql, backendConnection);
return databaseCommunicationEngine.execute();
}
......
......@@ -48,7 +48,7 @@ public final class QueryBackendHandler implements TextProtocolBackendHandler {
if (null == backendConnection.getSchema()) {
return new ErrorResponse(new NoDatabaseSelectedException());
}
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(backendConnection.getSchema(), sql, backendConnection);
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sql, backendConnection);
return databaseCommunicationEngine.execute();
}
......
......@@ -57,15 +57,18 @@ public final class DatabaseCommunicationEngineFactoryTest {
@Test
public void assertNewTextProtocolInstance() {
DatabaseCommunicationEngine engine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(schemaContext, "schemaName", mock(BackendConnection.class));
BackendConnection backendConnection = mock(BackendConnection.class);
when(backendConnection.getSchema()).thenReturn(schemaContext);
DatabaseCommunicationEngine engine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance("schemaName", backendConnection);
assertNotNull(engine);
assertThat(engine, instanceOf(JDBCDatabaseCommunicationEngine.class));
}
@Test
public void assertNewBinaryProtocolInstance() {
DatabaseCommunicationEngine engine = DatabaseCommunicationEngineFactory.getInstance()
.newBinaryProtocolInstance(schemaContext, "schemaName", Collections.emptyList(), mock(BackendConnection.class));
BackendConnection backendConnection = mock(BackendConnection.class);
when(backendConnection.getSchema()).thenReturn(schemaContext);
DatabaseCommunicationEngine engine = DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance("schemaName", Collections.emptyList(), backendConnection);
assertNotNull(engine);
assertThat(engine, instanceOf(JDBCDatabaseCommunicationEngine.class));
}
......
......@@ -104,7 +104,7 @@ public final class BroadcastBackendHandlerTest {
private void mockDatabaseCommunicationEngine(final BackendResponse backendResponse) {
when(databaseCommunicationEngine.execute()).thenReturn(backendResponse);
when(databaseCommunicationEngineFactory.newTextProtocolInstance(any(), anyString(), any())).thenReturn(databaseCommunicationEngine);
when(databaseCommunicationEngineFactory.newTextProtocolInstance(anyString(), any())).thenReturn(databaseCommunicationEngine);
}
@SneakyThrows(ReflectiveOperationException.class)
......
......@@ -97,7 +97,7 @@ public final class UnicastBackendHandlerTest {
private void setUnderlyingHandler(final BackendResponse backendResponse) {
DatabaseCommunicationEngine databaseCommunicationEngine = mock(DatabaseCommunicationEngine.class);
when(databaseCommunicationEngine.execute()).thenReturn(backendResponse);
when(databaseCommunicationEngineFactory.newTextProtocolInstance(any(), anyString(), any())).thenReturn(databaseCommunicationEngine);
when(databaseCommunicationEngineFactory.newTextProtocolInstance(anyString(), any())).thenReturn(databaseCommunicationEngine);
}
@SneakyThrows(ReflectiveOperationException.class)
......
......@@ -67,8 +67,8 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
private int currentSequenceId;
public MySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket comStmtExecutePacket, final BackendConnection backendConnection) {
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(
backendConnection.getSchema(), comStmtExecutePacket.getSql(), comStmtExecutePacket.getParameters(), backendConnection);
databaseCommunicationEngine =
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(comStmtExecutePacket.getSql(), comStmtExecutePacket.getParameters(), backendConnection);
}
@Override
......
......@@ -51,7 +51,7 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
public MySQLComFieldListPacketExecutor(final MySQLComFieldListPacket packet, final BackendConnection backendConnection) {
this.packet = packet;
schemaName = backendConnection.getSchema().getName();
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(backendConnection.getSchema(), getShowColumnsSQL(), backendConnection);
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(getShowColumnsSQL(), backendConnection);
}
@Override
......
......@@ -72,7 +72,7 @@ public final class PostgreSQLComBindExecutor implements QueryCommandExecutor {
public PostgreSQLComBindExecutor(final PostgreSQLComBindPacket packet, final BackendConnection backendConnection) {
this.packet = packet;
databaseCommunicationEngine = null == packet.getSql()
? null : DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(backendConnection.getSchema(), packet.getSql(), packet.getParameters(), backendConnection);
? null : DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(packet.getSql(), packet.getParameters(), backendConnection);
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册