Caideyipi commented on code in PR #17865:
URL: https://github.com/apache/iotdb/pull/17865#discussion_r4373563380


##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java:
##########
@@ -722,49 +818,97 @@ public int getResultSetType() throws SQLException {
   }
 
   @Override
-  public int getUpdateCount() {
+  public int getUpdateCount() throws SQLException {
+    checkConnection("getUpdateCount");
     return -1;
   }
 
   @Override
-  public SQLWarning getWarnings() {
+  public SQLWarning getWarnings() throws SQLException {
+    checkConnection("getWarnings");
     return warningChain;
   }
 
   @Override
   public boolean isCloseOnCompletion() throws SQLException {
-    throw new SQLException(JdbcMessages.NOT_SUPPORT_IS_CLOSE_ON_COMPLETION);
+    throw unsupportedOperation(
+        "isCloseOnCompletion", 
JdbcMessages.NOT_SUPPORT_IS_CLOSE_ON_COMPLETION);
   }
 
   @Override
   public boolean isClosed() {
-    return isClosed;
+    return isClosed || connection == null || connection.isClosed();
   }
 
   @Override
   public boolean isPoolable() throws SQLException {
-    throw new SQLException(JdbcMessages.NOT_SUPPORT_IS_POOLABLE);
+    throw unsupportedOperation("isPoolable", 
JdbcMessages.NOT_SUPPORT_IS_POOLABLE);
   }
 
   @Override
   public void setPoolable(boolean arg0) throws SQLException {
-    throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_POOLABLE);
+    throw unsupportedOperation("setPoolable", 
JdbcMessages.NOT_SUPPORT_SET_POOLABLE);
   }
 
   @Override
   public void setCursorName(String arg0) throws SQLException {
-    throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_CURSOR_NAME);
+    throw unsupportedOperation("setCursorName", 
JdbcMessages.NOT_SUPPORT_SET_CURSOR_NAME);
   }
 
   @Override
   public void setEscapeProcessing(boolean enable) throws SQLException {
-    throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_ESCAPE_PROCESSING);
+    throw unsupportedOperation(
+        "setEscapeProcessing", JdbcMessages.NOT_SUPPORT_SET_ESCAPE_PROCESSING);
   }
 
-  private void checkConnection(String action) throws SQLException {
+  protected void checkConnection(String action) throws SQLException {
     if (connection == null || connection.isClosed()) {
       throw new 
SQLException(String.format(JdbcMessages.CANNOT_AFTER_CONNECTION_CLOSED, 
action));
     }
+    if (isClosed) {
+      throw new SQLException(String.format(CANNOT_AFTER_STATEMENT_CLOSED, 
action));
+    }
+  }
+
+  protected void closeCurrentResultSet() throws SQLException {
+    if (resultSet != null) {
+      ResultSet currentResultSet = resultSet;

Review Comment:
   [P2] Retain failed query cleanup before reusing the statement
   
   If closing the current ResultSet fails, this method discards its reference 
before cleanup succeeds. ResultSet.close() also refuses subsequent cleanup 
attempts, so the next execution can overwrite the old query ID without 
releasing that query. Retain the ResultSet until successful cleanup, allow 
close retries while continuing to reject reads, and retry any pending query 
cleanup after result-set construction fails.



##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java:
##########
@@ -51,6 +51,9 @@ private Config() {
   static final int RETRY_NUM = 3;
   static final long RETRY_INTERVAL_MS = 1000;
 
+  static final int DRIVER_MAJOR_VERSION = 4;

Review Comment:
   [P2] Report the driver build version separately from the JDBC API version
   
   The artifact is 2.0.11-SNAPSHOT, but 
Driver.getMajorVersion()/getMinorVersion() report 4.3. Those methods describe 
the driver release; getJDBCMajorVersion()/getJDBCMinorVersion() already 
describe JDBC 4.3. Read the release from a Maven-filtered resource and share it 
with both database metadata implementations.



##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -786,119 +853,135 @@ public Time getTime(String columnName) throws 
SQLException {
 
   @Override
   public Time getTime(int arg0, Calendar arg1) throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public Time getTime(String arg0, Calendar arg1) throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public Timestamp getTimestamp(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getTimestamp(columnIndex);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
   public Timestamp getTimestamp(String columnName) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getTimestamp(columnName);
-    } catch (StatementExecutionException | IllegalArgumentException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
   public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public Timestamp getTimestamp(String arg0, Calendar arg1) throws 
SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
-  public int getType() {
+  public int getType() throws SQLException {
+    checkOpen();
     return ResultSet.TYPE_FORWARD_ONLY;
   }
 
   @Override
   public URL getURL(int arg0) throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public URL getURL(String arg0) throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public InputStream getUnicodeStream(int arg0) throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public InputStream getUnicodeStream(String arg0) throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
-  public SQLWarning getWarnings() {
+  public SQLWarning getWarnings() throws SQLException {
+    checkOpen();
     return warningChain;
   }
 
   @Override
   public void insertRow() throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public boolean isAfterLast() throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public boolean isBeforeFirst() throws SQLException {
-    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+    throw unsupportedOperation();
   }
 
   @Override
   public boolean isClosed() {
-    return ioTDBRpcDataSet.isClosed();
+    return explicitlyClosed;
+  }
+
+  private void checkOpen() throws SQLException {
+    if (explicitlyClosed) {
+      throw new SQLException("ResultSet has been closed");

Review Comment:
   [P2] Localize the newly added JDBC messages
   
   The new ResultSet/Statement/parameter/URL validation errors and 
DriverPropertyInfo descriptions use inline English strings. Under 
with-zh-locale these new paths remain English, contrary to the repository's 
i18n requirement. Move the complete messages to matching en/zh JdbcMessages 
constants and make the affected assertions locale-independent.



##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDriver.java:
##########
@@ -90,13 +97,87 @@ public Logger getParentLogger() throws 
SQLFeatureNotSupportedException {
   }
 
   @Override
-  public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
-    // TODO Auto-generated method stub
-    return new DriverPropertyInfo[0];
+  public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) 
throws SQLException {
+    Properties properties = info == null ? new Properties() : (Properties) 
info.clone();
+    if (url != null && acceptsURL(url)) {
+      Utils.parseUrl(url, properties);
+    }
+    return new DriverPropertyInfo[] {
+      createProperty(
+          Config.AUTH_USER, Config.DEFAULT_USER, "User name for 
authentication.", properties),
+      createSensitiveProperty(Config.AUTH_PASSWORD, "Password for 
authentication."),
+      createProperty(
+          Config.DEFAULT_BUFFER_CAPACITY,
+          String.valueOf(RpcUtils.THRIFT_DEFAULT_BUF_CAPACITY),
+          "Thrift default buffer capacity in bytes.",
+          properties),
+      createProperty(
+          Config.THRIFT_FRAME_MAX_SIZE,
+          String.valueOf(RpcUtils.THRIFT_FRAME_MAX_SIZE),
+          "Thrift max frame size in bytes.",
+          properties),
+      createProperty(
+          Config.VERSION,
+          Config.DEFAULT_VERSION.name(),
+          VERSION_CHOICES,
+          "Client compatibility version.",
+          properties),
+      createProperty(
+          Config.NETWORK_TIMEOUT,
+          String.valueOf(Config.DEFAULT_CONNECTION_TIMEOUT_MS),
+          "Network timeout in milliseconds.",
+          properties),
+      createProperty(
+          Config.TIME_ZONE, ZoneId.systemDefault().toString(), "Connection 
time zone.", properties),
+      createProperty(
+          Config.CHARSET, TSFileConfig.STRING_CHARSET.name(), "Connection 
charset.", properties),
+      createProperty(
+          Config.USE_SSL, "false", BOOLEAN_CHOICES, "Whether to enable SSL.", 
properties),
+      createProperty(
+          Utils.RPC_COMPRESS,
+          String.valueOf(Config.rpcThriftCompressionEnable),
+          BOOLEAN_CHOICES,
+          "Whether to enable RPC thrift compression.",
+          properties),
+      createProperty(Config.TRUST_STORE, null, "SSL trust store path.", 
properties),
+      createSensitiveProperty(Config.TRUST_STORE_PWD, "SSL trust store 
password."),

Review Comment:
   [P2] Include the supported client-key and protocol properties
   
   The parser and connection now support key_store, key_store_pwd and 
ssl_protocol, but getPropertyInfo() omits all three. JDBC tools that build 
their configuration UI from this metadata cannot discover the client 
certificate settings or protocol selection. Include these properties and keep 
the key-store password value redacted.



##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDataSource.java:
##########
@@ -89,61 +154,110 @@ public void setUrl(String url) {
     this.url = url;
   }
 
+  String getConnectionProperty(String key) {
+    return properties.getProperty(key);
+  }
+
+  void setConnectionProperty(String key, String value) {
+    setProperty(key, value);
+  }
+
   @Override
   public Connection getConnection() throws SQLException {
-    try {
-      return new IoTDBConnection(url, properties);
-    } catch (TTransportException e) {
-      LOGGER.error(JdbcMessages.GET_CONNECTION_ERROR, e);
-    }
-    return null;
+    return createConnection((Properties) properties.clone());
   }
 
   @Override
-  public Connection getConnection(String username, String password) {
-    try {
-      Properties newProp = new Properties();
-      newProp.setProperty("user", username);
-      newProp.setProperty(PWD_STR, password);
-      return new IoTDBConnection(url, newProp);
-    } catch (Exception e) {
-      LOGGER.error(JdbcMessages.GET_CONNECTION_ERROR, e);
-    }
-    return null;
+  public Connection getConnection(String username, String password) throws 
SQLException {
+    Properties newProp = (Properties) properties.clone();
+    setProperty(newProp, Config.AUTH_USER, username);
+    setProperty(newProp, Config.AUTH_PASSWORD, password);
+    return createConnection(newProp);
   }
 
   @Override
   public PrintWriter getLogWriter() {
-    return null;
+    return logWriter;
   }
 
   @Override
   public void setLogWriter(PrintWriter printWriter) {
-    // Do nothing
+    this.logWriter = printWriter;
   }
 
   @Override
-  public void setLoginTimeout(int i) {
-    // Do nothing
+  public void setLoginTimeout(int i) throws SQLException {
+    if (i < 0) {
+      throw new SQLException("loginTimeout must be >= 0");
+    }
+    this.loginTimeout = i;
   }
 
   @Override
   public int getLoginTimeout() {
-    return 0;
+    return loginTimeout;
   }
 
   @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 {
+    return JdbcWrapperUtils.unwrap(this, aClass);
   }
 
   @Override
   public boolean isWrapperFor(Class<?> aClass) {
-    return false;
+    return JdbcWrapperUtils.isWrapperFor(this, aClass);
+  }
+
+  private Connection createConnection(Properties connectionProperties) throws 
SQLException {
+    applyLoginTimeout(connectionProperties);

Review Comment:
   [P2] Keep the login timeout from becoming the query socket timeout
   
   setLoginTimeout(2) currently injects network_timeout=2000, so the returned 
connection retains a two-second read timeout and later queries can time out 
even though login completed successfully. Apply this limit during 
connection/session establishment, then restore the separately configured 
network timeout.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to