diff --git a/packaging/cfg/nginxd.service b/packaging/cfg/nginxd.service new file mode 100644 index 0000000000000000000000000000000000000000..50bbc1a21de5e6645404ec1d4e9bcd6f177f69d2 --- /dev/null +++ b/packaging/cfg/nginxd.service @@ -0,0 +1,22 @@ +[Unit] +Description=Nginx For TDengine Service +After=network-online.target +Wants=network-online.target + +[Service] +Type=forking +PIDFile=/usr/local/nginxd/logs/nginx.pid +ExecStart=/usr/local/nginxd/sbin/nginx +ExecStop=/usr/local/nginxd/sbin/nginx -s stop +TimeoutStopSec=1000000s +LimitNOFILE=infinity +LimitNPROC=infinity +LimitCORE=infinity +TimeoutStartSec=0 +StandardOutput=null +Restart=always +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target diff --git a/packaging/cfg/taosd.service b/packaging/cfg/taosd.service new file mode 100644 index 0000000000000000000000000000000000000000..fff4b74e62a6da8f2bda9a6306a79132d7585e42 --- /dev/null +++ b/packaging/cfg/taosd.service @@ -0,0 +1,21 @@ +[Unit] +Description=TDengine server service +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/bin/taosd +ExecStartPre=/usr/local/taos/bin/startPre.sh +TimeoutStopSec=1000000s +LimitNOFILE=infinity +LimitNPROC=infinity +LimitCORE=infinity +TimeoutStartSec=0 +StandardOutput=null +Restart=always +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target diff --git a/packaging/cfg/tarbitratord.service b/packaging/cfg/tarbitratord.service new file mode 100644 index 0000000000000000000000000000000000000000..d60cb536b094fe6b6c472d55076dc4d1db669d68 --- /dev/null +++ b/packaging/cfg/tarbitratord.service @@ -0,0 +1,20 @@ +[Unit] +Description=TDengine arbitrator service +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/bin/tarbitrator +TimeoutStopSec=1000000s +LimitNOFILE=infinity +LimitNPROC=infinity +LimitCORE=infinity +TimeoutStartSec=0 +StandardOutput=null +Restart=always +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target diff --git a/packaging/release.sh b/packaging/release.sh index 8049e974b807363c856f63eebe026c74c6972c0a..19a0a7702bb25bf60efd9bff4af166a1336d721f 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -14,6 +14,7 @@ set -e # -d [taos | power | tq | pro | kh | jh] # -n [2.0.0.3] # -m [2.0.0.0] +# -H [ false | true] # set parameters by default value verMode=edge # [cluster, edge] @@ -26,8 +27,9 @@ dbName=taos # [taos | power | tq | pro | kh | jh] allocator=glibc # [glibc | jemalloc] verNumber="" verNumberComp="1.0.0.0" +httpdBuild=false -while getopts "hv:V:c:o:l:s:d:a:n:m:" arg +while getopts "hv:V:c:o:l:s:d:a:n:m:H:" arg do case $arg in v) @@ -70,6 +72,10 @@ do #echo "osType=$OPTARG" osType=$(echo $OPTARG) ;; + H) + #echo "httpdBuild=$OPTARG" + httpdBuild=$(echo $OPTARG) + ;; h) echo "Usage: `basename $0` -v [cluster | edge] " echo " -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] " @@ -81,6 +87,7 @@ do echo " -d [taos | power | tq | pro | kh | jh] " echo " -n [version number] " echo " -m [compatible version number] " + echo " -H [false | true] " exit 0 ;; ?) #unknow option @@ -90,7 +97,7 @@ do esac done -echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} soMode=${soMode} dbName=${dbName} allocator=${allocator} verNumber=${verNumber} verNumberComp=${verNumberComp}" +echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} soMode=${soMode} dbName=${dbName} allocator=${allocator} verNumber=${verNumber} verNumberComp=${verNumberComp} httpdBuild=${httpdBuild}" curr_dir=$(pwd) @@ -405,8 +412,7 @@ if [[ "$dbName" == "jh" ]]; then # TODO: src/dnode/CMakeLists.txt fi -echo "build ${pagMode} package ..." -if [[ "$pagMode" == "lite" ]]; then +if [[ "$httpdBuild" == "true" ]]; then BUILD_HTTP=true BUILD_TOOLS=false else diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index c0377cf8345b66ed8d588a6b36a4b7cdcdba028d..284926625f869d7ea82a800f4c470a83e2840404 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -700,78 +700,93 @@ function clean_service_on_systemd() { function install_service_on_systemd() { clean_service_on_systemd - taosd_service_config="${service_config_dir}/taosd.service" - ${csudo} bash -c "echo '[Unit]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'StartLimitIntervalSec=60s' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" + [ -f ${script_dir}/cfg/taosd.service ] &&\ + ${csudo} cp ${script_dir}/cfg/taosd.service \ + ${service_config_dir}/ || : + ${csudo} systemctl daemon-reload + + #taosd_service_config="${service_config_dir}/taosd.service" + #${csudo} bash -c "echo '[Unit]' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" + #${csudo} bash -c "echo >> ${taosd_service_config}" + #${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" + ##${csudo} bash -c "echo 'StartLimitIntervalSec=60s' >> ${taosd_service_config}" + #${csudo} bash -c "echo >> ${taosd_service_config}" + #${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}" + #${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" ${csudo} systemctl enable taosd - tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=TDengine arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + [ -f ${script_dir}/cfg/tarbitratord.service ] &&\ + ${csudo} cp ${script_dir}/cfg/tarbitratord.service \ + ${service_config_dir}/ || : + ${csudo} systemctl daemon-reload + + #tarbitratord_service_config="${service_config_dir}/tarbitratord.service" + #${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'Description=TDengine arbitrator service' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + #${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" #${csudo} systemctl enable tarbitratord if [ "$verMode" == "cluster" ]; then - nginx_service_config="${service_config_dir}/nginxd.service" - ${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Description=Nginx For TDengine Service' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" + [ -f ${script_dir}/cfg/nginxd.service ] &&\ + ${csudo} cp ${script_dir}/cfg/nginxd.service \ + ${service_config_dir}/ || : + ${csudo} systemctl daemon-reload + + #nginx_service_config="${service_config_dir}/nginxd.service" + #${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'Description=Nginx For TDengine Service' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" + #${csudo} bash -c "echo >> ${nginx_service_config}" + #${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" + #${csudo} bash -c "echo >> ${nginx_service_config}" + #${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" + #${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" if ! ${csudo} systemctl enable nginxd &> /dev/null; then ${csudo} systemctl daemon-reexec ${csudo} systemctl enable nginxd diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 0f226dbb21232047ba0c19d2141958c2111f8c57..c9555291bc77828da336c6bfe9c6215f208ff178 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -86,6 +86,16 @@ if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then cp ${compile_dir}/test/cfg/taosadapter.service ${install_dir}/cfg || : fi +if [ -f "${cfg_dir}/taosd.service" ]; then + cp ${cfg_dir}/taosd.service ${install_dir}/cfg || : +fi +if [ -f "${cfg_dir}/tarbitratord.service" ]; then + cp ${cfg_dir}/tarbitratord.service ${install_dir}/cfg || : +fi +if [ -f "${cfg_dir}/nginxd.service" ]; then + cp ${cfg_dir}/nginxd.service ${install_dir}/cfg || : +fi + mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || : mkdir -p ${install_dir}/init.d && cp ${init_file_deb} ${install_dir}/init.d/taosd.deb mkdir -p ${install_dir}/init.d && cp ${init_file_rpm} ${install_dir}/init.d/taosd.rpm diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java index c992cf58ba43eb0e052d9bc80824d94e98b725ca..15695ae9204c40db16c9f4d367c80a285335cbef 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java @@ -107,16 +107,6 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti public void setCatalog(String catalog) throws SQLException { if (isClosed()) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); - /* - try (Statement stmt = createStatement()) { - boolean execute = stmt.execute("use " + catalog); - if (execute) - this.catalog = catalog; - } catch (SQLException e) { - // do nothing - } - */ - this.catalog = catalog; } @@ -416,7 +406,6 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti } catch (InterruptedException | ExecutionException ignored) { } catch (TimeoutException e) { future.cancel(true); - status = false; } finally { executor.shutdownNow(); } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java index 8cd8da6de4f7d5324afbc6d5a5d54d6b8dcc7a8d..77a97d644ca3da3a51bce021ab7904883ed885f4 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java @@ -1,17 +1,3 @@ -/*************************************************************************** - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - *****************************************************************************/ package com.taosdata.jdbc; import java.sql.*; @@ -66,7 +52,7 @@ public class TSDBConnection extends AbstractConnection { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); } - long id = this.connector.subscribe(topic, sql, restart, 0); + long id = this.connector.subscribe(topic, sql, restart); if (id == 0) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED); } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java index 0fef64a6f82706e30677ad4e74604924c5cc2e60..00eff99f45cb6aa8cc0fbc7bce40e0d82f401e05 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java @@ -1,23 +1,8 @@ -/*************************************************************************** - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - *****************************************************************************/ package com.taosdata.jdbc; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.sql.*; -import java.util.*; +import java.util.Properties; +import java.util.StringTokenizer; import java.util.logging.Logger; /** @@ -139,7 +124,7 @@ public class TSDBDriver extends AbstractDriver { } catch (SQLException sqlEx) { throw sqlEx; } catch (Exception ex) { - throw new SQLException("SQLException:" + ex.toString(), ex); + throw new SQLException("SQLException:" + ex, ex); } } @@ -152,7 +137,7 @@ public class TSDBDriver extends AbstractDriver { public boolean acceptsURL(String url) throws SQLException { if (url == null) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET); - return url.length() > 0 && url.trim().length() > 0 && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1)); + return url.trim().length() > 0 && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1)); } public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index ee2c8141a81bb9dc2aa51ba14247dfbb834ec746..247ae929dabc9aba4d50309433a9b1866125909d 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -1,19 +1,3 @@ -/** - * ************************************************************************* - * Copyright (c) 2019 TAOS Data, Inc. - *

- * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - *

- * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - *

- * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * *************************************************************************** - */ package com.taosdata.jdbc; import com.alibaba.fastjson.JSONObject; @@ -261,8 +245,8 @@ public class TSDBJNIConnector { /** * Create a subscription */ - long subscribe(String topic, String sql, boolean restart, int period) { - return subscribeImp(this.taos, restart, topic, sql, period); + long subscribe(String topic, String sql, boolean restart) { + return subscribeImp(this.taos, restart, topic, sql, 0); } private native long subscribeImp(long connection, boolean restart, String topic, String sql, int period); @@ -285,16 +269,6 @@ public class TSDBJNIConnector { private native void unsubscribeImp(long subscription, boolean isKeep); - /** - * Validate if a create table SQL statement is correct without actually creating that table - */ - public boolean validateCreateTableSql(String sql) { - int res = validateCreateTableSqlImp(taos, sql.getBytes()); - return res == 0; - } - - private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes); - public long prepareStmt(String sql) throws SQLException { long stmt = prepareStmtImp(sql.getBytes(), this.taos); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java index 36714893e3ca519dea07910a95d5ee1c1b6fb731..fdd034a641d7fd829059c73061305bdf38eae1bf 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java @@ -39,7 +39,7 @@ public class RestfulDriver extends AbstractDriver { String port = props.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "6041"); String database = props.containsKey(TSDBDriver.PROPERTY_KEY_DBNAME) ? props.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME) : null; - String loginUrl = "http://" + host + ":" + port + "/rest/login/" + props.getProperty(TSDBDriver.PROPERTY_KEY_USER) + "/" + props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD) + ""; + String loginUrl; try { if (!props.containsKey(TSDBDriver.PROPERTY_KEY_USER)) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED); @@ -53,8 +53,8 @@ public class RestfulDriver extends AbstractDriver { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE, "unsupported UTF-8 concoding, user: " + props.getProperty(TSDBDriver.PROPERTY_KEY_USER) + ", password: " + props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD)); } - int poolSize = Integer.valueOf(props.getProperty("httpPoolSize", HttpClientPoolUtil.DEFAULT_MAX_PER_ROUTE)); - boolean keepAlive = Boolean.valueOf(props.getProperty("httpKeepAlive", HttpClientPoolUtil.DEFAULT_HTTP_KEEP_ALIVE)); + int poolSize = Integer.parseInt(props.getProperty("httpPoolSize", HttpClientPoolUtil.DEFAULT_MAX_PER_ROUTE)); + boolean keepAlive = Boolean.parseBoolean(props.getProperty("httpKeepAlive", HttpClientPoolUtil.DEFAULT_HTTP_KEEP_ALIVE)); HttpClientPoolUtil.init(poolSize, keepAlive); String result = HttpClientPoolUtil.execute(loginUrl); @@ -79,7 +79,7 @@ public class RestfulDriver extends AbstractDriver { public boolean acceptsURL(String url) throws SQLException { if (url == null) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET); - return url.length() > 0 && url.trim().length() > 0 && url.startsWith(URL_PREFIX); + return url.trim().length() > 0 && url.startsWith(URL_PREFIX); } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index fb8b82271b02b70b348b43a7c88a0084adaa5ab5..cdcd2eec482cc39e940bf20f6ae636568257faf2 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -65,7 +65,11 @@ public class RestfulStatement extends AbstractStatement { boolean result = true; if (SqlSyntaxValidator.isUseSql(sql)) { - HttpClientPoolUtil.execute(getUrl(), sql, this.conn.getToken()); + String ret = HttpClientPoolUtil.execute(getUrl(), sql, this.conn.getToken()); + JSONObject resultJson = JSON.parseObject(ret); + if (resultJson.getString("status").equals("error")) { + throw TSDBError.createSQLException(resultJson.getInteger("code"), "sql: " + sql + ", desc: " + resultJson.getString("desc")); + } this.database = sql.trim().replace("use", "").trim(); this.conn.setCatalog(this.database); result = false; @@ -114,7 +118,7 @@ public class RestfulStatement extends AbstractStatement { String result = HttpClientPoolUtil.execute(getUrl(), sql, this.conn.getToken()); JSONObject resultJson = JSON.parseObject(result); if (resultJson.getString("status").equals("error")) { - throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc")); + throw TSDBError.createSQLException(resultJson.getInteger("code"), "sql: " + sql + ", desc: " + resultJson.getString("desc")); } this.resultSet = new RestfulResultSet(database, this, resultJson); this.affectedRows = -1; @@ -125,7 +129,7 @@ public class RestfulStatement extends AbstractStatement { String result = HttpClientPoolUtil.execute(getUrl(), sql, this.conn.getToken()); JSONObject jsonObject = JSON.parseObject(result); if (jsonObject.getString("status").equals("error")) { - throw TSDBError.createSQLException(jsonObject.getInteger("code"), jsonObject.getString("desc")); + throw TSDBError.createSQLException(jsonObject.getInteger("code"), "sql: " + sql + ", desc: " + jsonObject.getString("desc")); } this.resultSet = null; this.affectedRows = getAffectedRows(jsonObject); @@ -133,16 +137,14 @@ public class RestfulStatement extends AbstractStatement { } private int getAffectedRows(JSONObject jsonObject) throws SQLException { - // create ... SQLs should return 0 , and Restful result like this: - // {"status": "succ", "head": ["affected_rows"], "data": [[0]], "rows": 1} JSONArray head = jsonObject.getJSONArray("head"); if (head.size() != 1 || !"affected_rows".equals(head.getString(0))) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE, "invalid variable: [" + head.toJSONString() + "]"); JSONArray data = jsonObject.getJSONArray("data"); if (data != null) { return data.getJSONArray(0).getInteger(0); } - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE, "invalid variable: [" + jsonObject.toJSONString() + "]"); } @Override diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java index d60ee14fbc87ba5d2bd2e851b5195b513fc4e028..5f821c5cc34dde0050d8e62afb6fc8ab17534a17 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java @@ -8,8 +8,13 @@ import java.sql.SQLException; public class ConnectWrongDatabaseTest { @Test(expected = SQLException.class) - public void connect() throws SQLException { + public void connectByJni() throws SQLException { DriverManager.getConnection("jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata"); } + @Test(expected = SQLException.class) + public void connectByRestful() throws SQLException { + DriverManager.getConnection("jdbc:TAOS-RS://localhost:6041/wrong_db?user=root&password=taosdata"); + } + }