⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 importdelimitedworker.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    boundVariables.clear();                    for (int k = 0; k < columnCount; k++) {                        boundVariables.put(columns.get(k), VARIABLE_NOT_BOUND);                    }                    row = reader.readLine();                    lineNumber++;                    String[] _columns = MiscUtils.splitSeparatedValues(row, delim);                    if (_columns != null && _columns.length > 0) {                        filesColumnCount = _columns.length;                                                // --------------------------------------                        // first determine if we have any columns in the                        // input file that were not selected for import                        // reset the ignored columns                        ignoredIndexes.clear();                                                // set up another list to re-add the columns in                        // the order in which they appear in the file.                        // all other columns will be added to the end                        Vector<ColumnData> temp = new Vector(columnCount);                                                ColumnData cd = null;                        int ignoredIndex = -1;                        for (int j = 0; j < _columns.length; j++) {                            ignoredIndex = j;                            String column = _columns[j];                            for (int k = 0; k < columnCount; k++) {                                cd = columns.get(k);                                String _column = cd.getColumnName();                                if (_column.equalsIgnoreCase(column)) {                                    temp.add(cd);                                    fileImportedColumns.put(cd, INCLUDED_COLUMN);                                    ignoredIndex = -1;                                    break;                                }                            }                                                        if (ignoredIndex != -1) {                                ignoredIndexes.add(new Integer(ignoredIndex));                            }                        }                        ignoredCount = ignoredIndexes.size();                                                // if we didn't find any columns at all, show warning                        if (temp.size() == 0) {                            String message = "No matching column names were " +                                    "found within the specified file's first line.\n" +                                    "The current file will be ignored.";                            outputBuffer.append(message);                            appendProgressWarningText(outputBuffer);                            int yesNo = GUIUtilities.displayYesNoDialog(                                    message + "\nDo you wish to continue?",                                    "Warning");                            if (yesNo == JOptionPane.YES_OPTION) {                                continue;                            } else {                                throw new InterruptedException();                            }                        }                        else {                            // add any other selected columns to the                            // end of the temp list with the columns                            // available in the file                            boolean addColumn = false;                            for (int k = 0; k < columnCount; k++) {                                addColumn = false;                                cd = columns.get(k);                                for (int j = 0, n = temp.size(); j < n; j++) {                                    addColumn = true;                                    if (temp.get(j) == cd) {                                        addColumn = false;                                        break;                                    }                                }                                                                if (addColumn) {                                    temp.add(cd);                                }                            }                            columns = temp; // note: size should not have changed                        }                                           }                }                // otherwise just populate the columns in the file                // with all the selected columns                else {                    for (int j = 0; j < columnCount; j++) {                        fileImportedColumns.put(columns.get(j), INCLUDED_COLUMN);                    }                }                /*                Log.debug("ignored count: " + ignoredCount);                for (int j = 0; j < columnCount; j++) {                    Log.debug("column: " + columns.get(j));                }                */                fileSize = inputFile.length();                progressStatus = 10;                progressCheck = (int)(fileSize / progressStatus);                // prepare the statement                prepareStatement(dto.getTableName(), columns);                                if (parsingDates && dateFormatString == null) {                    // check for a date data type                    for (int j = 0; j < columnCount; j++) {                        if (dateFormatString == null && !hasDate) {                            ColumnData cd = columns.get(j);                            if (fileImportedColumns.containsKey(cd)) {                                int sqlType = cd.getSQLType();                                if (sqlType == Types.DATE || sqlType == Types.TIME ||                                        sqlType == Types.TIMESTAMP) {                                    hasDate = true;                                    break;                                }                            }                        }                    }                                        if (hasDate && dateFormatString == null) {                        dateFormatString = verifyDate();                        if (dateFormatString == null) {                            fileReader.close();                            setProgressStatus(100);                            throw new InterruptedException();                        }                        df = new SimpleDateFormat(dateFormatString);                    }                }                                rowLength = 0;                                while ((row = reader.readLine()) != null) {                    insertLine = true;                    lineNumber++;                    tableRowCount++;                    totalRecordCount++;                    if (Thread.interrupted()) {                        fileReader.close();                        printTableResult(tableRowCount,                                 tableCommitCount, dto.getTableName());                        setProgressStatus(100);                        throw new InterruptedException();                    }                    currentRowLength = row.length();                                        if (currentRowLength == 0) {                        outputBuffer.append("Line ");                        outputBuffer.append(lineNumber);                        outputBuffer.append(" contains no delimited values");                        appendProgressWarningText(outputBuffer);                        int yesNo = GUIUtilities.displayYesNoDialog(                                "No values provided from line " +                                lineNumber + " - the row is blank.\n" +                                "Do you wish to continue?",                                "Warning");                        if (yesNo == JOptionPane.YES_OPTION) {                            continue;                        } else {                            throw new InterruptedException();                        }                    }                                        rowLength += currentRowLength;                    if (progressCheck < rowLength) {                        setProgressStatus(progressStatus);                        progressStatus += 10;                        rowLength = 0;                    }                    // reset matcher with current row                    matcher.reset(row);                    int index = 0;                    int lastIndex = -1;                    int loopIgnoredCount = 0;                    //Log.debug(row);                                        for (int j = 0; j < filesColumnCount; j++) {                        if (matcher.find(index)) {                            String first = matcher.group(2);                            if (first != null) {                                value = first;                            }                            else {                                qMatcher.reset(matcher.group(1));                                value = qMatcher.replaceAll("\"");                            }                            index = matcher.end();                                                        // check if its an ignored column                            if (ignoredCount > 0) {                                if (isIndexIgnored(ignoredIndexes, j)) {                                    loopIgnoredCount++;                                    continue;                                }                                                            }                                                    }                        else {                                                        // not enough delims check                            if (j < (filesColumnCount - 1) &&                                     index > (currentRowLength - 1)) {                                outputBuffer.append("Insufficient number of column ");                                outputBuffer.append("values provided at line ");                                outputBuffer.append(lineNumber);                                appendProgressErrorText(outputBuffer);                                int yesNo = GUIUtilities.displayYesNoDialog(                                        "Insufficient number of values provided from line " +                                        lineNumber + ".\n" +                                        "Do you wish to continue?",                                        "Warning");                                if (yesNo == JOptionPane.YES_OPTION) {                                    insertLine = false;                                    break;                                }                                else {                                    throw new InterruptedException();                                }                            }                            else {                                // check if we're on a delim the matcher didn't pick up                                if (row.charAt(index) == charDelim) {                                    // increment index                                    index++;                                    // assign as null value                                    value = null;                                }                            }                        }                        // check if we landed on the same index - likely null value                        if (index == lastIndex) {                            index++;                        }                        lastIndex = index;                        if (value != null && value.trim().length() == 0) {                            value = null;                        }                                                try {                            ColumnData cd = columns.get(j - loopIgnoredCount);                            setValue(value,                                      getIndexOfColumn(columns, cd) + 1,                                     cd.getSQLType(),                                     trimWhitespace,                                     df);                                                        if (hasColumnNames) {                                boundVariables.put(cd, VARIABLE_BOUND);                            }                        }                        catch (ParseException e) {                            errorCount++;                            failed = true;                            outputBuffer.append("Error parsing date value on line ");                            outputBuffer.append(lineNumber);                            outputBuffer.append(" at position ");                            outputBuffer.append(j);                            outputExceptionError(null, e);                            break;                        }                        catch (NumberFormatException e) {                            errorCount++;                            failed = true;                            outputBuffer.append("Error parsing value on line ");                            outputBuffer.append(lineNumber);                            outputBuffer.append(" at position ");                            outputBuffer.append(j);                            outputExceptionError(null, e);                            break;                        }                    }                                        if (!insertLine) {                        prepStmnt.clearParameters();                        continue;                    }                                        if (failed && haltOnError) {                        processResult = FAILED;                        break;                    }                                        // execute the statement                    try {                        // check all variables are bound if we used                        // the column names from the first row                        if (hasColumnNames) {                                                        index = 0;                            // check all variables are bound - insert NULL otherwise                            for (Iterator j = boundVariables.keySet().iterator(); j.hasNext();) {                                ColumnData cd = (ColumnData)j.next();                                //Log.debug(" col: " + cd +                                 //        " bound state: " + boundVariables.get(cd));                                if (boundVariables.get(cd) == VARIABLE_NOT_BOUND) {                                    index = getIndexOfColumn(columns, cd);                                    prepStmnt.setNull(index + 1, cd.getSQLType());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -