This is an automated email from the ASF dual-hosted git repository.
yx9o 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 71383367718 Refactor UnsupportedPreparedStatementException (#20610)
71383367718 is described below
commit 7138336771807489481e197b65a9f3b4c2ca2ba1
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 28 14:19:08 2022 +0800
Refactor UnsupportedPreparedStatementException (#20610)
---
.../user-manual/error-code/sql-error-code.cn.md | 2 +-
.../user-manual/error-code/sql-error-code.en.md | 2 +-
.../UnsupportedPreparedStatementException.java | 6 +-
.../mysql/mapper/MySQLDialectExceptionMapper.java | 4 +
.../util/exception/sql/UnknownSQLException.java | 2 +-
.../frontend/exception/ExpectedExceptions.java | 1 -
.../frontend/exception/ExpectedExceptionsTest.java | 1 -
.../prepare/MySQLComStmtPrepareExecutor.java | 2 +-
.../frontend/mysql/err/MySQLErrPacketFactory.java | 4 -
.../prepare/MySQLComStmtPrepareExecutorTest.java | 5 +-
.../mysql/err/MySQLErrPacketFactoryTest.java | 179 +++------------------
11 files changed, 39 insertions(+), 169 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index c23bdeb0fd5..f64a70f52e3 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -70,4 +70,4 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 44000 | 24004 | Can not find logic encrypt column by \`%s\` |
| HY004 | 25000 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type |
| 42000 | 25003 | Insert value of index \`%s\` can not support for
shadow |
-| 42000 | 30000 | Unknown exception: %s |
+| HY004 | 30000 | Unknown exception: %s |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index dcef20d974a..1ac6607759c 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -70,4 +70,4 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 44000 | 24004 | Can not find logic encrypt column by \`%s\` |
| HY004 | 25000 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type |
| 42000 | 25003 | Insert value of index \`%s\` can not support for
shadow |
-| 42000 | 30000 | Unknown exception: %s |
+| HY004 | 30000 | Unknown exception: %s |
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedPreparedStatementException.java
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/connection/UnsupportedPreparedStatementException.java
similarity index 86%
rename from
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedPreparedStatementException.java
rename to
shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/connection/UnsupportedPreparedStatementException.java
index 89e13d6ce8a..9312ac5c2f9 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedPreparedStatementException.java
+++
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/connection/UnsupportedPreparedStatementException.java
@@ -15,12 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.frontend.exception;
+package org.apache.shardingsphere.dialect.exception.connection;
+
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
/**
* Unsupported prepared statement exception.
*/
-public final class UnsupportedPreparedStatementException extends
FrontendException {
+public final class UnsupportedPreparedStatementException extends
SQLDialectException {
private static final long serialVersionUID = 2185290474191327830L;
}
diff --git
a/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
b/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
index b03186b6be0..8866adf7ffb 100644
---
a/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
+++
b/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.dialect.mysql.mapper;
import org.apache.shardingsphere.dialect.exception.SQLDialectException;
import
org.apache.shardingsphere.dialect.exception.connection.TooManyConnectionsException;
+import
org.apache.shardingsphere.dialect.exception.connection.UnsupportedPreparedStatementException;
import
org.apache.shardingsphere.dialect.exception.data.InsertColumnsAndValuesMismatchedException;
import
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseCreateExistsException;
import
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseDropNotExistsException;
@@ -70,6 +71,9 @@ public final class MySQLDialectExceptionMapper implements
SQLDialectExceptionMap
if (sqlDialectException instanceof TooManyConnectionsException) {
return toSQLException(MySQLVendorError.ER_CON_COUNT_ERROR);
}
+ if (sqlDialectException instanceof
UnsupportedPreparedStatementException) {
+ return toSQLException(MySQLVendorError.ER_UNSUPPORTED_PS);
+ }
return new UnknownSQLException(sqlDialectException).toSQLException();
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/UnknownSQLException.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/UnknownSQLException.java
index e2d5a8dac73..0955d82d80f 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/UnknownSQLException.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/UnknownSQLException.java
@@ -27,6 +27,6 @@ public final class UnknownSQLException extends
ShardingSphereSQLException {
private static final long serialVersionUID = -7357918573504734977L;
public UnknownSQLException(final Exception cause) {
- super(XOpenSQLState.SYNTAX_ERROR, 30000, "Unknown exception: %s",
cause.getMessage());
+ super(XOpenSQLState.GENERAL_ERROR, 30000, "Unknown exception: %s",
cause.getMessage());
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
index 5533a594649..dc7870f0e04 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
@@ -42,7 +42,6 @@ public final class ExpectedExceptions {
EXCEPTIONS.add(ShardingSphereConfigurationException.class);
EXCEPTIONS.add(SQLParsingException.class);
EXCEPTIONS.add(DistSQLException.class);
- EXCEPTIONS.add(UnsupportedPreparedStatementException.class);
}
/**
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
index 58623206084..142a110d5bd 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
@@ -38,7 +38,6 @@ public final class ExpectedExceptionsTest {
assertTrue(ExpectedExceptions.isExpected(SQLParsingException.class));
assertTrue(ExpectedExceptions.isExpected(DistSQLException.class));
assertTrue(ExpectedExceptions.isExpected(NoDatabaseSelectedException.class));
-
assertTrue(ExpectedExceptions.isExpected(UnsupportedPreparedStatementException.class));
}
@Test
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
index f31ba85f093..81795966531 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
@@ -37,7 +37,7 @@ import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
-import
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedPreparedStatementException;
+import
org.apache.shardingsphere.dialect.exception.connection.UnsupportedPreparedStatementException;
import
org.apache.shardingsphere.proxy.frontend.mysql.command.ServerStatusFlagCalculator;
import
org.apache.shardingsphere.proxy.frontend.mysql.command.query.binary.MySQLPreparedStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index 68641318ad2..d111728685f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -28,7 +28,6 @@ import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLExcep
import org.apache.shardingsphere.infra.util.exception.sql.UnknownSQLException;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLException;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLVendorError;
-import
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedPreparedStatementException;
import java.nio.charset.UnsupportedCharsetException;
import java.sql.SQLException;
@@ -60,9 +59,6 @@ public final class MySQLErrPacketFactory {
DistSQLException distSQLException = (DistSQLException) cause;
return new MySQLErrPacket(1,
DistSQLVendorError.valueOf(distSQLException), distSQLException.getVariable());
}
- if (cause instanceof UnsupportedPreparedStatementException) {
- return new MySQLErrPacket(1, MySQLVendorError.ER_UNSUPPORTED_PS);
- }
if (cause instanceof UnsupportedCharsetException) {
return new MySQLErrPacket(1,
MySQLVendorError.ER_UNKNOWN_CHARACTER_SET, cause.getMessage());
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java
index dc4ff8f9dca..c383cd609c5 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java
@@ -36,7 +36,7 @@ import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.proxy.backend.session.PreparedStatementRegistry;
-import
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedPreparedStatementException;
+import
org.apache.shardingsphere.dialect.exception.connection.UnsupportedPreparedStatementException;
import org.apache.shardingsphere.proxy.frontend.mysql.ProxyContextRestorer;
import
org.apache.shardingsphere.proxy.frontend.mysql.command.query.binary.MySQLPreparedStatement;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
@@ -56,6 +56,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -111,6 +112,7 @@ public final class MySQLComStmtPrepareExecutorTest extends
ProxyContextRestorer
MySQLPreparedStatement actualPreparedStatement =
connectionSession.getPreparedStatementRegistry().getPreparedStatement(1);
assertThat(actualPreparedStatement.getSql(), is(sql));
assertThat(actualPreparedStatement.getSqlStatement(),
instanceOf(MySQLSelectStatement.class));
+
assertTrue(actualPreparedStatement.getSqlStatementContext().isPresent());
assertThat(actualPreparedStatement.getSqlStatementContext().get(),
instanceOf(SelectStatementContext.class));
MySQLStatementIDGenerator.getInstance().unregisterConnection(1);
}
@@ -129,6 +131,7 @@ public final class MySQLComStmtPrepareExecutorTest extends
ProxyContextRestorer
MySQLPreparedStatement actualPreparedStatement =
connectionSession.getPreparedStatementRegistry().getPreparedStatement(1);
assertThat(actualPreparedStatement.getSql(), is(sql));
assertThat(actualPreparedStatement.getSqlStatement(),
instanceOf(MySQLUpdateStatement.class));
+
assertTrue(actualPreparedStatement.getSqlStatementContext().isPresent());
assertThat(actualPreparedStatement.getSqlStatementContext().get(),
instanceOf(UpdateStatementContext.class));
MySQLStatementIDGenerator.getInstance().unregisterConnection(1);
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
index 95c26486ad7..9f872c32d4b 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
@@ -18,204 +18,71 @@
package org.apache.shardingsphere.proxy.frontend.mysql.err;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
-import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
-import
org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException;
-import
org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException;
import
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
-import
org.apache.shardingsphere.proxy.frontend.exception.CircuitBreakException;
-import
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseCreateExistsException;
-import
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseDropNotExistsException;
-import
org.apache.shardingsphere.dialect.exception.transaction.TableModifyInTransactionException;
+import
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.UnsupportedVariableException;
-import
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedCommandException;
-import
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedPreparedStatementException;
-import
org.apache.shardingsphere.dialect.exception.syntax.table.NoSuchTableException;
-import
org.apache.shardingsphere.dialect.exception.syntax.table.TableExistsException;
-import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
+import
org.apache.shardingsphere.proxy.frontend.exception.CircuitBreakException;
import org.junit.Test;
import java.sql.SQLException;
-import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public final class MySQLErrPacketFactoryTest {
@Test
- public void assertNewInstanceWithSQLException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
SQLException("No reason", "XXX", 30000, new RuntimeException("")));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(30000));
- assertThat(actual.getSqlState(), is("XXX"));
- assertThat(actual.getErrorMessage(), is("No reason"));
- }
-
- @Test
- public void assertNewInstanceWithSQLExceptionOfNullSQLState() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
SQLException(new RuntimeException("No reason")));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1815));
- assertThat(actual.getSqlState(), is("HY000"));
- assertThat(actual.getErrorMessage(), endsWith("No reason"));
- }
-
- @Test
- public void assertNewInstanceWithSQLExceptionOfNullParam() {
+ public void assertNewInstanceWithSQLExceptionForNullSQLState() {
MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
SQLException(""));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(1815));
- assertThat(actual.getSqlState(), is("HY000"));
+ assertThat(actual.getSqlState(),
is(XOpenSQLState.GENERAL_ERROR.getValue()));
assertThat(actual.getErrorMessage(), startsWith("Internal error"));
}
@Test
- public void assertNewInstanceWithUnsupportedVariableExceptionException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnsupportedVariableException("test"));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(11001));
- assertThat(actual.getSqlState(), is("HY000"));
- assertThat(actual.getErrorMessage(), is("Could not support variable
`test`"));
- }
-
- @Test
- public void assertNewInstanceWithTableModifyInTransactionException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
TableModifyInTransactionException("unknown_table"));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(3176));
- assertThat(actual.getSqlState(), is("HY000"));
- assertThat(actual.getErrorMessage(), is("Please do not modify the
unknown_table table with an XA transaction. "
- + "This is an internal system table used to store GTIDs for
committed transactions. "
- + "Although modifying it can lead to an inconsistent GTID
state, if necessary you can modify it with a non-XA transaction."));
- }
-
- @Test
- public void assertNewInstanceWithUnknownDatabaseException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnknownDatabaseException("ds"));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1049));
- assertThat(actual.getSqlState(), is("42000"));
- assertThat(actual.getErrorMessage(), is("Unknown database 'ds'"));
- }
-
- @Test
- public void assertNewInstanceWithNoDatabaseSelectedException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
NoDatabaseSelectedException());
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1046));
- assertThat(actual.getSqlState(), is("3D000"));
- assertThat(actual.getErrorMessage(), is("No database selected"));
- }
-
- @Test
- public void assertNewInstanceWithDBCreateExistsException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
DatabaseCreateExistsException("No reason"));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1007));
- assertThat(actual.getSqlState(), is("HY000"));
- assertThat(actual.getErrorMessage(), is("Can't create database 'No
reason'; database exists"));
- }
-
- @Test
- public void assertNewInstanceWithDBDropExistsException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
DatabaseDropNotExistsException("No reason"));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1008));
- assertThat(actual.getSqlState(), is("HY000"));
- assertThat(actual.getErrorMessage(), is("Can't drop database 'No
reason'; database doesn't exist"));
- }
-
- @Test
- public void assertNewInstanceWithTableExistsException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
TableExistsException("table_name"));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1050));
- assertThat(actual.getSqlState(), is("42S01"));
- assertThat(actual.getErrorMessage(), is("Table 'table_name' already
exists"));
- }
-
- @Test
- public void assertNewInstanceWithNoSuchTableException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
NoSuchTableException("table_name"));
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1146));
- assertThat(actual.getSqlState(), is("42S02"));
- assertThat(actual.getErrorMessage(), is("Table 'table_name' doesn't
exist"));
- }
-
- @Test
- public void assertNewInstanceWithShardingSphereConfigurationException() {
-
assertShardingSphereConfigurationException(MySQLErrPacketFactory.newInstance(new
ShardingSphereConfigurationException("No reason")));
- }
-
- private void assertShardingSphereConfigurationException(final
MySQLErrPacket actual) {
+ public void assertNewInstanceWithSQLException() {
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
SQLException("No reason", "XXX", 30000, new RuntimeException("")));
assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(11001));
- assertThat(actual.getSqlState(), is("42000"));
+ assertThat(actual.getErrorCode(), is(30000));
+ assertThat(actual.getSqlState(), is("XXX"));
assertThat(actual.getErrorMessage(), is("No reason"));
}
@Test
- public void assertNewInstanceWithSQLParsingException() {
- assertSQLParsingException(MySQLErrPacketFactory.newInstance(new
SQLParsingException("test")));
- }
-
- private void assertSQLParsingException(final MySQLErrPacket actual) {
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(11000));
- assertThat(actual.getSqlState(), is("42000"));
- assertThat(actual.getErrorMessage(), is("You have an error in your SQL
syntax: test"));
- }
-
- @Test
- public void assertNewInstanceWithUnsupportedPreparedStatementException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnsupportedPreparedStatementException());
- assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1295));
- assertThat(actual.getSqlState(), is("HY000"));
- assertThat(actual.getErrorMessage(), is("This command is not supported
in the prepared statement protocol yet"));
- }
-
- @Test
- public void assertNewInstanceWithCircuitBreakException() {
+ public void assertNewInstanceWithShardingSphereSQLException() {
MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
CircuitBreakException());
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(10000));
- assertThat(actual.getSqlState(), is("01000"));
+ assertThat(actual.getSqlState(),
is(XOpenSQLState.GENERAL_WARNING.getValue()));
assertThat(actual.getErrorMessage(), is("Circuit break open, the
request has been ignored"));
}
@Test
- public void assertNewInstanceWithRuleDefinitionViolationException() {
- RuleDefinitionViolationException exception =
mock(RuleDefinitionViolationException.class);
- when(exception.getErrorCode()).thenReturn(1);
- when(exception.getSQLState()).thenReturn("C0000");
- when(exception.getMessage()).thenReturn("Test error");
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(exception);
+ public void assertNewInstanceWithSQLDialectException() {
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnknownDatabaseException("foo_db"));
assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(1));
- assertThat(actual.getSqlState(), is("C0000"));
- assertThat(actual.getErrorMessage(), is("Test error"));
+ assertThat(actual.getErrorCode(), is(1049));
+ assertThat(actual.getSqlState(),
is(XOpenSQLState.SYNTAX_ERROR.getValue()));
+ assertThat(actual.getErrorMessage(), is("Unknown database 'foo_db'"));
}
@Test
- public void assertNewInstanceWithUnsupportedCommandException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnsupportedCommandException("No reason"));
+ public void assertNewInstanceWithDistException() {
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnsupportedVariableException("test"));
assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(), is(12000));
- assertThat(actual.getSqlState(), is("42000"));
- assertThat(actual.getErrorMessage(), is("Unsupported command: No
reason"));
+ assertThat(actual.getErrorCode(), is(11001));
+ assertThat(actual.getSqlState(),
is(XOpenSQLState.GENERAL_ERROR.getValue()));
+ assertThat(actual.getErrorMessage(), is("Could not support variable
`test`"));
}
@Test
- public void assertNewInstanceWithOtherException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
ReflectiveOperationException("No reason"));
+ public void assertNewInstanceWithUnknownException() {
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
RuntimeException("No reason"));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(30000));
- assertThat(actual.getSqlState(), is("42000"));
+ assertThat(actual.getSqlState(),
is(XOpenSQLState.GENERAL_ERROR.getValue()));
assertThat(actual.getErrorMessage(), is("Unknown exception: No
reason"));
}
}