Search in sources :

Example 1 with ImportColumnData

use of com.cubrid.common.ui.cubrid.table.dialog.imp.model.ImportColumnData in project cubrid-manager by CUBRID.

the class AbsImportRunnable method processRowData.

protected ImportRowData processRowData(String[] columnArray, String[] columnPattern, int currentRow, File parentFile) throws StopPerformException {
    // FIXME move this logic to core module
    ImportRowData rowData = new ImportRowData(currentRow);
    ImportColumnData columnData = null;
    boolean isSuccess = false;
    try {
        for (int j = 0; j < tableConfig.getPstmList().size(); j++) {
            PstmtParameter pstmtParameter = tableConfig.getPstmList().get(j);
            int column = Integer.parseInt(pstmtParameter.getStringParamValue());
            String content = null;
            String pattern = null;
            if (columnArray.length > column) {
                content = columnArray[column];
            }
            if (columnPattern != null && columnPattern.length > column) {
                pattern = columnPattern[column];
            }
            /*Recored the origin data*/
            columnData = new ImportColumnData(content);
            rowData.getColumnList().add(columnData);
            String dataType = DataType.getRealType(pstmtParameter.getDataType());
            Object value = getRealValueForImport(dataType, content, parentFile);
            try {
                PstmtParameter parameter = new PstmtParameter(pstmtParameter.getParamName(), pstmtParameter.getParamIndex(), pstmtParameter.getDataType(), value);
                parameter.setCharSet(importConfig.getFilesCharset());
                if (StringUtil.isNotEmpty(pattern)) {
                    parameter.setDatePattern(pattern);
                }
                if (value != null && value instanceof File) {
                    parameter.setFileValue(true);
                }
                setPreparedStatementValue(pStmt, parameter, dbCharset);
                columnData.setStatus(ImportStatus.STATUS_FORMAT_SUCCESS);
                isSuccess = true;
            } catch (ParamSetException ex) {
                isSuccess = false;
                LOGGER.debug(ex.getMessage());
            } catch (SQLException ex) {
                isSuccess = false;
                LOGGER.debug(ex.getMessage());
            } finally {
                if (!isSuccess) {
                    columnData.setStatus(ImportStatus.STATUS_FORMAT_FAILED);
                    dataTypeErrorHandling(getErrorMsg(currentRow, column, dataType));
                    PstmtParameter parameter = new PstmtParameter(pstmtParameter.getParamName(), pstmtParameter.getParamIndex(), pstmtParameter.getDataType(), null);
                    parameter.setCharSet(importConfig.getFilesCharset());
                    try {
                        setPreparedStatementNULL(pStmt, parameter);
                    } catch (SQLException e) {
                        LOGGER.debug(e.getMessage());
                    }
                }
            }
        }
    } catch (OutOfMemoryError error) {
        throw new RuntimeException(error);
    }
    return rowData;
}
Also used : ImportRowData(com.cubrid.common.ui.cubrid.table.dialog.imp.model.ImportRowData) ImportColumnData(com.cubrid.common.ui.cubrid.table.dialog.imp.model.ImportColumnData) PstmtParameter(com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter) ParamSetException(com.cubrid.common.ui.spi.util.paramSetter.ParamSetException) SQLException(java.sql.SQLException) File(java.io.File)

Aggregations

PstmtParameter (com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter)1 ImportColumnData (com.cubrid.common.ui.cubrid.table.dialog.imp.model.ImportColumnData)1 ImportRowData (com.cubrid.common.ui.cubrid.table.dialog.imp.model.ImportRowData)1 ParamSetException (com.cubrid.common.ui.spi.util.paramSetter.ParamSetException)1 File (java.io.File)1 SQLException (java.sql.SQLException)1