This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 68a3800080f Remove immature JDBC impl on ShardingSphereConnection
(#31721)
68a3800080f is described below
commit 68a3800080f228cbf9db5015986c405f7726ec8b
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jun 16 23:07:59 2024 +0800
Remove immature JDBC impl on ShardingSphereConnection (#31721)
* Refactor ShardingSphereConnection
* Remove immature JDBC impl on ShardingSphereConnection
---
.../core/connection/ShardingSphereConnection.java | 31 ----------------------
.../AbstractUnsupportedOperationConnection.java | 28 +++++++++++++++++++
.../connection/CircuitBreakerConnection.java | 16 -----------
.../UnsupportedOperationConnectionTest.java | 20 ++++++++++++++
4 files changed, 48 insertions(+), 47 deletions(-)
diff --git
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index 503c2a3d42a..cf302ac963d 100644
---
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -36,9 +36,6 @@ import org.apache.shardingsphere.traffic.rule.TrafficRule;
import org.apache.shardingsphere.transaction.api.TransactionType;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import java.sql.Array;
-import java.sql.CallableStatement;
-import java.sql.Clob;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -185,24 +182,6 @@ public final class ShardingSphereConnection extends
AbstractConnectionAdapter {
return new ShardingSphereStatement(this, resultSetType,
resultSetConcurrency, resultSetHoldability);
}
- @Override
- public CallableStatement prepareCall(final String sql) throws SQLException
{
- // TODO Support single DataSource scenario for now. Implement
ShardingSphereCallableStatement to support multi DataSource scenarios.
- return
databaseConnectionManager.getRandomConnection().prepareCall(sql);
- }
-
- @Override
- public CallableStatement prepareCall(final String sql, final int
resultSetType, final int resultSetConcurrency) throws SQLException {
- // TODO Support single DataSource scenario for now. Implement
ShardingSphereCallableStatement to support multi DataSource scenarios.
- return
databaseConnectionManager.getRandomConnection().prepareCall(sql, resultSetType,
resultSetConcurrency);
- }
-
- @Override
- public CallableStatement prepareCall(final String sql, final int
resultSetType, final int resultSetConcurrency, final int resultSetHoldability)
throws SQLException {
- // TODO Support single DataSource scenario for now. Implement
ShardingSphereCallableStatement to support multi DataSource scenarios.
- return
databaseConnectionManager.getRandomConnection().prepareCall(sql, resultSetType,
resultSetConcurrency, resultSetHoldability);
- }
-
@Override
public boolean getAutoCommit() {
return autoCommit;
@@ -327,16 +306,6 @@ public final class ShardingSphereConnection extends
AbstractConnectionAdapter {
return databaseConnectionManager.isValid(timeout);
}
- @Override
- public Clob createClob() throws SQLException {
- return databaseConnectionManager.getRandomConnection().createClob();
- }
-
- @Override
- public Array createArrayOf(final String typeName, final Object[] elements)
throws SQLException {
- return
databaseConnectionManager.getRandomConnection().createArrayOf(typeName,
elements);
- }
-
@Override
public String getSchema() {
// TODO return databaseName for now in getSchema(), the same as before
diff --git
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationConnection.java
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationConnection.java
index f62e3b5c7d6..a439450835f 100644
---
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationConnection.java
+++
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationConnection.java
@@ -20,7 +20,10 @@ package org.apache.shardingsphere.driver.jdbc.unsupported;
import org.apache.shardingsphere.driver.jdbc.adapter.WrapperAdapter;
import
org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
+import java.sql.Array;
import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.NClob;
import java.sql.SQLException;
@@ -36,6 +39,21 @@ import java.util.concurrent.Executor;
*/
public abstract class AbstractUnsupportedOperationConnection extends
WrapperAdapter implements Connection {
+ @Override
+ public final CallableStatement prepareCall(final String sql) throws
SQLException {
+ throw new SQLFeatureNotSupportedException("prepareCall");
+ }
+
+ @Override
+ public final CallableStatement prepareCall(final String sql, final int
resultSetType, final int resultSetConcurrency) throws SQLException {
+ throw new SQLFeatureNotSupportedException("prepareCall");
+ }
+
+ @Override
+ public final CallableStatement prepareCall(final String sql, final int
resultSetType, final int resultSetConcurrency, final int resultSetHoldability)
throws SQLException {
+ throw new SQLFeatureNotSupportedException("prepareCall");
+ }
+
@Override
public final String nativeSQL(final String sql) throws SQLException {
throw new SQLFeatureNotSupportedException("nativeSQL");
@@ -66,11 +84,21 @@ public abstract class
AbstractUnsupportedOperationConnection extends WrapperAdap
throw new SQLFeatureNotSupportedException("setNetworkTimeout");
}
+ @Override
+ public Array createArrayOf(final String typeName, final Object[] elements)
throws SQLException {
+ throw new SQLFeatureNotSupportedException("createArrayOf");
+ }
+
@Override
public final Blob createBlob() throws SQLException {
throw new SQLFeatureNotSupportedException("createBlob");
}
+ @Override
+ public Clob createClob() throws SQLException {
+ throw new SQLFeatureNotSupportedException("createClob");
+ }
+
@Override
public final NClob createNClob() throws SQLException {
throw new SQLFeatureNotSupportedException("createNClob");
diff --git
a/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnection.java
b/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnection.java
index e075e34da4d..0dad66ec20c 100644
---
a/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnection.java
+++
b/jdbc/src/main/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnection.java
@@ -23,7 +23,6 @@ import
org.apache.shardingsphere.driver.state.circuit.statement.CircuitBreakerPr
import
org.apache.shardingsphere.driver.state.circuit.statement.CircuitBreakerStatement;
import java.sql.Array;
-import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -156,21 +155,6 @@ public final class CircuitBreakerConnection extends
AbstractUnsupportedOperation
return new CircuitBreakerPreparedStatement();
}
- @Override
- public CallableStatement prepareCall(final String sql) throws SQLException
{
- throw new SQLFeatureNotSupportedException("prepareCall");
- }
-
- @Override
- public CallableStatement prepareCall(final String sql, final int
resultSetType, final int resultSetConcurrency) throws SQLException {
- throw new SQLFeatureNotSupportedException("prepareCall");
- }
-
- @Override
- public CallableStatement prepareCall(final String sql, final int
resultSetType, final int resultSetConcurrency, final int resultSetHoldability)
throws SQLException {
- throw new SQLFeatureNotSupportedException("prepareCall");
- }
-
@Override
public boolean isValid(final int timeout) {
return true;
diff --git
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
index dd7543d384b..b4fd5c0dbc5 100644
---
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
+++
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.traffic.rule.TrafficRule;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
import org.junit.jupiter.api.Test;
+import java.sql.ResultSet;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Arrays;
import java.util.Properties;
@@ -46,6 +47,15 @@ class UnsupportedOperationConnectionTest {
shardingSphereConnection = new
ShardingSphereConnection(DefaultDatabase.LOGIC_NAME, contextManager);
}
+ @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed")
+ @Test
+ void assertPrepareCall() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
shardingSphereConnection.prepareCall("foo_call"));
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
shardingSphereConnection.prepareCall("foo_call", ResultSet.FETCH_FORWARD,
ResultSet.CONCUR_READ_ONLY));
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
shardingSphereConnection.prepareCall("foo_call",
+ ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT));
+ }
+
@Test
void assertNativeSQL() {
assertThrows(SQLFeatureNotSupportedException.class, () ->
shardingSphereConnection.nativeSQL(""));
@@ -76,11 +86,21 @@ class UnsupportedOperationConnectionTest {
assertThrows(SQLFeatureNotSupportedException.class, () ->
shardingSphereConnection.setNetworkTimeout(null, 0));
}
+ @Test
+ void assertCreateArrayOf() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
shardingSphereConnection.createArrayOf("", null));
+ }
+
@Test
void assertCreateBlob() {
assertThrows(SQLFeatureNotSupportedException.class,
shardingSphereConnection::createBlob);
}
+ @Test
+ void assertCreateClob() {
+ assertThrows(SQLFeatureNotSupportedException.class,
shardingSphereConnection::createClob);
+ }
+
@Test
void assertCreateNClob() {
assertThrows(SQLFeatureNotSupportedException.class,
shardingSphereConnection::createNClob);