package com.codvision.db.constants;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.codvision.db.exception.DataQueryException;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

@Data
@AllArgsConstructor
public class DbQueryProperty implements Serializable {

    private static final long serialVersionUID = 1L;

    private DbType dbType;
    private String host;
    private String username;
    private String password;
    private Integer port;
    private String dbName;
    private String sid;

    /**
     * 参数合法性校验
     */
    public void valid() {
        if (ObjectUtil.isEmpty(dbType) || StrUtil.isEmpty(host) ||
                StrUtil.isEmpty(username) || StrUtil.isEmpty(password) ||
                ObjectUtil.isEmpty(port)) {
            throw new DataQueryException("参数不完整");
        }
        if (DbType.OTHER.getDb().equals(dbType)) {
            throw new DataQueryException("不支持的数据库类型");
        }
    }
}
