You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "iamhucong (via GitHub)" <gi...@apache.org> on 2023/04/12 01:34:56 UTC

[GitHub] [shardingsphere] iamhucong commented on a diff in pull request #25092: replace PSQLException with PostgreSQLException (#22544)

iamhucong commented on code in PR #25092:
URL: https://github.com/apache/shardingsphere/pull/25092#discussion_r1163475142


##########
dialect-exception/postgresql/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/PostgreSQLException.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.dialect.postgresql.exception;
+
+import lombok.Getter;
+import org.apache.shardingsphere.infra.util.exception.external.sql.vendor.VendorError;
+
+import java.sql.SQLException;
+import java.text.MessageFormat;
+
+@Getter
+public class PostgreSQLException extends SQLException {
+    
+    private final ServerErrorMessage serverErrorMessage;
+    
+    public PostgreSQLException(final String msg, final String state) {
+        super(msg, state);
+        this.serverErrorMessage = null;
+    }
+    
+    public PostgreSQLException(final ServerErrorMessage serverErrorMessage) {
+        super(serverErrorMessage.toString(), serverErrorMessage.getSqlState());
+        this.serverErrorMessage = serverErrorMessage;
+    }
+    
+    @Getter
+    public static class ServerErrorMessage {
+    
+        private final String severity;
+    
+        private final String sqlState;
+    
+        private final String message;
+        
+        public ServerErrorMessage(final String severity, final VendorError vendorError, final Object... reasonArgs) {
+            this(severity, vendorError.getSqlState().getValue(), String.format(vendorError.getReason(), reasonArgs));
+        }
+
+        public ServerErrorMessage(final String severity, final String sqlState, final String message) {

Review Comment:
   Yes, we don't need this constructor. I will make some modifications.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org