package com.muyu.common.iotdb.config;

import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.session.pool.SessionPool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 时序数据库配置
 *
 * @Author: 胡杨
 * @Name: IotDBConfig
 * @Description: 时序数据库配置
 * @CreatedDate: 2024/9/29 下午9:30
 * @FilePath: com.muyu.data.processing.config
 */

@Configuration
public class IotDBSessionConfig {

    @Value("${spring.iotdb.ip}")
    private String ip;

    @Value("${spring.iotdb.port}")
    private int port;

    @Value("${spring.iotdb.user}")
    private String user;

    @Value("${spring.iotdb.password}")
    private String password;

    @Value("${spring.iotdb.fetchSize}")
    private int fetchSize;

    private static SessionPool sessionPool;
    @Bean
    public SessionPool getSessionPool(){
        if (sessionPool == null) {
            sessionPool = new SessionPool(ip, port, user, password, fetchSize);
            try {
                sessionPool.setTimeZone("+08:00");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return sessionPool;
    }

}
