diff --git a/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/ConnectionManager.java b/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/ConnectionManager.java index 38299081d8..215d866920 100644 --- a/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/ConnectionManager.java +++ b/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/ConnectionManager.java @@ -19,6 +19,7 @@ import org.apache.linkis.common.utils.SecurityUtils; import org.apache.linkis.hadoop.common.utils.KerberosUtils; +import org.apache.linkis.manager.engineplugin.jdbc.conf.JDBCConfiguration$; import org.apache.linkis.manager.engineplugin.jdbc.constant.JDBCEngineConnConstant; import org.apache.linkis.manager.engineplugin.jdbc.exception.JDBCParamsIllegalException; import org.apache.linkis.manager.engineplugin.jdbc.utils.JdbcParamUtils; @@ -187,6 +188,16 @@ protected DataSource buildDataSource(String dbUrl, Map propertie JDBCPropertiesParser.getInt( properties, JDBCEngineConnConstant.JDBC_POOL_REMOVE_ABANDONED_TIMEOUT, 300); + int connectionTimeout = + JDBCPropertiesParser.getInt( + properties, JDBCEngineConnConstant.JDBC_CONNECTION_TIMEOUT, 0); + int socketTimeout = + JDBCPropertiesParser.getInt( + properties, JDBCEngineConnConstant.JDBC_SOCKET_TIMEOUT, 0); + int queryTimeout = + JDBCPropertiesParser.getInt( + properties, JDBCConfiguration$.MODULE$.JDBC_QUERY_TIMEOUT().key(), 0); + DruidDataSource datasource = new DruidDataSource(); LOG.info("Database connection address information(数据库连接地址信息)=" + dbUrl); datasource.setUrl(dbUrl); @@ -207,6 +218,15 @@ protected DataSource buildDataSource(String dbUrl, Map propertie datasource.setPoolPreparedStatements(poolPreparedStatements); datasource.setRemoveAbandoned(removeAbandoned); datasource.setRemoveAbandonedTimeout(removeAbandonedTimeout); + if (connectionTimeout > 0) { + datasource.setConnectTimeout(connectionTimeout); + } + if (socketTimeout > 0) { + datasource.setSocketTimeout(socketTimeout); + } + if (queryTimeout > 0) { + datasource.setQueryTimeout(queryTimeout); + } return datasource; } diff --git a/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/constant/JDBCEngineConnConstant.java b/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/constant/JDBCEngineConnConstant.java index 9e19ea9f50..16f6a7e324 100644 --- a/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/constant/JDBCEngineConnConstant.java +++ b/linkis-engineconn-plugins/jdbc/src/main/java/org/apache/linkis/manager/engineplugin/jdbc/constant/JDBCEngineConnConstant.java @@ -34,6 +34,11 @@ private JDBCEngineConnConstant() {} "wds.linkis.jdbc.auth.kerberos.proxy.enable"; public static final String JDBC_PROXY_USER_PROPERTY = "wds.linkis.jdbc.proxy.user.property"; public static final String JDBC_PROXY_USER = "wds.linkis.jdbc.proxy.user"; + + public static final String JDBC_CONNECTION_TIMEOUT = "wds.linkis.jdbc.connection.timeout"; + + public static final String JDBC_SOCKET_TIMEOUT = "wds.linkis.jdbc.socket.timeout"; + public static final String JDBC_SCRIPTS_EXEC_USER = "execUser"; public static final String JDBC_ENGINE_RUN_TIME_DS = "wds.linkis.engine.runtime.datasource"; public static final String JDBC_ENGINE_RUN_TIME_DS_MAX_VERSION_ID = diff --git a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala index 8a2d64fa76..240fed100f 100644 --- a/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala +++ b/linkis-engineconn-plugins/jdbc/src/main/scala/org/apache/linkis/manager/engineplugin/jdbc/executor/JDBCEngineConnExecutor.scala @@ -146,7 +146,9 @@ class JDBCEngineConnExecutor(override val outputPrintLimit: Int, val id: Int) try { statement = connection.createStatement() - statement.setQueryTimeout(JDBCConfiguration.JDBC_QUERY_TIMEOUT.getValue) + if (statement.getQueryTimeout == 0) { + statement.setQueryTimeout(JDBCConfiguration.JDBC_QUERY_TIMEOUT.getValue) + } statement.setFetchSize(outputPrintLimit) statement.setMaxRows(outputPrintLimit)