📄 abstractimportexportworker.java
字号:
prepStmnt.setDate(index, java.sql.Date.valueOf(value)); } */ } // want a more useful message here than what will likely // be returned due to internal driver code on formatting // a SQL date value from string // (ie. could be parsing error, number format etc...) catch (Exception e) { throw new IllegalArgumentException( "[ " + MiscUtils.getExceptionName(e) + " ] " + "Error converting date/time value - " + "invalid SQL date/time escape format."); } } break; case Types.BLOB: case Types.CLOB: case Types.BINARY: case Types.LONGVARBINARY: prepStmnt.setBytes(index, Base64.decode(value)); break; default: prepStmnt.setObject(index, value); break; } } } /** * Displays an error dialog with the specified message. */ protected void displayErrorDialog(String message) { GUIUtilities.displayErrorMessage(message); } /** * Displays an input dialog to enter the date format mask. * * @return the mask entered */ protected String displayDateFormatDialog() { StringBuffer sb = new StringBuffer(); sb.append("At least one column in the current table is a Date/Time "); sb.append("SQL datatype.\nPlease enter the date format for this "); sb.append("column as displayed in the import file in the field below."); return GUIUtilities.displayInputMessage("Date Field", sb.toString()); } /** * Verifies the date format where applicable. * * @return the date format */ protected String verifyDate() { String format = displayDateFormatDialog(); if (format == null || format.length() == 0) { int yesNo = GUIUtilities.displayConfirmDialog( "This will cancel the current process.\nDo you wish to proceed?"); if (yesNo == JOptionPane.YES_OPTION) { cancelTransfer(); return null; } else { format = displayDateFormatDialog(); } } return format; } /** * Appends the specified text to the output pane as normal * fixed width text. * * @param text - the text to be appended */ protected void appendProgressText(String text) { progress.appendProgressText(text); } /** * Appends the specified text to the output pane as normal * fixed width text. * * @param text - the text to be appended */ protected void appendProgressErrorText(String text) { progress.appendProgressErrorText(text); } /** * Appends the specified buffer to the output pane as normal * fixed width text. * * @param text - the text to be appended */ protected void appendProgressText(StringBuffer text) { progress.appendProgressText(text.toString()); text.setLength(0); } /** * Appends the specified buffer to the output pane as error * fixed width text. * * @param text - the text to be appended */ protected void appendProgressErrorText(StringBuffer text) { progress.appendProgressErrorText(text.toString()); text.setLength(0); } /** * Appends the specified buffer to the output pane as warning * fixed width text. * * @param text - the text to be appended */ protected void appendProgressWarningText(StringBuffer text) { progress.appendProgressWarningText(text.toString()); text.setLength(0); } /** * Sets the progress bar as indeterminate as specified */ protected void setIndeterminateProgress(boolean indeterminate) { progress.setIndeterminate(indeterminate); } /** * Sets the maximum value for the progess bar. * * @param value - the max value */ protected void setProgressBarMaximum(int value) { progress.setMaximum(value); } /** * Sets the progress bar's position during the process. * * @param the new process status */ public void setProgressStatus(int status) { progress.setProgressStatus(status); } /** * Releases all held database resources. */ protected void releaseResources(DatabaseConnection dc) { try { if (stmnt != null) { stmnt.close(); stmnt = null; } if (prepStmnt != null) { prepStmnt.close(); prepStmnt = null; } if (conn != null) { conn.setAutoCommit(true); ConnectionManager.close(dc, conn); conn = null; } } catch (DataSourceException e) { System.err.println( "Exception releasing resources at: " + e.getMessage()); } catch (SQLException e) { System.err.println( "Exception releasing resources at: " + e.getMessage()); } } protected void outputExceptionError(String message, Throwable e) { if (message != null) { outputBuffer.append(message); } outputBuffer.append("\n[ "); outputBuffer.append(MiscUtils.getExceptionName(e)); outputBuffer.append(" ] "); if (e instanceof DataSourceException) { outputBuffer.append(e.getMessage()); outputBuffer.append(((DataSourceException)e).getExtendedMessage()); } else if (e instanceof SQLException) { outputBuffer.append(e.getMessage()); SQLException _e = (SQLException)e; outputBuffer.append("\nError Code: " + _e.getErrorCode()); String state = _e.getSQLState(); if (state != null) { outputBuffer.append("\nSQL State Code: " + state); } } else { outputBuffer.append(e.getMessage()); } appendProgressErrorText(outputBuffer); } /** * Appends the final process results to the output pane. */ protected void printResults() { StringBuffer sb = new StringBuffer(); sb.append("---------------------------\n"); if (result == SUCCESS) { sb.append("Process completed successfully\n"); } else if (result == CANCELLED) { sb.append("Process cancelled.\n"); } else if (result == FAILED) { sb.append("Process completed with errors.\n"); } sb.append("\nTotal duration: "); sb.append(getFormattedDuration()); sb.append("\nTotal tables processed: "); sb.append(tableCount); sb.append("\nTotal records processed: "); sb.append(recordCount); sb.append("\nTotal records transferred: "); sb.append(recordCountProcessed); sb.append("\nErrors: "); sb.append(errorCount); appendProgressText(sb.toString()); // log the output to file GUIUtils.startWorker(new Runnable() { public void run() { logOutputToFile(); } }); } /** * Returns the controlling parent process object. */ protected ImportExportProcess getParent() { return parent; } /** * Cancels the current data transfer process. */ public abstract void cancelTransfer(); /** * Indicates a data transfer process has completed * and clean-up can be performed. */ public abstract void finished(); /** * Logs the start time of this process. */ protected void start() { startTime = System.currentTimeMillis(); } /** * Logs the finish time of this process. */ protected void finish() { finishTime = System.currentTimeMillis(); progress.setStopButtonEnabled(false); } /** * Logs the contents of the output pane to file. */ protected void logOutputToFile() { PrintWriter writer = null; try { String logHeader = null; String path = SystemUtilities.getUserLogsPath(); int transferType = parent.getTransferType(); if (transferType == ImportExportProcess.EXPORT) { logHeader = "[ Data Export Process - "; path += SystemProperties.getProperty("system", "eq.export.log"); } else { logHeader = "[ Data Import Process - "; path += SystemProperties.getProperty("system", "eq.import.log"); } // add a header for this process DateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); StringBuffer sb = new StringBuffer(); sb.append(logHeader); sb.append(df.format(new Date(startTime))); sb.append(" ]\n\n"); sb.append(progress.getText()); sb.append("\n\n"); writer = new PrintWriter(new FileWriter(path, true), true); writer.println(sb.toString()); sb = null; } catch (IOException io) {} finally { if (writer != null) { writer.close(); } writer = null; } } /** * Returns the start time of the import/export process. * * @return the process start time */ public long getStartTime() { return startTime; } /** * Returns the start time of the import/export process. * * @return the process finish time */ public long getFinishTime() { return finishTime; } /** * Returns a formatted string of the duration of the process. * * @return the process duration formatted as hh:mm:ss */ public String getFormattedDuration() { return MiscUtils.formatDuration(finishTime - startTime); } /** * Sets the start time to that specified. */ public void setStartTime(long startTime) { this.startTime = startTime; } /** * Sets the finish time to that specified. */ public void setFinishTime(long finishTime) { this.finishTime = finishTime; } /** * Returns the total record count. */ public int getRecordCount() { return recordCount; } public void setRecordCount(int recordCount) { this.recordCount = recordCount; } public int getRecordCountProcessed() { return recordCountProcessed; } public void setRecordCountProcessed(int recordCountProcessed) { this.recordCountProcessed = recordCountProcessed; } public int getErrorCount() { return errorCount; } public void setErrorCount(int errorCount) { this.errorCount = errorCount; } public int getTableCount() { return tableCount; } public void setTableCount(int tableCount) { this.tableCount = tableCount; } public String getResult() { return result; } public void setResult(String result) { this.result = result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -