This is an automated email from the ASF dual-hosted git repository.
Caideyipi pushed a commit to branch codex/jdbc-driver-info
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/codex/jdbc-driver-info by this
push:
new 14c92f38b07 Improve JDBC DataSource standard behavior
14c92f38b07 is described below
commit 14c92f38b07d7902b63e3c991e7479cbc44ed098
Author: Caideyipi <[email protected]>
AuthorDate: Mon Jun 8 17:56:12 2026 +0800
Improve JDBC DataSource standard behavior
---
.../org/apache/iotdb/jdbc/IoTDBDataSource.java | 18 +++++++-----
.../iotdb/jdbc/IoTDBDataSourceFactoryTest.java | 34 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 7 deletions(-)
diff --git
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDataSource.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDataSource.java
index 25c6d02c65c..c3f880565a3 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDataSource.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDataSource.java
@@ -28,6 +28,7 @@ import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
public class IoTDBDataSource implements DataSource {
@@ -99,13 +100,13 @@ public class IoTDBDataSource implements DataSource {
}
@Override
- public Connection getConnection(String username, String password) {
+ public Connection getConnection(String username, String password) throws
SQLException {
try {
Properties newProp = new Properties();
setProperty(newProp, Config.AUTH_USER, username);
setProperty(newProp, Config.AUTH_PASSWORD, password);
return new IoTDBConnection(url, newProp);
- } catch (Exception e) {
+ } catch (TTransportException e) {
LOGGER.error(JdbcMessages.GET_CONNECTION_ERROR, e);
}
return null;
@@ -132,18 +133,21 @@ public class IoTDBDataSource implements DataSource {
}
@Override
- public java.util.logging.Logger getParentLogger() {
- return null;
+ public java.util.logging.Logger getParentLogger() throws
SQLFeatureNotSupportedException {
+ throw new
SQLFeatureNotSupportedException(JdbcMessages.METHOD_NOT_SUPPORTED);
}
@Override
- public <T> T unwrap(Class<T> aClass) {
- return null;
+ public <T> T unwrap(Class<T> aClass) throws SQLException {
+ if (isWrapperFor(aClass)) {
+ return aClass.cast(this);
+ }
+ throw new SQLException(JdbcMessages.CANNOT_UNWRAP_TO + aClass);
}
@Override
public boolean isWrapperFor(Class<?> aClass) {
- return false;
+ return aClass != null && aClass.isInstance(this);
}
private void setProperty(String key, String value) {
diff --git
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBDataSourceFactoryTest.java
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBDataSourceFactoryTest.java
index cad6cf80a3c..f4073b24003 100644
---
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBDataSourceFactoryTest.java
+++
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBDataSourceFactoryTest.java
@@ -24,10 +24,14 @@ import org.osgi.service.jdbc.DataSourceFactory;
import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class IoTDBDataSourceFactoryTest {
@@ -78,4 +82,34 @@ public class IoTDBDataSourceFactoryTest {
assertEquals(Integer.valueOf(6667), dataSource.getPort());
}
+
+ @Test
+ public void testDataSourceWrapperMethods() throws SQLException {
+ IoTDBDataSource dataSource = new IoTDBDataSource();
+
+ assertTrue(dataSource.isWrapperFor(IoTDBDataSource.class));
+ assertTrue(dataSource.isWrapperFor(DataSource.class));
+ assertFalse(dataSource.isWrapperFor(String.class));
+ assertFalse(dataSource.isWrapperFor(null));
+ assertSame(dataSource, dataSource.unwrap(IoTDBDataSource.class));
+ assertSame(dataSource, dataSource.unwrap(DataSource.class));
+ }
+
+ @Test(expected = SQLException.class)
+ public void testDataSourceUnwrapRejectsUnsupportedClass() throws
SQLException {
+ new IoTDBDataSource().unwrap(String.class);
+ }
+
+ @Test(expected = SQLFeatureNotSupportedException.class)
+ public void testDataSourceParentLoggerIsUnsupported() throws SQLException {
+ new IoTDBDataSource().getParentLogger();
+ }
+
+ @Test(expected = SQLException.class)
+ public void testDataSourceConnectionWithCredentialsThrowsInvalidUrl() throws
SQLException {
+ IoTDBDataSource dataSource = new IoTDBDataSource();
+
+ dataSource.setUrl("jdbc:iotdb://test");
+ dataSource.getConnection("root", "root");
+ }
}