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

change

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