sql上报数据2

/**
     * 初始化入库文件的数据库相关信息
     * @param fileName
     * @param dbInfo
     */
    public SqlLoad(String fileName, DBInfo dbInfo, String loadDirectory)
    {
        this.fileName = fileName;

        // 配置数据库相关信息
        dbType = dbInfo.getDbType();
        host = DasUtil.longToIP(dbInfo.getIp());
        db = dbInfo.getSchema();
        uName = dbInfo.getUserName();
        passwd = dbInfo.getPassword();

        // 生成的load文件目录
        sqlLoadDirectory = loadDirectory;
    }

    /**
     * 上报数据
     *
     * @return
     */
    public boolean sqlldr(AbstractSqlLoad oracleSqlload)
    {
        // 定义处理状态
        boolean result = false;

        // 如果dbType是RptConstants.DB_TYPE_MYSQL ,数据库类型是MySQL
        if (dbType == DasConstants.DB_TYPE_MYSQL)
        {
            MySQLSqlLoad sqlload = new MySQLSqlLoad();

            // 设置相关参数
            sqlload.setDataBase(db);
            sqlload.setHost(host);
            sqlload.setPassword(passwd);
            sqlload.setUser(uName);
            sqlload.setHome(DASProperties.getMysql_home());

            try
            {
                sqlload.setFilenameAndTable(getSqlLoadDirectory(), fileName,
                        fileName.substring(fileName.indexOf("_") + 1, fileName
                                .lastIndexOf(".")));
            }
            catch (IOException e)
            {
                logger.error(e.getMessage(), e);
            }

            // SQLLOAD 加载
            try
            {
                result = sqlload.preform();
            }
            catch (Throwable e)
            {
                logger.error("Mysql sqlload datafile failed.", e);

            }

            // 判断load子进程是否挂死或超时
            if (sqlload.isTimeOut())
            {
                throw new IllegalThreadStateException(
                        "The mysql sqlldr prcess is not determined!");
            }
        }
        // 如果dbType是RptConstants.DB_TYPE_ORACLE,数据库类型是ORACLE
        else if (dbType == DasConstants.DB_TYPE_ORACLE)
        {
            try
            {
                String tabName = fileName.substring(fileName.indexOf("_") + 1,
                        fileName.lastIndexOf(DasConstants.TXT_FIILE_SUFFIX));
                String path = new File(getSqlLoadDirectory(), fileName)
                        .getPath();

                // 在linux服务器下使用oracle oci实现的jni sqlldr。
                if (oracleSqlload.isLinux())
                {
                    result = ociSqlldr(path, oracleSqlload);
                }
                // 其它操作系统使用oracle sqlldr工具进行load数据。
                else
                {
                    result = oracleSqlldr(tabName, path, oracleSqlload);
                }
            }
            catch (Throwable e)
            {
                logger
                        .error("Sqlload datafile " + this.fileName + " failed",
                                e);
            }
        }
        /* 返回处理状态 */
        return result;
    }

你可能感兴趣的:(sql上报数据2)