Implement the TSDBStatement.getConnection function

This commit is contained in:
zyyang-taosdata 2020-09-11 00:02:58 +08:00
parent 8c677755ee
commit 54143e0669
4 changed files with 223 additions and 209 deletions

View File

@ -91,7 +91,7 @@ public class TSDBConnection implements Connection {
/** /**
* @param cfgDirPath * @param cfgDirPath
* @return return the config dir * @return return the config dir
* **/ **/
private File loadConfigDir(String cfgDirPath) { private File loadConfigDir(String cfgDirPath) {
if (cfgDirPath == null) if (cfgDirPath == null)
return loadDefaultConfigDir(); return loadDefaultConfigDir();
@ -103,7 +103,7 @@ public class TSDBConnection implements Connection {
/** /**
* @return search the default config dir, if the config dir is not exist will return null * @return search the default config dir, if the config dir is not exist will return null
* */ */
private File loadDefaultConfigDir() { private File loadDefaultConfigDir() {
File cfgDir; File cfgDir;
File cfgDir_linux = new File("/etc/taos"); File cfgDir_linux = new File("/etc/taos");
@ -132,7 +132,9 @@ public class TSDBConnection implements Connection {
public Statement createStatement() throws SQLException { public Statement createStatement() throws SQLException {
if (!this.connector.isClosed()) { if (!this.connector.isClosed()) {
return new TSDBStatement(this.connector); TSDBStatement statement = new TSDBStatement(this, this.connector);
statement.setConnection(this);
return statement;
} else { } else {
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
} }
@ -153,7 +155,7 @@ public class TSDBConnection implements Connection {
public PreparedStatement prepareStatement(String sql) throws SQLException { public PreparedStatement prepareStatement(String sql) throws SQLException {
if (!this.connector.isClosed()) { if (!this.connector.isClosed()) {
return new TSDBPreparedStatement(this.connector, sql); return new TSDBPreparedStatement(this, this.connector, sql);
} else { } else {
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
} }

View File

@ -42,8 +42,8 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
private SavedPreparedStatement savedPreparedStatement; private SavedPreparedStatement savedPreparedStatement;
TSDBPreparedStatement(TSDBJNIConnector connecter, String sql) { TSDBPreparedStatement(TSDBConnection connection, TSDBJNIConnector connecter, String sql) {
super(connecter); super(connection, connecter);
init(sql); init(sql);
} }

View File

@ -21,10 +21,14 @@ import java.util.List;
public class TSDBStatement implements Statement { public class TSDBStatement implements Statement {
private TSDBJNIConnector connecter = null; private TSDBJNIConnector connecter = null;
/** To store batched commands */ /**
* To store batched commands
*/
protected List<String> batchedArgs; protected List<String> batchedArgs;
/** Timeout for a query */ /**
* Timeout for a query
*/
protected int queryTimeout = 0; protected int queryTimeout = 0;
private Long pSql = 0l; private Long pSql = 0l;
@ -35,7 +39,14 @@ public class TSDBStatement implements Statement {
private boolean isClosed = true; private boolean isClosed = true;
private int affectedRows = 0; private int affectedRows = 0;
TSDBStatement(TSDBJNIConnector connecter) { private TSDBConnection connection;
public void setConnection(TSDBConnection connection) {
this.connection = connection;
}
TSDBStatement(TSDBConnection connection, TSDBJNIConnector connecter) {
this.connection = connection;
this.connecter = connecter; this.connecter = connecter;
this.isClosed = false; this.isClosed = false;
} }
@ -256,6 +267,8 @@ public class TSDBStatement implements Statement {
} }
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
if (this.connecter != null)
return this.connection;
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
} }

View File

@ -61,5 +61,4 @@ public class BatcherInsertTest {
assertEquals(count, numOfRecordsPerTable); assertEquals(count, numOfRecordsPerTable);
} }
} }