change
This commit is contained in:
parent
bfdd5c10c0
commit
5a7b932f2f
|
@ -4,7 +4,7 @@ import java.sql.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrapper {
|
||||
public abstract class AbstractDatabaseMetaData extends WrapperImpl implements DatabaseMetaData {
|
||||
|
||||
private final static String PRODUCT_NAME = "TDengine";
|
||||
private final static String PRODUCT_VESION = "2.0.x.x";
|
||||
|
@ -1092,20 +1092,6 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
|
|||
return new EmptyResultSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
try {
|
||||
return iface.cast(this);
|
||||
} catch (ClassCastException cce) {
|
||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
protected ResultSet getCatalogs(Connection conn) throws SQLException {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
|
|
|
@ -18,6 +18,10 @@ public class TSDBError {
|
|||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: (?)");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)");
|
||||
|
||||
/**************************************************/
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
|
||||
|
|
|
@ -12,6 +12,10 @@ public class TSDBErrorNumbers {
|
|||
public static final int ERROR_BATCH_IS_EMPTY = 0x2306; //Batch is empty!
|
||||
public static final int ERROR_INVALID_WITH_EXECUTEQUERY = 0x2307; //Can not issue data manipulation statements with executeQuery()
|
||||
public static final int ERROR_INVALID_WITH_EXECUTEUPDATE = 0x2308; //Can not issue SELECT via executeUpdate()
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE_QUERY = 0x2309; //not a valid sql for executeQuery: (SQL)
|
||||
public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x2310; //Database not specified or available
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x2311; //not a valid sql for executeUpdate: (SQL)
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE = 0x2312; //not a valid sql for execute: (SQL)
|
||||
|
||||
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
|
||||
|
||||
|
@ -37,6 +41,11 @@ public class TSDBErrorNumbers {
|
|||
errorNumbers.add(ERROR_RESULTSET_CLOSED);
|
||||
errorNumbers.add(ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||
errorNumbers.add(ERROR_INVALID_WITH_EXECUTEUPDATE);
|
||||
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_QUERY);
|
||||
errorNumbers.add(ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_UPDATE);
|
||||
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE);
|
||||
|
||||
/*****************************************************/
|
||||
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
|
||||
errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
|
||||
|
|
|
@ -16,9 +16,6 @@ package com.taosdata.jdbc;
|
|||
|
||||
import javax.management.OperationsException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class TSDBSubscribe {
|
||||
private TSDBJNIConnector connecter = null;
|
||||
|
@ -36,9 +33,8 @@ public class TSDBSubscribe {
|
|||
/**
|
||||
* consume
|
||||
*
|
||||
* @throws OperationsException, SQLException
|
||||
*/
|
||||
public TSDBResultSet consume() throws OperationsException, SQLException {
|
||||
public TSDBResultSet consume() throws SQLException {
|
||||
if (this.connecter.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.taosdata.jdbc.AbstractStatement;
|
||||
import com.taosdata.jdbc.TSDBConstants;
|
||||
import com.taosdata.jdbc.TSDBError;
|
||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||
import com.taosdata.jdbc.rs.util.HttpClientPoolUtil;
|
||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||
|
||||
|
@ -63,9 +65,9 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("statement already closed");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sql))
|
||||
throw new SQLException("not a valid sql for executeQuery: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: " + sql);
|
||||
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) {
|
||||
|
@ -73,7 +75,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
}
|
||||
|
||||
if (this.database == null || this.database.isEmpty())
|
||||
throw new SQLException("Database not specified or available");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneQuery(url, sql);
|
||||
}
|
||||
|
@ -81,9 +83,9 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("statement already closed");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql))
|
||||
throw new SQLException("not a valid sql for executeUpdate: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql);
|
||||
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (SqlSyntaxValidator.isDatabaseUnspecifiedUpdate(sql)) {
|
||||
|
@ -91,7 +93,8 @@ public class RestfulStatement extends AbstractStatement {
|
|||
}
|
||||
|
||||
if (this.database == null || this.database.isEmpty())
|
||||
throw new SQLException("Database not specified or available");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneUpdate(url, sql);
|
||||
}
|
||||
|
@ -107,9 +110,9 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("Invalid method call on a closed statement.");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
if (!SqlSyntaxValidator.isValidForExecute(sql))
|
||||
throw new SQLException("not a valid sql for execute: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: " + sql);
|
||||
|
||||
//如果执行了use操作应该将当前Statement的catalog设置为新的database
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
|
@ -134,7 +137,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
|
||||
private ResultSet executeOneQuery(String url, String sql) throws SQLException {
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sql))
|
||||
throw new SQLException("not a select sql for executeQuery: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: " + sql);
|
||||
|
||||
// row data
|
||||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
|
@ -165,7 +168,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
|
||||
private int executeOneUpdate(String url, String sql) throws SQLException {
|
||||
if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql))
|
||||
throw new SQLException("not a valid sql for executeUpdate: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql);
|
||||
|
||||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
|
@ -186,16 +189,16 @@ public class RestfulStatement extends AbstractStatement {
|
|||
|
||||
@Override
|
||||
public int getUpdateCount() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw new SQLException("Invalid method call on a closed statement.");
|
||||
}
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
|
||||
return this.affectedRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBatch(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
@ -213,7 +216,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
return this.conn;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TSDBConnectionTest {
|
|||
}
|
||||
Assert.assertNotNull(rs);
|
||||
subscribe.close(false);
|
||||
} catch (SQLException | OperationsException e) {
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.*;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
Loading…
Reference in New Issue