package io.gisbi.extensions.datasource.dto;

import com.jcraft.jsch.Session;
import io.gisbi.extensions.datasource.provider.Provider;
import io.gisbi.extensions.datasource.vo.DatasourceConfiguration;
import lombok.Data;

import java.sql.Connection;

@Data
public class ConnectionObj implements AutoCloseable {


    private Connection connection;
    private Session session;
    private Integer lPort;
    private DatasourceConfiguration configuration;

    @Override
    public void close() throws Exception {
        if (this.connection != null) {
            this.connection.close();
        }

        if (session != null) {
            session.disconnect();
        }

        if(lPort != null){
            Provider.getLPorts().remove(Long.valueOf(lPort));
        }

    }
}
