Skip to content

Commit

Permalink
use ShardingSphereSQLParserEngine instead of SQLParserEngine (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaZero authored and qiulu3 committed Aug 3, 2020
1 parent 6e98d39 commit b38c537
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 159 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@

package org.apache.shardingsphere.driver.jdbc.core.resultset;

import java.sql.Array;
import java.time.LocalDateTime;
import java.time.ZoneId;
import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import org.apache.shardingsphere.driver.jdbc.core.context.RuntimeContext;
import org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
Expand All @@ -37,6 +33,7 @@
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
Expand All @@ -46,6 +43,8 @@
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
Expand All @@ -68,8 +67,6 @@ public final class ShardingSphereResultSetTest {
@Before
public void setUp() throws SQLException {
mergeResultSet = mock(MergedResult.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
when(runtimeContext.getProps()).thenReturn(new ConfigurationProperties(new Properties()));
shardingSphereResultSet = new ShardingSphereResultSet(getResultSets(), mergeResultSet, getShardingSphereStatement(), createExecutionContext());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-sql-parser-engine</artifactId>
<artifactId>shardingsphere-rdl-parser-engine</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngineFactory;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngineFactory;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;

import javax.sql.DataSource;
Expand Down Expand Up @@ -110,7 +110,7 @@ public SchemaContexts build() throws SQLException {
private SchemaContext createSchemaContext(final String schemaName) throws SQLException {
Map<String, DataSource> dataSources = this.dataSources.get(schemaName);
RuntimeContext runtimeContext = new RuntimeContext(createCachedDatabaseMetaData(dataSources),
executorKernel, SQLParserEngineFactory.getSQLParserEngine(DatabaseTypes.getTrunkDatabaseTypeName(databaseType)), createShardingTransactionManagerEngine(dataSources));
executorKernel, ShardingSphereSQLParserEngineFactory.getSQLParserEngine(DatabaseTypes.getTrunkDatabaseTypeName(databaseType)), createShardingTransactionManagerEngine(dataSources));
return new SchemaContext(schemaName, createShardingSphereSchema(schemaName), runtimeContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngine;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;

/**
Expand All @@ -34,7 +34,7 @@ public final class RuntimeContext {

private final ExecutorKernel executorKernel;

private final SQLParserEngine sqlParserEngine;
private final ShardingSphereSQLParserEngine sqlParserEngine;

private final ShardingTransactionManagerEngine transactionManagerEngine;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngine;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -47,7 +47,7 @@ public void setUp() {
schemaContext = mock(SchemaContext.class);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
SQLParserEngine sqlParserEngine = mock(SQLParserEngine.class);
ShardingSphereSQLParserEngine sqlParserEngine = mock(ShardingSphereSQLParserEngine.class);
when(sqlParserEngine.parse(anyString(), anyBoolean())).thenReturn(mock(SQLStatement.class));
when(runtimeContext.getSqlParserEngine()).thenReturn(sqlParserEngine);
when(schema.getRules()).thenReturn(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngine;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void setUp() {
}

private SchemaContext createSchemaContext() {
RuntimeContext runtimeContext = new RuntimeContext(null, null, new SQLParserEngine("MySQL"), null);
RuntimeContext runtimeContext = new RuntimeContext(null, null, new ShardingSphereSQLParserEngine(new SQLParserEngine("MySQL")), null);
ShardingSphereSchema schema = new ShardingSphereSchema(new MySQLDatabaseType(), Collections.emptyList(),
Collections.emptyList(), Collections.singletonMap("ds0", mock(DataSource.class)), null);
return new SchemaContext("c1", schema, runtimeContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.apache.shardingsphere.proxy.frontend.mysql.command.query.binary.reset.MySQLComStmtResetExecutor;
import org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.fieldlist.MySQLComFieldListPacketExecutor;
import org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngine;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.junit.Test;

Expand All @@ -60,7 +60,7 @@ public void assertNewInstance() {
SchemaContext schemaContext = mock(SchemaContext.class);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
SQLParserEngine sqlParserEngine = mock(SQLParserEngine.class);
ShardingSphereSQLParserEngine sqlParserEngine = mock(ShardingSphereSQLParserEngine.class);
when(sqlParserEngine.parse(anyString(), anyBoolean())).thenReturn(mock(SQLStatement.class));
when(runtimeContext.getSqlParserEngine()).thenReturn(sqlParserEngine);
when(schema.getRules()).thenReturn(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngine;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void assertIsErrorResponse() {
BackendConnection backendConnection = mock(BackendConnection.class);
SchemaContext schema = mock(SchemaContext.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
SQLParserEngine sqlParserEngine = mock(SQLParserEngine.class);
ShardingSphereSQLParserEngine sqlParserEngine = mock(ShardingSphereSQLParserEngine.class);
when(runtimeContext.getSqlParserEngine()).thenReturn(sqlParserEngine);
when(schema.getRuntimeContext()).thenReturn(runtimeContext);
when(backendConnection.getSchema()).thenReturn(schema);
Expand All @@ -75,7 +75,7 @@ public void assertIsUpdateResponse() {
BackendConnection backendConnection = mock(BackendConnection.class);
SchemaContext schema = mock(SchemaContext.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
SQLParserEngine sqlParserEngine = mock(SQLParserEngine.class);
ShardingSphereSQLParserEngine sqlParserEngine = mock(ShardingSphereSQLParserEngine.class);
when(runtimeContext.getSqlParserEngine()).thenReturn(sqlParserEngine);
when(schema.getRuntimeContext()).thenReturn(runtimeContext);
when(backendConnection.getSchema()).thenReturn(schema);
Expand All @@ -92,7 +92,7 @@ public void assertIsQuery() {
BackendConnection backendConnection = mock(BackendConnection.class);
SchemaContext schema = mock(SchemaContext.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
SQLParserEngine sqlParserEngine = mock(SQLParserEngine.class);
ShardingSphereSQLParserEngine sqlParserEngine = mock(ShardingSphereSQLParserEngine.class);
when(runtimeContext.getSqlParserEngine()).thenReturn(sqlParserEngine);
when(schema.getRuntimeContext()).thenReturn(runtimeContext);
when(backendConnection.getSchema()).thenReturn(schema);
Expand Down

0 comments on commit b38c537

Please sign in to comment.