This is an automated email from the ASF dual-hosted git repository.
panjuan 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 bf5de8f Refactor MySQLErrPacketFactory (#7487)
bf5de8f is described below
commit bf5de8fba870746b5da6a640ec3a52f97a549178
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 16 18:57:29 2020 +0800
Refactor MySQLErrPacketFactory (#7487)
---
.../frontend/mysql/MySQLErrPacketFactory.java | 27 +++++++++++-----------
.../mysql/command/MySQLCommandExecuteEngine.java | 2 +-
.../frontend/mysql/MySQLErrPacketFactoryTest.java | 18 +++++++--------
3 files changed, 23 insertions(+), 24 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
index 12e5ccb..4f5a038 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
@@ -45,44 +45,43 @@ public final class MySQLErrPacketFactory {
/**
* New instance of MySQL ERR packet.
*
- * @param sequenceId sequence ID
* @param cause cause
* @return instance of MySQL ERR packet
*/
- public static MySQLErrPacket newInstance(final int sequenceId, final
Exception cause) {
+ public static MySQLErrPacket newInstance(final Exception cause) {
if (cause instanceof SQLException) {
SQLException sqlException = (SQLException) cause;
- return null != sqlException.getSQLState() ? new
MySQLErrPacket(sequenceId, sqlException.getErrorCode(),
sqlException.getSQLState(), sqlException.getMessage())
- : new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_INTERNAL_ERROR, cause.getMessage());
+ return null != sqlException.getSQLState() ? new MySQLErrPacket(1,
sqlException.getErrorCode(), sqlException.getSQLState(),
sqlException.getMessage())
+ : new MySQLErrPacket(1,
MySQLServerErrorCode.ER_INTERNAL_ERROR, cause.getMessage());
}
if (cause instanceof ShardingCTLException) {
ShardingCTLException shardingCTLException = (ShardingCTLException)
cause;
- return new MySQLErrPacket(sequenceId,
ShardingCTLErrorCode.valueOf(shardingCTLException),
shardingCTLException.getShardingCTL());
+ return new MySQLErrPacket(1,
ShardingCTLErrorCode.valueOf(shardingCTLException),
shardingCTLException.getShardingCTL());
}
if (cause instanceof TableModifyInTransactionException) {
- return new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE,
((TableModifyInTransactionException) cause).getTableName());
+ return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE,
((TableModifyInTransactionException) cause).getTableName());
}
if (cause instanceof UnknownDatabaseException) {
- return new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_BAD_DB_ERROR, ((UnknownDatabaseException)
cause).getDatabaseName());
+ return new MySQLErrPacket(1, MySQLServerErrorCode.ER_BAD_DB_ERROR,
((UnknownDatabaseException) cause).getDatabaseName());
}
if (cause instanceof NoDatabaseSelectedException) {
- return new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_NO_DB_ERROR);
+ return new MySQLErrPacket(1, MySQLServerErrorCode.ER_NO_DB_ERROR);
}
if (cause instanceof DBCreateExistsException) {
- return new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_DB_CREATE_EXISTS_ERROR, ((DBCreateExistsException)
cause).getDatabaseName());
+ return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_DB_CREATE_EXISTS_ERROR, ((DBCreateExistsException)
cause).getDatabaseName());
}
if (cause instanceof DBDropExistsException) {
- return new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_DB_DROP_EXISTS_ERROR, ((DBDropExistsException)
cause).getDatabaseName());
+ return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_DB_DROP_EXISTS_ERROR, ((DBDropExistsException)
cause).getDatabaseName());
}
if (cause instanceof TableExistsException) {
- return new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_TABLE_EXISTS_ERROR, ((TableExistsException)
cause).getTableName());
+ return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_TABLE_EXISTS_ERROR, ((TableExistsException)
cause).getTableName());
}
if (cause instanceof CircuitBreakException) {
- return new MySQLErrPacket(sequenceId,
CommonErrorCode.CIRCUIT_BREAK_MODE);
+ return new MySQLErrPacket(1, CommonErrorCode.CIRCUIT_BREAK_MODE);
}
if (cause instanceof ShardingSphereConfigurationException || cause
instanceof SQLParsingException) {
- return new MySQLErrPacket(sequenceId,
MySQLServerErrorCode.ER_NOT_SUPPORTED_YET, cause.getMessage());
+ return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_NOT_SUPPORTED_YET, cause.getMessage());
}
- return new MySQLErrPacket(sequenceId,
CommonErrorCode.UNKNOWN_EXCEPTION, cause.getMessage());
+ return new MySQLErrPacket(1, CommonErrorCode.UNKNOWN_EXCEPTION,
cause.getMessage());
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
index 7030dcf..f6dc671 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
@@ -62,7 +62,7 @@ public final class MySQLCommandExecuteEngine implements
CommandExecuteEngine {
@Override
public DatabasePacket<?> getErrorPacket(final Exception cause) {
- return MySQLErrPacketFactory.newInstance(1, cause);
+ return MySQLErrPacketFactory.newInstance(cause);
}
@Override
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
index ac6a1f7..5f78bfd 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
@@ -36,7 +36,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithSQLException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
SQLException("No reason", "XXX", 9999, new RuntimeException("")));
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
SQLException("No reason", "XXX", 9999, new RuntimeException("")));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(9999));
assertThat(actual.getSqlState(), is("XXX"));
@@ -45,7 +45,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithSQLExceptionOfNullSQLState() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
SQLException(new RuntimeException("No reason")));
+ 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"));
@@ -54,7 +54,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithSQLExceptionOfNullParam() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
SQLException(""));
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
SQLException(""));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(1815));
assertThat(actual.getSqlState(), is("HY000"));
@@ -63,7 +63,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithInvalidShardingCTLFormatException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
InvalidShardingCTLFormatException("test"));
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
InvalidShardingCTLFormatException("test"));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(11000));
assertThat(actual.getSqlState(), is("S11000"));
@@ -72,7 +72,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithUnsupportedShardingCTLTypeException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
UnsupportedShardingCTLTypeException("sctl:set xxx=xxx"));
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnsupportedShardingCTLTypeException("sctl:set xxx=xxx"));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(11001));
assertThat(actual.getSqlState(), is("S11001"));
@@ -81,7 +81,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithTableModifyInTransactionException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
TableModifyInTransactionException("tbl"));
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
TableModifyInTransactionException("tbl"));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(3176));
assertThat(actual.getSqlState(), is("HY000"));
@@ -91,7 +91,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithUnknownDatabaseException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
UnknownDatabaseException("ds"));
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
UnknownDatabaseException("ds"));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(1049));
assertThat(actual.getSqlState(), is("42000"));
@@ -100,7 +100,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithNoDatabaseSelectedException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
NoDatabaseSelectedException());
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
NoDatabaseSelectedException());
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(1046));
assertThat(actual.getSqlState(), is("3D000"));
@@ -109,7 +109,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public void assertNewInstanceWithOtherException() {
- MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(1, new
RuntimeException("No reason"));
+ MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new
RuntimeException("No reason"));
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(), is(10002));
assertThat(actual.getSqlState(), is("C10002"));