You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/09/30 14:00:11 UTC
[shardingsphere] branch master updated: Remove console print if SQL
parse failed (#12867)
This is an automated email from the ASF dual-hosted git repository.
menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 01ab976 Remove console print if SQL parse failed (#12867)
01ab976 is described below
commit 01ab976a0c1d0be9bfa61158a783be60c95a257e
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Sep 30 21:59:35 2021 +0800
Remove console print if SQL parse failed (#12867)
* Refactor HikariJDBCParameterDecoratorTest
* Remove console print if SQL parse failed
---
.../datasource/decorator/HikariJDBCParameterDecoratorTest.java | 7 ++++---
.../apache/shardingsphere/sql/parser/core/SQLParserFactory.java | 3 +++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariJDBCParameterDecoratorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariJDBCParameterDecoratorTest.java
index 50a4d93..65ea2be 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariJDBCParameterDecoratorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariJDBCParameterDecoratorTest.java
@@ -18,14 +18,15 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.decorator;
import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.test.mock.MockedDriver;
import org.junit.Test;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertNull;
public final class HikariJDBCParameterDecoratorTest {
@@ -37,7 +38,7 @@ public final class HikariJDBCParameterDecoratorTest {
@Test
public void assertDecoratedHikariDataSource() {
HikariDataSource dataSource = new HikariDataSource();
- dataSource.setDriverClassName("org.apache.shardingsphere.test.mock.MockedDriver");
+ dataSource.setDriverClassName(MockedDriver.class.getName());
dataSource.setJdbcUrl("mock:jdbc");
HikariDataSource actual = new HikariJDBCParameterDecorator().decorate(dataSource);
Properties props = actual.getDataSourceProperties();
@@ -60,7 +61,7 @@ public final class HikariJDBCParameterDecoratorTest {
@Test
public void assertDecoratedHikariDataSourceWithExistedParam() {
HikariDataSource dataSource = new HikariDataSource();
- dataSource.setDriverClassName("org.apache.shardingsphere.test.mock.MockedDriver");
+ dataSource.setDriverClassName(MockedDriver.class.getName());
dataSource.setJdbcUrl("mock:jdbc://127.0.0.1:3306/test0?tinyInt1isBit=true&useSSL=false");
HikariDataSource actual = new HikariJDBCParameterDecorator().decorate(dataSource);
Properties props = actual.getDataSourceProperties();
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/SQLParserFactory.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/SQLParserFactory.java
index a95d1fc..4098db2 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/SQLParserFactory.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/SQLParserFactory.java
@@ -25,6 +25,7 @@ import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CodePointBuffer;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.ConsoleErrorListener;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.TokenStream;
@@ -61,6 +62,7 @@ public final class SQLParserFactory {
Arrays.stream(parserClass.getMethods()).filter(each -> "setSqlCommentParseEnabled".equals(each.getName())).findAny().ifPresent(each -> setEnableSqlCommentParse(result, each));
}
((Parser) result).setErrorHandler(new BailErrorStrategy());
+ ((Parser) result).removeErrorListener(ConsoleErrorListener.INSTANCE);
return result;
}
@@ -72,6 +74,7 @@ public final class SQLParserFactory {
@SneakyThrows(ReflectiveOperationException.class)
private static TokenStream createTokenStream(final String sql, final Class<? extends SQLLexer> lexerClass) {
Lexer lexer = (Lexer) lexerClass.getConstructor(CharStream.class).newInstance(getSQLCharStream(sql));
+ lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
return new CommonTokenStream(lexer);
}