Merge remote-tracking branch 'origin/develop' into feature/td-1371
This commit is contained in:
commit
a93e2c804e
|
@ -1,101 +1,102 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>JDBCDriver</name>
|
<name>JDBCDriver</name>
|
||||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
|
||||||
<description>TDengine JDBC Driver</description>
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>GNU AFFERO GENERAL PUBLIC LICENSE Version 3</name>
|
|
||||||
<url>https://github.com/taosdata/TDengine/blob/master/LICENSE</url>
|
|
||||||
<distribution>repo</distribution>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
<scm>
|
|
||||||
<connection>scm:git:git://github.com/taosdata/TDengine.git</connection>
|
|
||||||
<developerConnection>scm:git:git@github.com:taosdata/TDengine.git</developerConnection>
|
|
||||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||||
<tag>HEAD</tag>
|
|
||||||
</scm>
|
<description>TDengine JDBC Driver</description>
|
||||||
<developers>
|
<licenses>
|
||||||
<developer>
|
<license>
|
||||||
<name>taosdata</name>
|
<name>GNU AFFERO GENERAL PUBLIC LICENSE Version 3</name>
|
||||||
<email>support@taosdata.com</email>
|
<url>https://github.com/taosdata/TDengine/blob/master/LICENSE</url>
|
||||||
<organization>https://www.taosdata.com/</organization>
|
<distribution>repo</distribution>
|
||||||
<organizationUrl>https://www.taosdata.com/</organizationUrl>
|
</license>
|
||||||
</developer>
|
</licenses>
|
||||||
</developers>
|
<scm>
|
||||||
<properties>
|
<connection>scm:git:git://github.com/taosdata/TDengine.git</connection>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<developerConnection>scm:git:git@github.com:taosdata/TDengine.git</developerConnection>
|
||||||
<java.version>1.8</java.version>
|
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
<tag>HEAD</tag>
|
||||||
<commons-logging.version>1.1.2</commons-logging.version>
|
</scm>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<developers>
|
||||||
</properties>
|
<developer>
|
||||||
<dependencies>
|
<name>taosdata</name>
|
||||||
<dependency>
|
<email>support@taosdata.com</email>
|
||||||
<groupId>commons-logging</groupId>
|
<organization>https://www.taosdata.com/</organization>
|
||||||
<artifactId>commons-logging</artifactId>
|
<organizationUrl>https://www.taosdata.com/</organizationUrl>
|
||||||
<version>${commons-logging.version}</version>
|
</developer>
|
||||||
<exclusions>
|
</developers>
|
||||||
<exclusion>
|
<properties>
|
||||||
<groupId>*</groupId>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<artifactId>*</artifactId>
|
<java.version>1.8</java.version>
|
||||||
</exclusion>
|
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||||
</exclusions>
|
<commons-logging.version>1.1.2</commons-logging.version>
|
||||||
</dependency>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<dependency>
|
</properties>
|
||||||
<groupId>junit</groupId>
|
<dependencies>
|
||||||
<artifactId>junit</artifactId>
|
<dependency>
|
||||||
<version>4.13</version>
|
<groupId>commons-logging</groupId>
|
||||||
<scope>test</scope>
|
<artifactId>commons-logging</artifactId>
|
||||||
</dependency>
|
<version>${commons-logging.version}</version>
|
||||||
</dependencies>
|
<exclusions>
|
||||||
<build>
|
<exclusion>
|
||||||
<plugins>
|
<groupId>*</groupId>
|
||||||
<plugin>
|
<artifactId>*</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
</exclusion>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
</exclusions>
|
||||||
<version>3.0.0</version>
|
</dependency>
|
||||||
<configuration>
|
<dependency>
|
||||||
<descriptors>
|
<groupId>junit</groupId>
|
||||||
<descriptor>src/main/assembly/assembly-jar.xml</descriptor>
|
<artifactId>junit</artifactId>
|
||||||
</descriptors>
|
<version>4.13</version>
|
||||||
</configuration>
|
<scope>test</scope>
|
||||||
<executions>
|
</dependency>
|
||||||
<execution>
|
</dependencies>
|
||||||
<id>make-assembly</id>
|
<build>
|
||||||
<phase>package</phase>
|
<plugins>
|
||||||
<goals>
|
<plugin>
|
||||||
<goal>single</goal>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
</goals>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
</execution>
|
<version>3.0.0</version>
|
||||||
</executions>
|
<configuration>
|
||||||
</plugin>
|
<descriptors>
|
||||||
<plugin>
|
<descriptor>src/main/assembly/assembly-jar.xml</descriptor>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
</descriptors>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
</configuration>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<executions>
|
||||||
<configuration>
|
<execution>
|
||||||
<encoding>UTF-8</encoding>
|
<id>make-assembly</id>
|
||||||
<source>${java.version}</source>
|
<phase>package</phase>
|
||||||
<target>${java.version}</target>
|
<goals>
|
||||||
<debug>true</debug>
|
<goal>single</goal>
|
||||||
<showDeprecation>true</showDeprecation>
|
</goals>
|
||||||
</configuration>
|
</execution>
|
||||||
</plugin>
|
</executions>
|
||||||
<plugin>
|
</plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>2.12.4</version>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<testFailureIgnore>true</testFailureIgnore>
|
<configuration>
|
||||||
</configuration>
|
<encoding>UTF-8</encoding>
|
||||||
</plugin>
|
<source>${java.version}</source>
|
||||||
</plugins>
|
<target>${java.version}</target>
|
||||||
</build>
|
<debug>true</debug>
|
||||||
|
<showDeprecation>true</showDeprecation>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.12.4</version>
|
||||||
|
<configuration>
|
||||||
|
<testFailureIgnore>true</testFailureIgnore>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -53,66 +53,12 @@ public class TSDBConnection implements Connection {
|
||||||
public TSDBConnection(Properties info, TSDBDatabaseMetaData meta) throws SQLException {
|
public TSDBConnection(Properties info, TSDBDatabaseMetaData meta) throws SQLException {
|
||||||
this.dbMetaData = meta;
|
this.dbMetaData = meta;
|
||||||
|
|
||||||
//load taos.cfg start
|
|
||||||
File cfgDir = loadConfigDir(info.getProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR));
|
|
||||||
File cfgFile = cfgDir.listFiles((dir, name) -> "taos.cfg".equalsIgnoreCase(name))[0];
|
|
||||||
List<String> endpoints = loadConfigEndpoints(cfgFile);
|
|
||||||
if (!endpoints.isEmpty()) {
|
|
||||||
info.setProperty(TSDBDriver.PROPERTY_KEY_HOST, endpoints.get(0).split(":")[0]);
|
|
||||||
info.setProperty(TSDBDriver.PROPERTY_KEY_PORT, endpoints.get(0).split(":")[1]);
|
|
||||||
}
|
|
||||||
//load taos.cfg end
|
|
||||||
|
|
||||||
connect(info.getProperty(TSDBDriver.PROPERTY_KEY_HOST),
|
connect(info.getProperty(TSDBDriver.PROPERTY_KEY_HOST),
|
||||||
Integer.parseInt(info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "0")),
|
Integer.parseInt(info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "0")),
|
||||||
info.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME), info.getProperty(TSDBDriver.PROPERTY_KEY_USER),
|
info.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME), info.getProperty(TSDBDriver.PROPERTY_KEY_USER),
|
||||||
info.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD));
|
info.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> loadConfigEndpoints(File cfgFile) {
|
|
||||||
List<String> endpoints = new ArrayList<>();
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(cfgFile))) {
|
|
||||||
String line = null;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
if (line.trim().startsWith("firstEp") || line.trim().startsWith("secondEp")) {
|
|
||||||
endpoints.add(line.substring(line.indexOf('p') + 1).trim());
|
|
||||||
}
|
|
||||||
if (endpoints.size() > 1)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return endpoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param cfgDirPath
|
|
||||||
* @return return the config dir
|
|
||||||
**/
|
|
||||||
private File loadConfigDir(String cfgDirPath) {
|
|
||||||
if (cfgDirPath == null)
|
|
||||||
return loadDefaultConfigDir();
|
|
||||||
File cfgDir = new File(cfgDirPath);
|
|
||||||
if (!cfgDir.exists())
|
|
||||||
return loadDefaultConfigDir();
|
|
||||||
return cfgDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return search the default config dir, if the config dir is not exist will return null
|
|
||||||
*/
|
|
||||||
private File loadDefaultConfigDir() {
|
|
||||||
File cfgDir;
|
|
||||||
File cfgDir_linux = new File("/etc/taos");
|
|
||||||
cfgDir = cfgDir_linux.exists() ? cfgDir_linux : null;
|
|
||||||
File cfgDir_windows = new File("C:\\TDengine\\cfg");
|
|
||||||
cfgDir = (cfgDir == null && cfgDir_windows.exists()) ? cfgDir_windows : cfgDir;
|
|
||||||
return cfgDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void connect(String host, int port, String dbName, String user, String password) throws SQLException {
|
private void connect(String host, int port, String dbName, String user, String password) throws SQLException {
|
||||||
this.connector = new TSDBJNIConnector();
|
this.connector = new TSDBJNIConnector();
|
||||||
this.connector.connect(host, port, dbName, user, password);
|
this.connector.connect(host, port, dbName, user, password);
|
||||||
|
|
|
@ -68,15 +68,15 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean nullsAreSortedLow() throws SQLException {
|
public boolean nullsAreSortedLow() throws SQLException {
|
||||||
return false;
|
return !nullsAreSortedHigh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean nullsAreSortedAtStart() throws SQLException {
|
public boolean nullsAreSortedAtStart() throws SQLException {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean nullsAreSortedAtEnd() throws SQLException {
|
public boolean nullsAreSortedAtEnd() throws SQLException {
|
||||||
return false;
|
return !nullsAreSortedAtStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDatabaseProductName() throws SQLException {
|
public String getDatabaseProductName() throws SQLException {
|
||||||
|
|
|
@ -14,24 +14,29 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Java SQL framework allows for multiple database drivers. Each driver
|
* The Java SQL framework allows for multiple database drivers. Each driver
|
||||||
* should supply a class that implements the Driver interface
|
* should supply a class that implements the Driver interface
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* The DriverManager will try to load as many drivers as it can find and then
|
* The DriverManager will try to load as many drivers as it can find and then
|
||||||
* for any given connection request, it will ask each driver in turn to try to
|
* for any given connection request, it will ask each driver in turn to try to
|
||||||
* connect to the target URL.
|
* connect to the target URL.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* It is strongly recommended that each Driver class should be small and stand
|
* It is strongly recommended that each Driver class should be small and stand
|
||||||
* alone so that the Driver class can be loaded and queried without bringing in
|
* alone so that the Driver class can be loaded and queried without bringing in
|
||||||
* vast quantities of supporting code.
|
* vast quantities of supporting code.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* When a Driver class is loaded, it should create an instance of itself and
|
* When a Driver class is loaded, it should create an instance of itself and
|
||||||
* register it with the DriverManager. This means that a user can load and
|
* register it with the DriverManager. This means that a user can load and
|
||||||
|
@ -39,38 +44,41 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class TSDBDriver implements java.sql.Driver {
|
public class TSDBDriver implements java.sql.Driver {
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private static final String URL_PREFIX1 = "jdbc:tsdb://";
|
|
||||||
private static final String URL_PREFIX = "jdbc:taos://";
|
|
||||||
|
|
||||||
/**
|
@Deprecated
|
||||||
* Key used to retrieve the database value from the properties instance passed
|
private static final String URL_PREFIX1 = "jdbc:TSDB://";
|
||||||
* to the driver.
|
|
||||||
*/
|
|
||||||
public static final String PROPERTY_KEY_DBNAME = "dbname";
|
|
||||||
|
|
||||||
/**
|
private static final String URL_PREFIX = "jdbc:TAOS://";
|
||||||
* Key used to retrieve the host value from the properties instance passed to
|
|
||||||
* the driver.
|
|
||||||
*/
|
|
||||||
public static final String PROPERTY_KEY_HOST = "host";
|
|
||||||
/**
|
|
||||||
* Key used to retrieve the password value from the properties instance passed
|
|
||||||
* to the driver.
|
|
||||||
*/
|
|
||||||
public static final String PROPERTY_KEY_PASSWORD = "password";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key used to retrieve the port number value from the properties instance
|
* Key used to retrieve the database value from the properties instance passed
|
||||||
* passed to the driver.
|
* to the driver.
|
||||||
*/
|
*/
|
||||||
public static final String PROPERTY_KEY_PORT = "port";
|
public static final String PROPERTY_KEY_DBNAME = "dbname";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key used to retrieve the host value from the properties instance passed to
|
||||||
|
* the driver.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_KEY_HOST = "host";
|
||||||
|
/**
|
||||||
|
* Key used to retrieve the password value from the properties instance passed
|
||||||
|
* to the driver.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_KEY_PASSWORD = "password";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key used to retrieve the port number value from the properties instance
|
||||||
|
* passed to the driver.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_KEY_PORT = "port";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key used to retrieve the user value from the properties instance passed to
|
||||||
|
* the driver.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_KEY_USER = "user";
|
||||||
|
|
||||||
/**
|
|
||||||
* Key used to retrieve the user value from the properties instance passed to
|
|
||||||
* the driver.
|
|
||||||
*/
|
|
||||||
public static final String PROPERTY_KEY_USER = "user";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key for the configuration file directory of TSDB client in properties instance
|
* Key for the configuration file directory of TSDB client in properties instance
|
||||||
|
@ -95,278 +103,320 @@ public class TSDBDriver implements java.sql.Driver {
|
||||||
|
|
||||||
public static final String PROPERTY_KEY_PROTOCOL = "protocol";
|
public static final String PROPERTY_KEY_PROTOCOL = "protocol";
|
||||||
|
|
||||||
/**
|
|
||||||
* Index for port coming out of parseHostPortPair().
|
|
||||||
*/
|
|
||||||
public final static int PORT_NUMBER_INDEX = 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index for host coming out of parseHostPortPair().
|
* Index for port coming out of parseHostPortPair().
|
||||||
*/
|
*/
|
||||||
public final static int HOST_NAME_INDEX = 0;
|
public final static int PORT_NUMBER_INDEX = 1;
|
||||||
|
|
||||||
private TSDBDatabaseMetaData dbMetaData = null;
|
/**
|
||||||
|
* Index for host coming out of parseHostPortPair().
|
||||||
|
*/
|
||||||
|
public final static int HOST_NAME_INDEX = 0;
|
||||||
|
|
||||||
static {
|
private TSDBDatabaseMetaData dbMetaData = null;
|
||||||
try {
|
|
||||||
java.sql.DriverManager.registerDriver(new TSDBDriver());
|
|
||||||
} catch (SQLException E) {
|
|
||||||
throw new RuntimeException(TSDBConstants.WrapErrMsg("can't register tdengine jdbc driver!"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection connect(String url, Properties info) throws SQLException {
|
static {
|
||||||
if (url == null) {
|
try {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
java.sql.DriverManager.registerDriver(new TSDBDriver());
|
||||||
}
|
} catch (SQLException E) {
|
||||||
|
throw new RuntimeException(TSDBConstants.WrapErrMsg("can't register tdengine jdbc driver!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Properties props = null;
|
private List<String> loadConfigEndpoints(File cfgFile) {
|
||||||
|
List<String> endpoints = new ArrayList<>();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(cfgFile))) {
|
||||||
|
String line = null;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (line.trim().startsWith("firstEp") || line.trim().startsWith("secondEp")) {
|
||||||
|
endpoints.add(line.substring(line.indexOf('p') + 1).trim());
|
||||||
|
}
|
||||||
|
if (endpoints.size() > 1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return endpoints;
|
||||||
|
}
|
||||||
|
|
||||||
if ((props = parseURL(url, info)) == null) {
|
/**
|
||||||
return null;
|
* @param cfgDirPath
|
||||||
}
|
* @return return the config dir
|
||||||
|
**/
|
||||||
|
private File loadConfigDir(String cfgDirPath) {
|
||||||
|
if (cfgDirPath == null)
|
||||||
|
return loadDefaultConfigDir();
|
||||||
|
File cfgDir = new File(cfgDirPath);
|
||||||
|
if (!cfgDir.exists())
|
||||||
|
return loadDefaultConfigDir();
|
||||||
|
return cfgDir;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
/**
|
||||||
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE), (String) props.get(PROPERTY_KEY_CHARSET),
|
* @return search the default config dir, if the config dir is not exist will return null
|
||||||
(String) props.get(PROPERTY_KEY_TIME_ZONE));
|
*/
|
||||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
private File loadDefaultConfigDir() {
|
||||||
return newConn;
|
File cfgDir;
|
||||||
} catch (SQLWarning sqlWarning) {
|
File cfgDir_linux = new File("/etc/taos");
|
||||||
sqlWarning.printStackTrace();
|
cfgDir = cfgDir_linux.exists() ? cfgDir_linux : null;
|
||||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
File cfgDir_windows = new File("C:\\TDengine\\cfg");
|
||||||
return newConn;
|
cfgDir = (cfgDir == null && cfgDir_windows.exists()) ? cfgDir_windows : cfgDir;
|
||||||
} catch (SQLException sqlEx) {
|
return cfgDir;
|
||||||
throw sqlEx;
|
}
|
||||||
} catch (Exception ex) {
|
|
||||||
SQLException sqlEx = new SQLException("SQLException:" + ex.toString());
|
|
||||||
sqlEx.initCause(ex);
|
|
||||||
throw sqlEx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public Connection connect(String url, Properties info) throws SQLException {
|
||||||
* Parses hostPortPair in the form of [host][:port] into an array, with the
|
if (url == null) {
|
||||||
* element of index HOST_NAME_INDEX being the host (or null if not specified),
|
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
||||||
* and the element of index PORT_NUMBER_INDEX being the port (or null if not
|
}
|
||||||
* specified).
|
|
||||||
*
|
|
||||||
* @param hostPortPair
|
|
||||||
* host and port in form of of [host][:port]
|
|
||||||
*
|
|
||||||
* @return array containing host and port as Strings
|
|
||||||
*
|
|
||||||
* @throws SQLException
|
|
||||||
* if a parse error occurs
|
|
||||||
*/
|
|
||||||
protected static String[] parseHostPortPair(String hostPortPair) throws SQLException {
|
|
||||||
String[] splitValues = new String[2];
|
|
||||||
|
|
||||||
int portIndex = hostPortPair.indexOf(":");
|
Properties props = null;
|
||||||
|
if ((props = parseURL(url, info)) == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String hostname = null;
|
//load taos.cfg start
|
||||||
|
if (info.getProperty(TSDBDriver.PROPERTY_KEY_HOST) == null && info.getProperty(TSDBDriver.PROPERTY_KEY_PORT) == null){
|
||||||
|
File cfgDir = loadConfigDir(info.getProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR));
|
||||||
|
File cfgFile = cfgDir.listFiles((dir, name) -> "taos.cfg".equalsIgnoreCase(name))[0];
|
||||||
|
List<String> endpoints = loadConfigEndpoints(cfgFile);
|
||||||
|
if (!endpoints.isEmpty()) {
|
||||||
|
info.setProperty(TSDBDriver.PROPERTY_KEY_HOST, endpoints.get(0).split(":")[0]);
|
||||||
|
info.setProperty(TSDBDriver.PROPERTY_KEY_PORT, endpoints.get(0).split(":")[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (portIndex != -1) {
|
try {
|
||||||
if ((portIndex + 1) < hostPortPair.length()) {
|
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE), (String) props.get(PROPERTY_KEY_CHARSET),
|
||||||
String portAsString = hostPortPair.substring(portIndex + 1);
|
(String) props.get(PROPERTY_KEY_TIME_ZONE));
|
||||||
hostname = hostPortPair.substring(0, portIndex);
|
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
||||||
|
return newConn;
|
||||||
|
} catch (SQLWarning sqlWarning) {
|
||||||
|
sqlWarning.printStackTrace();
|
||||||
|
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
||||||
|
return newConn;
|
||||||
|
} catch (SQLException sqlEx) {
|
||||||
|
throw sqlEx;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SQLException sqlEx = new SQLException("SQLException:" + ex.toString());
|
||||||
|
sqlEx.initCause(ex);
|
||||||
|
throw sqlEx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
splitValues[HOST_NAME_INDEX] = hostname;
|
/**
|
||||||
|
* Parses hostPortPair in the form of [host][:port] into an array, with the
|
||||||
|
* element of index HOST_NAME_INDEX being the host (or null if not specified),
|
||||||
|
* and the element of index PORT_NUMBER_INDEX being the port (or null if not
|
||||||
|
* specified).
|
||||||
|
*
|
||||||
|
* @param hostPortPair host and port in form of of [host][:port]
|
||||||
|
* @return array containing host and port as Strings
|
||||||
|
* @throws SQLException if a parse error occurs
|
||||||
|
*/
|
||||||
|
protected static String[] parseHostPortPair(String hostPortPair) throws SQLException {
|
||||||
|
String[] splitValues = new String[2];
|
||||||
|
|
||||||
splitValues[PORT_NUMBER_INDEX] = portAsString;
|
int portIndex = hostPortPair.indexOf(":");
|
||||||
} else {
|
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("port is not proper!"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
splitValues[HOST_NAME_INDEX] = hostPortPair;
|
|
||||||
splitValues[PORT_NUMBER_INDEX] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return splitValues;
|
String hostname = null;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean acceptsURL(String url) throws SQLException {
|
if (portIndex != -1) {
|
||||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && url.toLowerCase().startsWith(URL_PREFIX);
|
if ((portIndex + 1) < hostPortPair.length()) {
|
||||||
}
|
String portAsString = hostPortPair.substring(portIndex + 1);
|
||||||
|
hostname = hostPortPair.substring(0, portIndex);
|
||||||
|
|
||||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
splitValues[HOST_NAME_INDEX] = hostname;
|
||||||
if (info == null) {
|
|
||||||
info = new Properties();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((url != null) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1))) {
|
splitValues[PORT_NUMBER_INDEX] = portAsString;
|
||||||
info = parseURL(url, info);
|
} else {
|
||||||
}
|
throw new SQLException(TSDBConstants.WrapErrMsg("port is not proper!"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
splitValues[HOST_NAME_INDEX] = hostPortPair;
|
||||||
|
splitValues[PORT_NUMBER_INDEX] = null;
|
||||||
|
}
|
||||||
|
|
||||||
DriverPropertyInfo hostProp = new DriverPropertyInfo(PROPERTY_KEY_HOST, info.getProperty(PROPERTY_KEY_HOST));
|
return splitValues;
|
||||||
hostProp.required = true;
|
}
|
||||||
|
|
||||||
DriverPropertyInfo portProp = new DriverPropertyInfo(PROPERTY_KEY_PORT,
|
public boolean acceptsURL(String url) throws SQLException {
|
||||||
info.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
return (url != null && url.length() > 0 && url.trim().length() > 0) && url.toLowerCase().startsWith(URL_PREFIX);
|
||||||
portProp.required = false;
|
}
|
||||||
|
|
||||||
DriverPropertyInfo dbProp = new DriverPropertyInfo(PROPERTY_KEY_DBNAME, info.getProperty(PROPERTY_KEY_DBNAME));
|
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||||
dbProp.required = false;
|
if (info == null) {
|
||||||
dbProp.description = "Database name";
|
info = new Properties();
|
||||||
|
}
|
||||||
|
|
||||||
DriverPropertyInfo userProp = new DriverPropertyInfo(PROPERTY_KEY_USER, info.getProperty(PROPERTY_KEY_USER));
|
if ((url != null) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1))) {
|
||||||
userProp.required = true;
|
info = parseURL(url, info);
|
||||||
|
}
|
||||||
|
|
||||||
DriverPropertyInfo passwordProp = new DriverPropertyInfo(PROPERTY_KEY_PASSWORD,
|
DriverPropertyInfo hostProp = new DriverPropertyInfo(PROPERTY_KEY_HOST, info.getProperty(PROPERTY_KEY_HOST));
|
||||||
info.getProperty(PROPERTY_KEY_PASSWORD));
|
hostProp.required = true;
|
||||||
passwordProp.required = true;
|
|
||||||
|
|
||||||
DriverPropertyInfo[] propertyInfo = new DriverPropertyInfo[5];
|
DriverPropertyInfo portProp = new DriverPropertyInfo(PROPERTY_KEY_PORT, info.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
||||||
propertyInfo[0] = hostProp;
|
portProp.required = false;
|
||||||
propertyInfo[1] = portProp;
|
|
||||||
propertyInfo[2] = dbProp;
|
|
||||||
propertyInfo[3] = userProp;
|
|
||||||
propertyInfo[4] = passwordProp;
|
|
||||||
|
|
||||||
return propertyInfo;
|
DriverPropertyInfo dbProp = new DriverPropertyInfo(PROPERTY_KEY_DBNAME, info.getProperty(PROPERTY_KEY_DBNAME));
|
||||||
}
|
dbProp.required = false;
|
||||||
|
dbProp.description = "Database name";
|
||||||
|
|
||||||
/**
|
DriverPropertyInfo userProp = new DriverPropertyInfo(PROPERTY_KEY_USER, info.getProperty(PROPERTY_KEY_USER));
|
||||||
* example: jdbc:TSDB://127.0.0.1:0/db?user=root&password=your_password
|
userProp.required = true;
|
||||||
*/
|
|
||||||
|
|
||||||
public Properties parseURL(String url, Properties defaults) throws java.sql.SQLException {
|
DriverPropertyInfo passwordProp = new DriverPropertyInfo(PROPERTY_KEY_PASSWORD, info.getProperty(PROPERTY_KEY_PASSWORD));
|
||||||
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
passwordProp.required = true;
|
||||||
if (url == null) {
|
|
||||||
return null;
|
DriverPropertyInfo[] propertyInfo = new DriverPropertyInfo[5];
|
||||||
}
|
propertyInfo[0] = hostProp;
|
||||||
|
propertyInfo[1] = portProp;
|
||||||
|
propertyInfo[2] = dbProp;
|
||||||
|
propertyInfo[3] = userProp;
|
||||||
|
propertyInfo[4] = passwordProp;
|
||||||
|
|
||||||
|
return propertyInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* example: jdbc:TSDB://127.0.0.1:0/db?user=root&password=your_password
|
||||||
|
*/
|
||||||
|
public Properties parseURL(String url, Properties defaults) throws java.sql.SQLException {
|
||||||
|
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
||||||
|
if (url == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String lowerUrl = url.toLowerCase();
|
String lowerUrl = url.toLowerCase();
|
||||||
if (!lowerUrl.startsWith(URL_PREFIX) && !lowerUrl.startsWith(URL_PREFIX1)) {
|
if (!lowerUrl.startsWith(URL_PREFIX) && !lowerUrl.startsWith(URL_PREFIX1)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String urlForMeta = url;
|
String urlForMeta = url;
|
||||||
|
|
||||||
String dbProductName = url.substring(url.indexOf(":") + 1);
|
String dbProductName = url.substring(url.indexOf(":") + 1);
|
||||||
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
||||||
int beginningOfSlashes = url.indexOf("//");
|
int beginningOfSlashes = url.indexOf("//");
|
||||||
url = url.substring(beginningOfSlashes + 2);
|
url = url.substring(beginningOfSlashes + 2);
|
||||||
|
|
||||||
String host = url.substring(0, url.indexOf(":"));
|
String host = url.substring(0, url.indexOf(":"));
|
||||||
url = url.substring(url.indexOf(":") + 1);
|
url = url.substring(url.indexOf(":") + 1);
|
||||||
urlProps.setProperty(PROPERTY_KEY_HOST, host);
|
urlProps.setProperty(PROPERTY_KEY_HOST, host);
|
||||||
|
|
||||||
String port = url.substring(0, url.indexOf("/"));
|
String port = url.substring(0, url.indexOf("/"));
|
||||||
urlProps.setProperty(PROPERTY_KEY_PORT, port);
|
urlProps.setProperty(PROPERTY_KEY_PORT, port);
|
||||||
url = url.substring(url.indexOf("/") + 1);
|
url = url.substring(url.indexOf("/") + 1);
|
||||||
|
|
||||||
if (url.indexOf("?") != -1) {
|
if (url.indexOf("?") != -1) {
|
||||||
String dbName = url.substring(0, url.indexOf("?"));
|
String dbName = url.substring(0, url.indexOf("?"));
|
||||||
urlProps.setProperty(PROPERTY_KEY_DBNAME, dbName);
|
urlProps.setProperty(PROPERTY_KEY_DBNAME, dbName);
|
||||||
url = url.trim().substring(url.indexOf("?") + 1);
|
url = url.trim().substring(url.indexOf("?") + 1);
|
||||||
} else {
|
} else {
|
||||||
// without user & password so return
|
// without user & password so return
|
||||||
if(!url.trim().isEmpty()) {
|
if (!url.trim().isEmpty()) {
|
||||||
String dbName = url.trim();
|
String dbName = url.trim();
|
||||||
urlProps.setProperty(PROPERTY_KEY_DBNAME, dbName);
|
urlProps.setProperty(PROPERTY_KEY_DBNAME, dbName);
|
||||||
}
|
}
|
||||||
this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, urlProps.getProperty("user"));
|
this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, urlProps.getProperty("user"));
|
||||||
return urlProps;
|
return urlProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
String user = "";
|
String user = "";
|
||||||
|
|
||||||
if (url.indexOf("&") == -1) {
|
if (url.indexOf("&") == -1) {
|
||||||
String[] kvPair = url.trim().split("=");
|
String[] kvPair = url.trim().split("=");
|
||||||
if (kvPair.length == 2) {
|
if (kvPair.length == 2) {
|
||||||
setPropertyValue(urlProps, kvPair);
|
setPropertyValue(urlProps, kvPair);
|
||||||
return urlProps;
|
return urlProps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] queryStrings = url.trim().split("&");
|
String[] queryStrings = url.trim().split("&");
|
||||||
for (String queryStr : queryStrings) {
|
for (String queryStr : queryStrings) {
|
||||||
String[] kvPair = queryStr.trim().split("=");
|
String[] kvPair = queryStr.trim().split("=");
|
||||||
if (kvPair.length < 2){
|
if (kvPair.length < 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
setPropertyValue(urlProps, kvPair);
|
setPropertyValue(urlProps, kvPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
user = urlProps.getProperty(PROPERTY_KEY_USER).toString();
|
user = urlProps.getProperty(PROPERTY_KEY_USER).toString();
|
||||||
this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, user);
|
this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, user);
|
||||||
|
|
||||||
return urlProps;
|
return urlProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPropertyValue(Properties property, String[] keyValuePair) {
|
public void setPropertyValue(Properties property, String[] keyValuePair) {
|
||||||
switch (keyValuePair[0].toLowerCase()) {
|
switch (keyValuePair[0].toLowerCase()) {
|
||||||
case PROPERTY_KEY_USER:
|
case PROPERTY_KEY_USER:
|
||||||
property.setProperty(PROPERTY_KEY_USER, keyValuePair[1]);
|
property.setProperty(PROPERTY_KEY_USER, keyValuePair[1]);
|
||||||
break;
|
break;
|
||||||
case PROPERTY_KEY_PASSWORD:
|
case PROPERTY_KEY_PASSWORD:
|
||||||
property.setProperty(PROPERTY_KEY_PASSWORD, keyValuePair[1]);
|
property.setProperty(PROPERTY_KEY_PASSWORD, keyValuePair[1]);
|
||||||
break;
|
break;
|
||||||
case PROPERTY_KEY_TIME_ZONE:
|
case PROPERTY_KEY_TIME_ZONE:
|
||||||
property.setProperty(PROPERTY_KEY_TIME_ZONE, keyValuePair[1]);
|
property.setProperty(PROPERTY_KEY_TIME_ZONE, keyValuePair[1]);
|
||||||
break;
|
break;
|
||||||
case PROPERTY_KEY_LOCALE:
|
case PROPERTY_KEY_LOCALE:
|
||||||
property.setProperty(PROPERTY_KEY_LOCALE, keyValuePair[1]);
|
property.setProperty(PROPERTY_KEY_LOCALE, keyValuePair[1]);
|
||||||
break;
|
break;
|
||||||
case PROPERTY_KEY_CHARSET:
|
case PROPERTY_KEY_CHARSET:
|
||||||
property.setProperty(PROPERTY_KEY_CHARSET, keyValuePair[1]);
|
property.setProperty(PROPERTY_KEY_CHARSET, keyValuePair[1]);
|
||||||
break;
|
break;
|
||||||
case PROPERTY_KEY_CONFIG_DIR:
|
case PROPERTY_KEY_CONFIG_DIR:
|
||||||
property.setProperty(PROPERTY_KEY_CONFIG_DIR, keyValuePair[1]);
|
property.setProperty(PROPERTY_KEY_CONFIG_DIR, keyValuePair[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getMajorVersion() {
|
public int getMajorVersion() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinorVersion() {
|
public int getMinorVersion() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean jdbcCompliant() {
|
public boolean jdbcCompliant() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the host property
|
* Returns the host property
|
||||||
*
|
*
|
||||||
* @param props
|
* @param props the java.util.Properties instance to retrieve the hostname from.
|
||||||
* the java.util.Properties instance to retrieve the hostname from.
|
* @return the host
|
||||||
*
|
*/
|
||||||
* @return the host
|
public String host(Properties props) {
|
||||||
*/
|
return props.getProperty(PROPERTY_KEY_HOST, "localhost");
|
||||||
public String host(Properties props) {
|
}
|
||||||
return props.getProperty(PROPERTY_KEY_HOST, "localhost");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the port number property
|
* Returns the port number property
|
||||||
*
|
*
|
||||||
* @param props
|
* @param props the properties to get the port number from
|
||||||
* the properties to get the port number from
|
* @return the port number
|
||||||
*
|
*/
|
||||||
* @return the port number
|
public int port(Properties props) {
|
||||||
*/
|
return Integer.parseInt(props.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
||||||
public int port(Properties props) {
|
}
|
||||||
return Integer.parseInt(props.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the database property from <code>props</code>
|
* Returns the database property from <code>props</code>
|
||||||
*
|
*
|
||||||
* @param props
|
* @param props the Properties to look for the database property.
|
||||||
* the Properties to look for the database property.
|
* @return the database name.
|
||||||
*
|
*/
|
||||||
* @return the database name.
|
public String database(Properties props) {
|
||||||
*/
|
return props.getProperty(PROPERTY_KEY_DBNAME);
|
||||||
public String database(Properties props) {
|
}
|
||||||
return props.getProperty(PROPERTY_KEY_DBNAME);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class TSDBStatement implements Statement {
|
||||||
|
|
||||||
public void addBatch(String sql) throws SQLException {
|
public void addBatch(String sql) throws SQLException {
|
||||||
if (batchedArgs == null) {
|
if (batchedArgs == null) {
|
||||||
batchedArgs = new ArrayList<String>();
|
batchedArgs = new ArrayList<>();
|
||||||
}
|
}
|
||||||
batchedArgs.add(sql);
|
batchedArgs.add(sql);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue