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/11 04:00:24 UTC

[GitHub] [shardingsphere] iamhucong opened a new pull request, #25092: replace PSQLException with PostgreSQLException (#22544)

iamhucong opened a new pull request, #25092:
URL: https://github.com/apache/shardingsphere/pull/25092

   Fixes #ISSUSE_ID.
   
   Changes proposed in this pull request:
     -
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
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


[GitHub] [shardingsphere] TeslaCN merged pull request #25092: replace PSQLException with PostgreSQLException (#22544)

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN merged PR #25092:
URL: https://github.com/apache/shardingsphere/pull/25092


-- 
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #25092:
URL: https://github.com/apache/shardingsphere/pull/25092#discussion_r1162292973


##########
proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java:
##########
@@ -65,8 +71,8 @@ private static PostgreSQLErrorResponsePacket createErrorResponsePacket(final Ser
     
     @SuppressWarnings("ConstantConditions")
     private static PostgreSQLErrorResponsePacket createErrorResponsePacket(final SQLException cause) {
-        if (cause instanceof PSQLException && null != ((PSQLException) cause).getServerErrorMessage()) {

Review Comment:
   The `cause` could be `PSQLException`, so we need to keep the origin logic here and add a new branch to handle `PostgreSQLException`.



-- 
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


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

Posted by "iamhucong (via GitHub)" <gi...@apache.org>.
iamhucong commented on code in PR #25092:
URL: https://github.com/apache/shardingsphere/pull/25092#discussion_r1163477598


##########
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) {
+            this.severity = severity;
+            this.sqlState = sqlState;
+            this.message = message;
+        }
+        
+        @Override
+        public String toString() {

Review Comment:
   The purpose of `toString` is to serve as the message for the parent class SQLException.



-- 
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


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

Posted by "iamhucong (via GitHub)" <gi...@apache.org>.
iamhucong commented on PR #25092:
URL: https://github.com/apache/shardingsphere/pull/25092#issuecomment-1503423472

   @TeslaCN Hi, already fixed, please help me review it.


-- 
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #25092:
URL: https://github.com/apache/shardingsphere/pull/25092#discussion_r1163469055


##########
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:
   When do we need this constructor?



##########
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) {
+            this.severity = severity;
+            this.sqlState = sqlState;
+            this.message = message;
+        }
+        
+        @Override
+        public String toString() {

Review Comment:
   Is this `toString` necessary?



-- 
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


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

Posted by "iamhucong (via GitHub)" <gi...@apache.org>.
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #25092:
URL: https://github.com/apache/shardingsphere/pull/25092#discussion_r1163661622


##########
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) {
+            this.severity = severity;
+            this.sqlState = sqlState;
+            this.message = message;
+        }
+        
+        @Override
+        public String toString() {

Review Comment:
   Got it.



-- 
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