You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/05/14 13:55:49 UTC

[shardingsphere] branch master updated: Fix sonar issue of PostgreSQLDialectExceptionMapper (#25663)

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 8c1ebcdf186 Fix sonar issue of PostgreSQLDialectExceptionMapper (#25663)
8c1ebcdf186 is described below

commit 8c1ebcdf186f993d1502d65df4dd6abeb09767aa
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun May 14 21:55:42 2023 +0800

    Fix sonar issue of PostgreSQLDialectExceptionMapper (#25663)
---
 .../mapper/PostgreSQLDialectExceptionMapper.java   | 28 ++++++++++++----------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/dialect-exception/postgresql/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java b/dialect-exception/postgresql/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
index f8adc291ddd..3726869a2e9 100644
--- a/dialect-exception/postgresql/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
+++ b/dialect-exception/postgresql/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
@@ -43,49 +43,53 @@ import java.sql.SQLException;
  */
 public final class PostgreSQLDialectExceptionMapper implements SQLDialectExceptionMapper {
     
+    private static final String FATAL_SEVERITY = "FATAL";
+    
+    private static final String ERROR_SEVERITY = "ERROR";
+    
     @Override
     public SQLException convert(final SQLDialectException sqlDialectException) {
         if (sqlDialectException instanceof UnknownDatabaseException) {
-            return new PostgreSQLException(new ServerErrorMessage("FATAL", PostgreSQLVendorError.INVALID_CATALOG_NAME, ((UnknownDatabaseException) sqlDialectException).getDatabaseName()));
+            return new PostgreSQLException(new ServerErrorMessage(FATAL_SEVERITY, PostgreSQLVendorError.INVALID_CATALOG_NAME, ((UnknownDatabaseException) sqlDialectException).getDatabaseName()));
         }
         if (sqlDialectException instanceof DatabaseCreateExistsException) {
-            return new PostgreSQLException(new ServerErrorMessage("FATAL", PostgreSQLVendorError.DUPLICATE_DATABASE, ((DatabaseCreateExistsException) sqlDialectException).getDatabaseName()));
+            return new PostgreSQLException(new ServerErrorMessage(FATAL_SEVERITY, PostgreSQLVendorError.DUPLICATE_DATABASE, ((DatabaseCreateExistsException) sqlDialectException).getDatabaseName()));
         }
         if (sqlDialectException instanceof InTransactionException) {
-            return new PostgreSQLException(new ServerErrorMessage("ERROR", PostgreSQLVendorError.TRANSACTION_STATE_INVALID));
+            return new PostgreSQLException(new ServerErrorMessage(ERROR_SEVERITY, PostgreSQLVendorError.TRANSACTION_STATE_INVALID));
         }
         if (sqlDialectException instanceof InsertColumnsAndValuesMismatchedException) {
-            return new PostgreSQLException(new ServerErrorMessage("ERROR",
+            return new PostgreSQLException(new ServerErrorMessage(ERROR_SEVERITY,
                     PostgreSQLVendorError.WRONG_VALUE_COUNT_ON_ROW, ((InsertColumnsAndValuesMismatchedException) sqlDialectException).getMismatchedRowNumber()));
         }
         if (sqlDialectException instanceof InvalidParameterValueException) {
             InvalidParameterValueException cause = (InvalidParameterValueException) sqlDialectException;
-            return new PostgreSQLException(new ServerErrorMessage("ERROR", PostgreSQLVendorError.INVALID_PARAMETER_VALUE, cause.getParameterName(), cause.getParameterValue()));
+            return new PostgreSQLException(new ServerErrorMessage(ERROR_SEVERITY, PostgreSQLVendorError.INVALID_PARAMETER_VALUE, cause.getParameterName(), cause.getParameterValue()));
         }
         if (sqlDialectException instanceof TooManyConnectionsException) {
-            return new PostgreSQLException(new ServerErrorMessage("ERROR", PostgreSQLVendorError.DATA_SOURCE_REJECTED_CONNECTION_ATTEMPT));
+            return new PostgreSQLException(new ServerErrorMessage(ERROR_SEVERITY, PostgreSQLVendorError.DATA_SOURCE_REJECTED_CONNECTION_ATTEMPT));
         }
         if (sqlDialectException instanceof UnknownUsernameException) {
             return new PostgreSQLException(new ServerErrorMessage(
-                    "FATAL", PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION, ((UnknownUsernameException) sqlDialectException).getUsername()));
+                    FATAL_SEVERITY, PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION, ((UnknownUsernameException) sqlDialectException).getUsername()));
         }
         if (sqlDialectException instanceof InvalidPasswordException) {
-            return new PostgreSQLException(new ServerErrorMessage("FATAL", PostgreSQLVendorError.INVALID_PASSWORD, ((InvalidPasswordException) sqlDialectException).getUsername()));
+            return new PostgreSQLException(new ServerErrorMessage(FATAL_SEVERITY, PostgreSQLVendorError.INVALID_PASSWORD, ((InvalidPasswordException) sqlDialectException).getUsername()));
         }
         if (sqlDialectException instanceof PrivilegeNotGrantedException) {
             PrivilegeNotGrantedException cause = (PrivilegeNotGrantedException) sqlDialectException;
-            return new PostgreSQLException(new ServerErrorMessage("FATAL", PostgreSQLVendorError.PRIVILEGE_NOT_GRANTED, cause.getUsername(), cause.getDatabaseName()));
+            return new PostgreSQLException(new ServerErrorMessage(FATAL_SEVERITY, PostgreSQLVendorError.PRIVILEGE_NOT_GRANTED, cause.getUsername(), cause.getDatabaseName()));
         }
         if (sqlDialectException instanceof EmptyUsernameException) {
-            return new PostgreSQLException(new ServerErrorMessage("FATAL", PostgreSQLVendorError.NO_USERNAME));
+            return new PostgreSQLException(new ServerErrorMessage(FATAL_SEVERITY, PostgreSQLVendorError.NO_USERNAME));
         }
         if (sqlDialectException instanceof ProtocolViolationException) {
             ProtocolViolationException cause = (ProtocolViolationException) sqlDialectException;
-            return new PostgreSQLException(new ServerErrorMessage("FATAL", PostgreSQLVendorError.PROTOCOL_VIOLATION, cause.getExpectedMessageType(), cause.getActualMessageType()));
+            return new PostgreSQLException(new ServerErrorMessage(FATAL_SEVERITY, PostgreSQLVendorError.PROTOCOL_VIOLATION, cause.getExpectedMessageType(), cause.getActualMessageType()));
         }
         if (sqlDialectException instanceof ColumnNotFoundException) {
             ColumnNotFoundException cause = (ColumnNotFoundException) sqlDialectException;
-            return new PostgreSQLException(new ServerErrorMessage("FATAL", PostgreSQLVendorError.UNDEFINED_COLUMN, cause.getTableName(), cause.getColumnName()));
+            return new PostgreSQLException(new ServerErrorMessage(FATAL_SEVERITY, PostgreSQLVendorError.UNDEFINED_COLUMN, cause.getTableName(), cause.getColumnName()));
         }
         return new PostgreSQLException(sqlDialectException.getMessage(), PostgreSQLState.UNEXPECTED_ERROR.getValue());
     }