提交 5d51c463 编写于 作者: Z zyyang

change

上级 7db50342
......@@ -17,12 +17,12 @@ package com.taosdata.jdbc;
import java.math.BigDecimal;
import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class TSDBResultSet extends AbstractResultSet implements ResultSet {
private TSDBJNIConnector jniConnector = null;
private TSDBJNIConnector jniConnector;
private final TSDBStatement statement;
private long resultSetPointer = 0L;
private List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
......@@ -33,24 +33,6 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
private boolean lastWasNull = false;
private final int COLUMN_INDEX_START_VALUE = 1;
private int rowIndex = 0;
public TSDBJNIConnector getJniConnector() {
return jniConnector;
}
public void setJniConnector(TSDBJNIConnector jniConnector) {
this.jniConnector = jniConnector;
}
public long getResultSetPointer() {
return resultSetPointer;
}
public void setResultSetPointer(long resultSetPointer) {
this.resultSetPointer = resultSetPointer;
}
public void setBatchFetch(boolean batchFetch) {
this.batchFetch = batchFetch;
}
......@@ -59,10 +41,6 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
return this.batchFetch;
}
public List<ColumnMetaData> getColumnMetaDataList() {
return columnMetaDataList;
}
public void setColumnMetaDataList(List<ColumnMetaData> columnMetaDataList) {
this.columnMetaDataList = columnMetaDataList;
}
......@@ -71,25 +49,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
return rowData;
}
public void setRowData(TSDBResultSetRowData rowData) {
this.rowData = rowData;
}
public boolean isLastWasNull() {
return lastWasNull;
}
public void setLastWasNull(boolean lastWasNull) {
this.lastWasNull = lastWasNull;
}
public TSDBResultSet() {
}
public TSDBResultSet(TSDBJNIConnector connector, long resultSetPointer) throws SQLException {
public TSDBResultSet(TSDBStatement statement, TSDBJNIConnector connector, long resultSetPointer) throws SQLException {
this.statement = statement;
this.jniConnector = connector;
this.resultSetPointer = resultSetPointer;
int code = this.jniConnector.getSchemaMetaData(this.resultSetPointer, this.columnMetaDataList);
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
......@@ -349,75 +313,109 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
@Override
public boolean isBeforeFirst() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
return false;
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean isAfterLast() throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean isFirst() throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean isLast() throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public void beforeFirst() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public void afterLast() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean first() throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean last() throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public int getRow() throws SQLException {
return 0;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean absolute(int row) throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean relative(int rows) throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public boolean previous() throws SQLException {
return false;
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
public Statement getStatement() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
// return this.statement;
return null;
return this.statement;
}
public boolean isClosed() throws SQLException {
//TODO:
//TODO: check if need release resources
boolean isClosed = true;
if (jniConnector != null) {
isClosed = jniConnector.isResultsetClosed();
......
......@@ -56,7 +56,7 @@ public class TSDBStatement extends AbstractStatement {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
}
TSDBResultSet res = new TSDBResultSet(this.connector, pSql);
TSDBResultSet res = new TSDBResultSet(this, this.connector, pSql);
res.setBatchFetch(this.connection.getBatchFetch());
return res;
}
......@@ -97,7 +97,7 @@ public class TSDBStatement extends AbstractStatement {
return false;
}
this.resultSet = new TSDBResultSet(this.connector, pSql);
this.resultSet = new TSDBResultSet(this, this.connector, pSql);
this.resultSet.setBatchFetch(this.connection.getBatchFetch());
return true;
}
......
......@@ -50,7 +50,7 @@ public class TSDBSubscribe {
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
return null;
} else {
return new TSDBResultSet(this.connecter, resultSetPointer);
return new TSDBResultSet(null, this.connecter, resultSetPointer);
}
}
......
......@@ -115,6 +115,7 @@ public class ResultSetTest {
public void testUnsupport() throws SQLException {
statement.executeQuery("show databases");
resSet = statement.getResultSet();
Assert.assertNotNull(resSet.unwrap(TSDBResultSet.class));
Assert.assertTrue(resSet.isWrapperFor(TSDBResultSet.class));
try {
......
......@@ -55,7 +55,7 @@ public class StatementTest {
statement.executeUpdate("create database if not exists " + dbName);
statement.executeUpdate("create table if not exists " + dbName + "." + tName + "(ts timestamp, k1 int)");
statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
statement.executeQuery("select * from " + dbName + "." + tName);
statement.execute("select * from " + dbName + "." + tName);
ResultSet resultSet = statement.getResultSet();
Assert.assertNotNull(resultSet);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册