class DatabaseService {

    public ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo) throws SQLException {
        // replace to current User's group
        if (dataBaseInfo.isAddToGroup()) {
            if (null == dataBaseInfo.getDal_group_id()) {
                List<UserGroup> list = userGroupDao.getUserGroupByUserId(user.getId());
                if (CollectionUtils.isNotEmpty(list)) {
                    dataBaseInfo.setDal_group_id(list.get(0).getGroup_id());
                }
            }
        }
        String dbname = dataBaseInfo.getDbname().trim();
        int maxlegnth = consts.dataBaseNameMaxLength;
        if (dbname.length() > maxlegnth) {
            return ServiceResult.fail(dbname + "物理库名称过长，不能大于" + maxlegnth + "个字符");
        }
        dataBaseInfo.setDb_password(DasEnv.encdecConfiguration.encrypt(dataBaseInfo.getDb_password()));
        Long dbId = dataBaseDao.insertDataBaseInfo(dataBaseInfo);
        if (dbId <= 0) {
            return ServiceResult.fail();
        }

        dataBaseInfo.setId(dbId);
        return genDefaultDbsetAndEntry(dataBaseInfo);
    }

}