未验证 提交 d332c3c3 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #8856 from taosdata/hotfix/TS-601

[TS-601]<fix>: no invalid database error in jdbc-restful with wrong db
[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
[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
[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
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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();
}
......
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
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);
}
......
/***************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
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 {
......
/**
* *************************************************************************
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ***************************************************************************
*/
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 <I>create table</I> 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);
......
......@@ -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
......
......@@ -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
......
......@@ -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");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册