This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 dd2b9dc11d7 Add OverallConnectionNotEnoughException (#20818)
dd2b9dc11d7 is described below
commit dd2b9dc11d73e2acd792793004698f5056ac651f
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Sep 6 12:34:14 2022 +0800
Add OverallConnectionNotEnoughException (#20818)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../impl/driver/jdbc/type/util/ResultSetUtil.java | 2 +-
.../advanced/resultset/WrapperAdapter.java | 3 ++-
.../driver/jdbc/adapter/WrapperAdapter.java | 3 ++-
.../driver/jdbc/core/ShardingSphereSavepoint.java | 5 +++--
.../jdbc/core/connection/ConnectionManager.java | 3 ++-
.../core/connection/ShardingSphereConnection.java | 5 +++--
.../OverallConnectionNotEnoughException.java | 24 ++++++++--------------
.../core/connection/ConnectionManagerTest.java | 2 +-
10 files changed, 24 insertions(+), 25 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 6251bf198e0..51516fdca39 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
@@ -17,6 +17,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY004 | 10004 | Unsupported conversion data type \`%s\` for value
\`%s\` |
| HY004 | 10005 | Unsupported conversion stream charset \`%s\` |
| HY004 | 10006 | SQL String can not be NULL or empty |
+| 08000 | 10007 | Can not get %d connections one time, partition
succeed connection(%d) have released |
| HY004 | 10100 | Can not register driver, reason is: %s |
| 34000 | 10200 | Can not get cursor name from fetch statement |
| HY000 | 10300 | Could not support variable \`%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 f36e6d9edfb..7122cfe00f4 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
@@ -17,6 +17,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY004 | 10004 | Unsupported conversion data type \`%s\` for value
\`%s\` |
| HY004 | 10005 | Unsupported conversion stream charset \`%s\` |
| HY004 | 10006 | SQL String can not be NULL or empty |
+| 08000 | 10007 | Can not get %d connections one time, partition
succeed connection(%d) have released |
| HY004 | 10100 | Can not register driver, reason is: %s |
| 34000 | 10200 | Can not get cursor name from fetch statement |
| HY000 | 10300 | Could not support variable \`%s\` |
diff --git
a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
index 761d4a18bf7..bea95d6e605 100644
---
a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
+++
b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
@@ -55,7 +55,7 @@ public final class ResultSetUtil {
*/
public static Object convertValue(final Object value, final Class<?>
convertType) throws SQLException {
if (null == convertType) {
- throw new SQLException("Type cannot be null");
+ throw new SQLFeatureNotSupportedException("Type cannot be null");
}
if (null == value) {
return convertNullValue(convertType);
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/resultset/WrapperAdapter.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/resultset/WrapperAdapter.java
index f20c0ab82d7..9ae0d511e03 100644
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/resultset/WrapperAdapter.java
+++
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/resultset/WrapperAdapter.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.federation.executor.advanced.resultset;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.sql.Wrapper;
/**
@@ -31,7 +32,7 @@ public abstract class WrapperAdapter implements Wrapper {
if (isWrapperFor(iface)) {
return (T) this;
}
- throw new SQLException(String.format("[%s] cannot be unwrapped as
[%s]", getClass().getName(), iface.getName()));
+ throw new SQLFeatureNotSupportedException(String.format("`%s` cannot
be unwrapped as `%s`", getClass().getName(), iface.getName()));
}
@Override
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapter.java
index b08cd3ec31e..89b390fbf2b 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapter.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapter.java
@@ -21,6 +21,7 @@ import lombok.Getter;
import
org.apache.shardingsphere.driver.jdbc.adapter.invocation.MethodInvocationRecorder;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.sql.Wrapper;
@@ -38,7 +39,7 @@ public abstract class WrapperAdapter implements Wrapper {
if (isWrapperFor(iface)) {
return (T) this;
}
- throw new SQLException(String.format("[%s] cannot be unwrapped as
[%s]", getClass().getName(), iface.getName()));
+ throw new SQLFeatureNotSupportedException(String.format("`%s` cannot
be unwrapped as `%s`", getClass().getName(), iface.getName()));
}
@Override
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java
index ce88854e357..d625edba5d2 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/ShardingSphereSavepoint.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.driver.jdbc.core;
import java.rmi.server.UID;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.sql.Savepoint;
/**
@@ -34,14 +35,14 @@ public final class ShardingSphereSavepoint implements
Savepoint {
public ShardingSphereSavepoint(final String name) throws SQLException {
if (null == name || 0 == name.length()) {
- throw new SQLException("Savepoint name can not be NULL or empty");
+ throw new SQLFeatureNotSupportedException("Savepoint name can not
be NULL or empty");
}
savepointName = name;
}
@Override
public int getSavepointId() throws SQLException {
- throw new SQLException("Only named savepoint are supported.");
+ throw new SQLFeatureNotSupportedException("Only named savepoint are
supported.");
}
@Override
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
index 71e7cf1a814..b9f6d547f1f 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
@@ -25,6 +25,7 @@ import lombok.Getter;
import
org.apache.shardingsphere.driver.jdbc.adapter.executor.ForceExecuteTemplate;
import
org.apache.shardingsphere.driver.jdbc.adapter.invocation.MethodInvocationRecorder;
import org.apache.shardingsphere.driver.jdbc.core.ShardingSphereSavepoint;
+import
org.apache.shardingsphere.driver.jdbc.exception.OverallConnectionNotEnoughException;
import
org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
@@ -347,7 +348,7 @@ public final class ConnectionManager implements
ExecutorJDBCConnectionManager, A
for (Connection each : result) {
each.close();
}
- throw new SQLException(String.format("Can not get %d
connections one time, partition succeed connection(%d) have released!",
connectionSize, result.size()), ex);
+ throw new OverallConnectionNotEnoughException(connectionSize,
result.size()).toSQLException();
}
}
return result;
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index f36b82d7551..8ca65e194d6 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -30,6 +30,7 @@ import java.sql.Array;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.sql.Savepoint;
import java.sql.Statement;
@@ -199,7 +200,7 @@ public final class ShardingSphereConnection extends
AbstractConnectionAdapter {
public Savepoint setSavepoint(final String name) throws SQLException {
checkClose();
if (!isHoldTransaction()) {
- throw new SQLException("Savepoint can only be used in transaction
blocks.");
+ throw new SQLFeatureNotSupportedException("Savepoint can only be
used in transaction blocks.");
}
return connectionManager.setSavepoint(name);
}
@@ -208,7 +209,7 @@ public final class ShardingSphereConnection extends
AbstractConnectionAdapter {
public Savepoint setSavepoint() throws SQLException {
checkClose();
if (!isHoldTransaction()) {
- throw new SQLException("Savepoint can only be used in transaction
blocks.");
+ throw new SQLFeatureNotSupportedException("Savepoint can only be
used in transaction blocks.");
}
return connectionManager.setSavepoint();
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/resultset/WrapperAdapter.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/OverallConnectionNotEnoughException.java
similarity index 53%
copy from
shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/resultset/WrapperAdapter.java
copy to
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/OverallConnectionNotEnoughException.java
index f20c0ab82d7..6d07d8b6372 100644
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/advanced/resultset/WrapperAdapter.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/OverallConnectionNotEnoughException.java
@@ -15,27 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.federation.executor.advanced.resultset;
+package org.apache.shardingsphere.driver.jdbc.exception;
-import java.sql.SQLException;
-import java.sql.Wrapper;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
/**
- * Adapter for {@code java.sql.Wrapper}.
+ * Overall connection not enough exception.
*/
-public abstract class WrapperAdapter implements Wrapper {
+public final class OverallConnectionNotEnoughException extends
ShardingSphereSQLException {
- @SuppressWarnings("unchecked")
- @Override
- public final <T> T unwrap(final Class<T> iface) throws SQLException {
- if (isWrapperFor(iface)) {
- return (T) this;
- }
- throw new SQLException(String.format("[%s] cannot be unwrapped as
[%s]", getClass().getName(), iface.getName()));
- }
+ private static final long serialVersionUID = -1297088138042287804L;
- @Override
- public final boolean isWrapperFor(final Class<?> iface) {
- return iface.isInstance(this);
+ public OverallConnectionNotEnoughException(final int desiredSize, final
int actualSize) {
+ super(XOpenSQLState.CONNECTION_EXCEPTION.getValue(), 10007, "Can not
get %d connections one time, partition succeed connection(%d) have released",
desiredSize, actualSize);
}
}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
index 04a8d4d0d18..281d4fd9010 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
@@ -225,7 +225,7 @@ public final class ConnectionManagerTest {
try {
connectionManager.getConnections("invalid_ds", 3,
ConnectionMode.CONNECTION_STRICTLY);
} catch (final SQLException ex) {
- assertThat(ex.getMessage(), is("Can not get 3 connections one
time, partition succeed connection(0) have released!"));
+ assertThat(ex.getMessage(), is("Can not get 3 connections one
time, partition succeed connection(0) have released"));
}
}
}