IoTDB时序数据库V2.0.2代码环境升级

前言:

        本人用的java相关的环境,其它语言环境请自测,但是应该大差不差。

Maven引用

       
            org.apache.iotdb
            iotdb-session
            2.0.2
       

        其中的版本号需要跟所用的数据库版本一致。

包变更

     1.升级之前:  import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;

        升级之后:  import org.apache.tsfile.enums.TSDataType;

     2.升级之前:  import org.apache.iotdb.tsfile.read.common.RowRecord;

        升级之后:  import org.apache.tsfile.read.common.RowRecord;

   如个人用的还有其它包的话,请自行修改。(项目编译就会报错,然后删除原有的import,idea会自动导入最新的包。)

WorkBench

      我用的还是2024年初的版本,能顺利链接到2.0.2版本的IoTDB,所以就没有跟商务要最新的WordkBench。如果不放心可以联系对应商务。

使用表模型

       记着用Table开头的相关SessionPool类,但是看代码上只是对原始的SessionPool进行了一定的封装。

public interface ITableSessionPool extends AutoCloseable {
    ITableSession getSession() throws IoTDBConnectionException;

    void close();
}

import org.apache.iotdb.isession.ITableSession;
import org.apache.iotdb.isession.pool.ITableSessionPool;
import org.apache.iotdb.rpc.IoTDBConnectionException;

public class TableSessionPool implements ITableSessionPool {
    private final SessionPool sessionPool;

    TableSessionPool(SessionPool sessionPool) {
        this.sessionPool = sessionPool;
    }

    public ITableSession getSession() throws IoTDBConnectionException {
        return this.sessionPool.getPooledTableSession();
    }

    public void close() {
        this.sessionPool.close();
    }
}
public class TableModelSessionPoolExample {

  private static final String LOCAL_URL = "127.0.0.1:6667";

  public static void main(String[] args) {

    // don't specify database in constructor
    ITableSessionPool tableSessionPool =
        new TableSessionPoolBuilder()
            .nodeUrls(Collections.singletonList(LOCAL_URL))
            .user("root")
            .password("root")
            .maxSize(1)
            .build();

    try (ITableSession session = tableSessionPool.getSession()) {

      session.executeNonQueryStatement("CREATE DATABASE test1");
      session.executeNonQueryStatement("CREATE DATABASE test2");

      session.executeNonQueryStatement("use test2"); 
     ……………………………等等……………………………

你可能感兴趣的:(IOTDB,iotdb,时序数据库,数据库)