Feature/td 3411 (#5648)
* [TD-3410]feature: adapted to nutz * change * change * change * change * [TD-3447]<feature>: JDBC-RESTful and JDBC-JNI support setObject * change * change * change * change * change * change * change * change * change * change * change * change * [TD-3548]<feature>: support ParameterMetaData in JDBC-RESTful and JDBC-JNI * change * change * [TD-3446]<feature>: JDBC-JNI and JDBC-RESTful do not need invoke Class.forName any more * change jdbc version * change * change * change * change * change * change * change * change * change version
This commit is contained in:
parent
af996100a2
commit
598b1ce6bf
|
@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
|
||||||
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
||||||
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
||||||
IF (TD_MVN_INSTALLED)
|
IF (TD_MVN_INSTALLED)
|
||||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.24-dist.jar DESTINATION connector/jdbc)
|
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.25-dist.jar DESTINATION connector/jdbc)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
ELSEIF (TD_DARWIN)
|
ELSEIF (TD_DARWIN)
|
||||||
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
||||||
|
|
|
@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
|
||||||
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.24-dist.jar ${LIBRARY_OUTPUT_PATH}
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.25-dist.jar ${LIBRARY_OUTPUT_PATH}
|
||||||
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
||||||
COMMENT "build jdbc driver")
|
COMMENT "build jdbc driver")
|
||||||
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
|
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.24</version>
|
<version>2.0.25</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>JDBCDriver</name>
|
<name>JDBCDriver</name>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<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.24</version>
|
<version>2.0.25</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>
|
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||||
|
@ -62,6 +62,14 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.md</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|
|
@ -15,7 +15,7 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getParameterCount() throws SQLException {
|
public int getParameterCount() throws SQLException {
|
||||||
return parameters.length;
|
return parameters == null ? 0 : parameters.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,45 +29,25 @@ public class TSDBJNIConnector {
|
||||||
private static volatile Boolean isInitialized = false;
|
private static volatile Boolean isInitialized = false;
|
||||||
|
|
||||||
private TaosInfo taosInfo = TaosInfo.getInstance();
|
private TaosInfo taosInfo = TaosInfo.getInstance();
|
||||||
|
// Connection pointer used in C
|
||||||
|
private long taos = TSDBConstants.JNI_NULL_POINTER;
|
||||||
|
// result set status in current connection
|
||||||
|
private boolean isResultsetClosed = true;
|
||||||
|
private int affectedRows = -1;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("taos");
|
System.loadLibrary("taos");
|
||||||
System.out.println("java.library.path:" + System.getProperty("java.library.path"));
|
System.out.println("java.library.path:" + System.getProperty("java.library.path"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Connection pointer used in C
|
|
||||||
*/
|
|
||||||
private long taos = TSDBConstants.JNI_NULL_POINTER;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Result set pointer for the current connection
|
|
||||||
*/
|
|
||||||
// private long taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* result set status in current connection
|
|
||||||
*/
|
|
||||||
private boolean isResultsetClosed = true;
|
|
||||||
private int affectedRows = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the connection is closed
|
|
||||||
*/
|
|
||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
return this.taos == TSDBConstants.JNI_NULL_POINTER;
|
return this.taos == TSDBConstants.JNI_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the status of last result set in current connection
|
|
||||||
*/
|
|
||||||
public boolean isResultsetClosed() {
|
public boolean isResultsetClosed() {
|
||||||
return this.isResultsetClosed;
|
return this.isResultsetClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize static variables in JNI to optimize performance
|
|
||||||
*/
|
|
||||||
public static void init(String configDir, String locale, String charset, String timezone) throws SQLWarning {
|
public static void init(String configDir, String locale, String charset, String timezone) throws SQLWarning {
|
||||||
synchronized (isInitialized) {
|
synchronized (isInitialized) {
|
||||||
if (!isInitialized) {
|
if (!isInitialized) {
|
||||||
|
@ -93,11 +73,6 @@ public class TSDBJNIConnector {
|
||||||
|
|
||||||
public static native String getTsCharset();
|
public static native String getTsCharset();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get connection pointer
|
|
||||||
*
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException {
|
public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException {
|
||||||
if (this.taos != TSDBConstants.JNI_NULL_POINTER) {
|
if (this.taos != TSDBConstants.JNI_NULL_POINTER) {
|
||||||
// this.closeConnectionImp(this.taos);
|
// this.closeConnectionImp(this.taos);
|
||||||
|
@ -185,13 +160,6 @@ public class TSDBJNIConnector {
|
||||||
|
|
||||||
private native String getErrMsgImp(long pSql);
|
private native String getErrMsgImp(long pSql);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get resultset pointer
|
|
||||||
* Each connection should have a single open result set at a time
|
|
||||||
*/
|
|
||||||
// public long getResultSet() {
|
|
||||||
// return taosResultSetPointer;
|
|
||||||
// }
|
|
||||||
private native long getResultSetImp(long connection, long pSql);
|
private native long getResultSetImp(long connection, long pSql);
|
||||||
|
|
||||||
public boolean isUpdateQuery(long pSql) {
|
public boolean isUpdateQuery(long pSql) {
|
||||||
|
@ -231,6 +199,7 @@ public class TSDBJNIConnector {
|
||||||
// }
|
// }
|
||||||
// return resCode;
|
// return resCode;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private native int freeResultSetImp(long connection, long result);
|
private native int freeResultSetImp(long connection, long result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -323,8 +292,7 @@ public class TSDBJNIConnector {
|
||||||
* Validate if a <I>create table</I> sql statement is correct without actually creating that table
|
* Validate if a <I>create table</I> sql statement is correct without actually creating that table
|
||||||
*/
|
*/
|
||||||
public boolean validateCreateTableSql(String sql) {
|
public boolean validateCreateTableSql(String sql) {
|
||||||
long connection = taos;
|
int res = validateCreateTableSqlImp(taos, sql.getBytes());
|
||||||
int res = validateCreateTableSqlImp(connection, sql.getBytes());
|
|
||||||
return res != 0 ? false : true;
|
return res != 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,9 +84,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return new Timestamp(row.getDate(colIndex).getTime());
|
return new Timestamp(row.getDate(colIndex).getTime());
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
return row.getString(colIndex).getBytes();
|
return row.getString(colIndex) == null ? null : row.getString(colIndex).getBytes();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
return row.getString(colIndex);
|
return row.getString(colIndex) == null ? null : row.getString(colIndex);
|
||||||
default:
|
default:
|
||||||
return row.get(colIndex);
|
return row.get(colIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.taosdata.jdbc.utils;
|
||||||
|
|
||||||
|
public class OSUtils {
|
||||||
|
private static final String OS = System.getProperty("os.name").toLowerCase();
|
||||||
|
|
||||||
|
public static boolean isWindows() {
|
||||||
|
return OS.indexOf("win") >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMac() {
|
||||||
|
return OS.indexOf("mac") >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isLinux() {
|
||||||
|
return OS.indexOf("nux") >= 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,7 +17,6 @@ public class DriverAutoloadTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestful() throws SQLException {
|
public void testRestful() throws SQLException {
|
||||||
// Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
|
||||||
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
||||||
Connection conn = DriverManager.getConnection(url, properties);
|
Connection conn = DriverManager.getConnection(url, properties);
|
||||||
Assert.assertNotNull(conn);
|
Assert.assertNotNull(conn);
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class NullValueInResultSetForJdbcRestfulTest {
|
||||||
|
|
||||||
|
private static final String host = "127.0.0.1";
|
||||||
|
Connection conn;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from weather");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
Object value = rs.getObject(i);
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + value + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() throws SQLException {
|
||||||
|
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
||||||
|
conn = DriverManager.getConnection(url);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
stmt.execute("drop database if exists test_null");
|
||||||
|
stmt.execute("create database if not exists test_null");
|
||||||
|
stmt.execute("use test_null");
|
||||||
|
stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64))");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f1) values(now+1s, 1)");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f2) values(now+2s, 2)");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f3) values(now+3s, 3.0)");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f4) values(now+4s, 4.0)");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f5) values(now+5s, 5)");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f6) values(now+6s, 6)");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')");
|
||||||
|
stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after() {
|
||||||
|
try {
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.taosdata.jdbc.utils;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class OSUtilsTest {
|
||||||
|
|
||||||
|
private String OS;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void inWindows() {
|
||||||
|
Assert.assertEquals(OS.indexOf("win") >= 0, OSUtils.isWindows());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isMac() {
|
||||||
|
Assert.assertEquals(OS.indexOf("mac") >= 0, OSUtils.isMac());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isLinux() {
|
||||||
|
Assert.assertEquals(OS.indexOf("nux") >= 0, OSUtils.isLinux());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
OS = System.getProperty("os.name").toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue