提交 7303c5d0 编写于 作者: Z zyyang

change

上级 b2afe151
...@@ -497,12 +497,12 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData { ...@@ -497,12 +497,12 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
throws SQLException { throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); return null;
} }
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern,
String columnNamePattern) throws SQLException { String columnNamePattern) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); return null;
} }
public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
......
...@@ -20,13 +20,11 @@ import java.util.List; ...@@ -20,13 +20,11 @@ import java.util.List;
public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
private String dbProductName = null; private String url;
private String url = null; private String userName;
private String userName = null; private Connection conn;
private Connection conn = null;
public TSDBDatabaseMetaData(String dbProductName, String url, String userName) { public TSDBDatabaseMetaData(String url, String userName) {
this.dbProductName = dbProductName;
this.url = url; this.url = url;
this.userName = userName; this.userName = userName;
} }
...@@ -116,7 +114,9 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -116,7 +114,9 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
return false; return false;
} }
public boolean supportsMixedCaseIdentifiers() throws SQLException { public boolean supportsMixedCaseIdentifiers() throws SQLException {
//像database、table这些对象的标识符,在存储时是否采用大小写混合的模式
return false; return false;
} }
...@@ -125,7 +125,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -125,7 +125,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public boolean storesLowerCaseIdentifiers() throws SQLException { public boolean storesLowerCaseIdentifiers() throws SQLException {
return false; return true;
} }
public boolean storesMixedCaseIdentifiers() throws SQLException { public boolean storesMixedCaseIdentifiers() throws SQLException {
...@@ -133,6 +133,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -133,6 +133,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
//像database、table这些对象的标识符,在存储时是否采用大小写混合、并带引号的模式
return false; return false;
} }
...@@ -193,10 +194,12 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -193,10 +194,12 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public boolean nullPlusNonNullIsNull() throws SQLException { public boolean nullPlusNonNullIsNull() throws SQLException {
// null + non-null != null
return false; return false;
} }
public boolean supportsConvert() throws SQLException { public boolean supportsConvert() throws SQLException {
// 是否支持转换函数convert
return false; return false;
} }
...@@ -221,7 +224,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -221,7 +224,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public boolean supportsGroupBy() throws SQLException { public boolean supportsGroupBy() throws SQLException {
return false; return true;
} }
public boolean supportsGroupByUnrelated() throws SQLException { public boolean supportsGroupByUnrelated() throws SQLException {
...@@ -493,7 +496,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -493,7 +496,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public int getDefaultTransactionIsolation() throws SQLException { public int getDefaultTransactionIsolation() throws SQLException {
return 0; return Connection.TRANSACTION_NONE;
} }
public boolean supportsTransactions() throws SQLException { public boolean supportsTransactions() throws SQLException {
...@@ -501,6 +504,8 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -501,6 +504,8 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public boolean supportsTransactionIsolationLevel(int level) throws SQLException { public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
if (level == Connection.TRANSACTION_NONE)
return true;
return false; return false;
} }
...@@ -522,28 +527,27 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -522,28 +527,27 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
throws SQLException { throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); return null;
} }
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern,
String columnNamePattern) throws SQLException { String columnNamePattern) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); return null;
} }
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
throws SQLException { if (conn == null || conn.isClosed()) {
Statement stmt = null; throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
if (null != conn && !conn.isClosed()) {
stmt = conn.createStatement();
if (catalog == null || catalog.length() < 1) {
catalog = conn.getCatalog();
} }
try (Statement stmt = conn.createStatement()) {
if (catalog == null || catalog.isEmpty())
return null;
stmt.executeUpdate("use " + catalog); stmt.executeUpdate("use " + catalog);
ResultSet resultSet0 = stmt.executeQuery("show tables"); ResultSet resultSet0 = stmt.executeQuery("show tables");
GetTablesResultSet getTablesResultSet = new GetTablesResultSet(resultSet0, catalog, schemaPattern, tableNamePattern, types); GetTablesResultSet getTablesResultSet = new GetTablesResultSet(resultSet0, catalog, schemaPattern, tableNamePattern, types);
return getTablesResultSet; return getTablesResultSet;
} else {
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
} }
} }
...@@ -552,14 +556,12 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -552,14 +556,12 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public ResultSet getCatalogs() throws SQLException { public ResultSet getCatalogs() throws SQLException {
if (conn == null || conn.isClosed())
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
if (conn != null && !conn.isClosed()) { try (Statement stmt = conn.createStatement()) {
Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("show databases");
ResultSet resultSet0 = stmt.executeQuery("show databases"); return new CatalogResultSet(rs);
CatalogResultSet resultSet = new CatalogResultSet(resultSet0);
return resultSet;
} else {
return getEmptyResultSet();
} }
} }
...@@ -567,7 +569,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -567,7 +569,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
// set up ColumnMetaDataList // set up ColumnMetaDataList
List<ColumnMetaData> columnMetaDataList = new ArrayList<ColumnMetaData>(1); List<ColumnMetaData> columnMetaDataList = new ArrayList<>(1);
ColumnMetaData colMetaData = new ColumnMetaData(); ColumnMetaData colMetaData = new ColumnMetaData();
colMetaData.setColIndex(0); colMetaData.setColIndex(0);
colMetaData.setColName("TABLE_TYPE"); colMetaData.setColName("TABLE_TYPE");
...@@ -576,7 +578,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -576,7 +578,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
columnMetaDataList.add(colMetaData); columnMetaDataList.add(colMetaData);
// set up rowDataList // set up rowDataList
List<TSDBResultSetRowData> rowDataList = new ArrayList<TSDBResultSetRowData>(2); List<TSDBResultSetRowData> rowDataList = new ArrayList<>(2);
TSDBResultSetRowData rowData = new TSDBResultSetRowData(); TSDBResultSetRowData rowData = new TSDBResultSetRowData();
rowData.setString(0, "TABLE"); rowData.setString(0, "TABLE");
rowDataList.add(rowData); rowDataList.add(rowData);
...@@ -596,11 +598,10 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -596,11 +598,10 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
Statement stmt = null; Statement stmt = null;
if (null != conn && !conn.isClosed()) { if (null != conn && !conn.isClosed()) {
stmt = conn.createStatement(); stmt = conn.createStatement();
if (catalog == null || catalog.length() < 1) { if (catalog == null || catalog.isEmpty())
catalog = conn.getCatalog(); return null;
}
stmt.executeUpdate("use " + catalog);
stmt.executeUpdate("use " + catalog);
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
// set up ColumnMetaDataList // set up ColumnMetaDataList
List<ColumnMetaData> columnMetaDataList = new ArrayList<>(24); List<ColumnMetaData> columnMetaDataList = new ArrayList<>(24);
...@@ -856,7 +857,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -856,7 +857,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
return null; return this.conn;
} }
public boolean supportsSavepoints() throws SQLException { public boolean supportsSavepoints() throws SQLException {
...@@ -889,11 +890,13 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { ...@@ -889,11 +890,13 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
} }
public boolean supportsResultSetHoldability(int holdability) throws SQLException { public boolean supportsResultSetHoldability(int holdability) throws SQLException {
if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT)
return true;
return false; return false;
} }
public int getResultSetHoldability() throws SQLException { public int getResultSetHoldability() throws SQLException {
return 0; return ResultSet.HOLD_CURSORS_OVER_COMMIT;
} }
public int getDatabaseMajorVersion() throws SQLException { public int getDatabaseMajorVersion() throws SQLException {
......
...@@ -214,7 +214,7 @@ public class TSDBDriver extends AbstractTaosDriver { ...@@ -214,7 +214,7 @@ public class TSDBDriver extends AbstractTaosDriver {
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_HOST, url); urlProps.setProperty(TSDBDriver.PROPERTY_KEY_HOST, url);
} }
this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, urlProps.getProperty(TSDBDriver.PROPERTY_KEY_USER)); this.dbMetaData = new TSDBDatabaseMetaData(urlForMeta, urlProps.getProperty(TSDBDriver.PROPERTY_KEY_USER));
return urlProps; return urlProps;
} }
......
...@@ -8,7 +8,6 @@ import java.util.List; ...@@ -8,7 +8,6 @@ import java.util.List;
public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData { public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
private final String url; private final String url;
private final String userName; private final String userName;
private final Connection connection; private final Connection connection;
......
...@@ -168,6 +168,7 @@ public class DatabaseMetaDataTest { ...@@ -168,6 +168,7 @@ public class DatabaseMetaDataTest {
try { try {
databaseMetaData.getProcedures("", "", ""); databaseMetaData.getProcedures("", "", "");
} catch (Exception e) { } catch (Exception e) {
} }
try { try {
databaseMetaData.getProcedureColumns("", "", "", ""); databaseMetaData.getProcedureColumns("", "", "", "");
...@@ -176,6 +177,7 @@ public class DatabaseMetaDataTest { ...@@ -176,6 +177,7 @@ public class DatabaseMetaDataTest {
try { try {
databaseMetaData.getTables("", "", "", new String[]{""}); databaseMetaData.getTables("", "", "", new String[]{""});
} catch (Exception e) { } catch (Exception e) {
} }
databaseMetaData.getSchemas(); databaseMetaData.getSchemas();
databaseMetaData.getCatalogs(); databaseMetaData.getCatalogs();
......
package com.taosdata.jdbc.cases;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
public class MultiThreadsWithSameStatmentTest {
private Connection conn;
private Statement stmt;
@Before
public void before() {
try {
Class.forName("com.taosdata.jdbc.TSDBDriver");
conn = DriverManager.getConnection("jdbc:TAOS://localhost:6030/?user=root&password=taosdata");
stmt = conn.createStatement();
stmt.execute("create database if not exists jdbctest");
stmt.executeUpdate("create table jdbctest.weather (ts timestamp, f1 int)");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
@Test
public void test() {
Thread t1 = new Thread(() -> {
try {
ResultSet resultSet = stmt.executeQuery("select * from log.");
sleep(5000);
while (resultSet.next()) {
ResultSetMetaData metaData = resultSet.getMetaData();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
System.out.print(metaData.getColumnLabel(i) + ": " + resultSet.getString(i));
}
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
}
});
Thread t2 = new Thread(() -> {
try {
stmt.executeUpdate("insert into jdbctest.weather values(now,1)");
} catch (SQLException e) {
e.printStackTrace();
}
});
t1.start();
sleep(1000);
t2.start();
}
private void sleep(long mills) {
try {
TimeUnit.MILLISECONDS.sleep(mills);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@After
public void after() {
try {
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册