Search in sources :

Example 1 with DfDtsColumnType

use of org.dbflute.helper.dataset.types.DfDtsColumnType in project dbflute-core by dbflute.

the class DfTableXlsReader method throwCellValueHandlingException.

protected void throwCellValueHandlingException(DfDataTable table, DfDataColumn column, Row row, Cell cell, Object value, RuntimeException cause) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Failed to handle the cell value on the xls file.");
    br.addItem("Advice");
    br.addElement("Confirm the exception message.");
    br.addElement("The cell value may be wrong type for the column.");
    br.addElement("So confirm the value on the xls file.");
    br.addItem("RuntimeException");
    br.addElement(cause.getMessage());
    br.addItem("Xls File");
    br.addElement(_xlsFile);
    br.addItem("Table");
    br.addElement(table.getTableDbName());
    br.addItem("Column");
    br.addElement(column != null ? column.getColumnDbName() : null);
    br.addItem("Mapping Type");
    final DfDtsColumnType columnType = column.getColumnType();
    br.addElement(columnType != null ? columnType.getType() : null);
    br.addItem("Cell Type");
    if (cell != null) {
        switch(cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                br.addElement("CELL_TYPE_NUMERIC");
                break;
            case Cell.CELL_TYPE_STRING:
                br.addElement("CELL_TYPE_STRING");
                break;
            case Cell.CELL_TYPE_FORMULA:
                br.addElement("CELL_TYPE_FORMULA");
                break;
            case Cell.CELL_TYPE_BLANK:
                br.addElement("CELL_TYPE_BLANK");
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                br.addElement("CELL_TYPE_BOOLEAN");
                break;
            case Cell.CELL_TYPE_ERROR:
                br.addElement("CELL_TYPE_ERROR");
                break;
            default:
                br.addElement(cell.getCellType());
                break;
        }
    }
    br.addItem("Cell Value");
    br.addElement(value);
    br.addItem("Row Number");
    br.addElement(column != null ? row.getRowNum() : null);
    final String msg = br.buildExceptionMessage();
    throw new DfXlsReaderReadFailureException(msg, cause);
}
Also used : DfDtsColumnType(org.dbflute.helper.dataset.types.DfDtsColumnType) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfXlsReaderReadFailureException(org.dbflute.exception.DfXlsReaderReadFailureException) RichTextString(org.apache.poi.ss.usermodel.RichTextString)

Example 2 with DfDtsColumnType

use of org.dbflute.helper.dataset.types.DfDtsColumnType in project dbflute-core by dbflute.

the class DfXlsDataHandlerImpl method setupDefaultValue.

protected void setupDefaultValue(String dataDirectory, final DfDataSet dataSet) {
    final Map<String, String> defaultValueMap = getDefaultValueMap(dataDirectory);
    for (int i = 0; i < dataSet.getTableSize(); i++) {
        final DfDataTable table = dataSet.getTable(i);
        final Set<String> defaultValueMapKeySet = defaultValueMap.keySet();
        final String tableName = table.getTableDbName();
        final Map<String, DfColumnMeta> metaMetaMap = getColumnMetaMap(tableName);
        for (String defaultTargetColumnName : defaultValueMapKeySet) {
            final String defaultValue = defaultValueMap.get(defaultTargetColumnName);
            if (metaMetaMap.containsKey(defaultTargetColumnName) && !table.hasColumn(defaultTargetColumnName)) {
                // values are resolved later so resolve type only here
                final DfDtsColumnType columnType;
                if (defaultValue.equalsIgnoreCase("sysdate")) {
                    columnType = DfDtsColumnTypes.TIMESTAMP;
                } else {
                    columnType = DfDtsColumnTypes.STRING;
                }
                table.addColumn(defaultTargetColumnName, columnType);
                for (int j = 0; j < table.getRowSize(); j++) {
                    final DfDataRow row = table.getRow(j);
                    // value is set later
                    row.addValue(defaultTargetColumnName, null);
                }
            }
        }
    }
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfDtsColumnType(org.dbflute.helper.dataset.types.DfDtsColumnType) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Example 3 with DfDtsColumnType

use of org.dbflute.helper.dataset.types.DfDtsColumnType in project dbflute-core by dbflute.

the class DfDataRow method equals.

// ===================================================================================
// Basic Override
// ==============
@Override
public boolean equals(Object o) {
    if (o == this) {
        return true;
    }
    if (!(o instanceof DfDataRow)) {
        return false;
    }
    final DfDataRow other = (DfDataRow) o;
    for (int i = 0; i < _table.getColumnSize(); ++i) {
        final String columnName = _table.getColumnName(i);
        final Object value = _values.get(i);
        final Object otherValue = other.getValue(columnName);
        final DfDtsColumnType ct = DfDtsColumnTypes.getColumnType(value);
        if (ct.equals(value, otherValue)) {
            continue;
        }
        return false;
    }
    return true;
}
Also used : DfDtsColumnType(org.dbflute.helper.dataset.types.DfDtsColumnType)

Example 4 with DfDtsColumnType

use of org.dbflute.helper.dataset.types.DfDtsColumnType in project dbflute-core by dbflute.

the class DfXlsDataHandlingWriter method setupDefaultValue.

protected void setupDefaultValue(String dataDirectory, final DfDataSet dataSet) {
    final Map<String, String> defaultValueMap = getDefaultValueMap(dataDirectory);
    for (int i = 0; i < dataSet.getTableSize(); i++) {
        final DfDataTable table = dataSet.getTable(i);
        final Set<String> defaultValueMapKeySet = defaultValueMap.keySet();
        final String tableName = table.getTableDbName();
        final Map<String, DfColumnMeta> metaMetaMap = getColumnMetaMap(tableName);
        for (String defaultTargetColumnName : defaultValueMapKeySet) {
            final String defaultValue = defaultValueMap.get(defaultTargetColumnName);
            if (metaMetaMap.containsKey(defaultTargetColumnName) && !table.hasColumn(defaultTargetColumnName)) {
                // values are resolved later so resolve type only here
                final DfDtsColumnType columnType;
                if (defaultValue.equalsIgnoreCase("sysdate")) {
                    columnType = DfDtsColumnTypes.TIMESTAMP;
                } else {
                    columnType = DfDtsColumnTypes.STRING;
                }
                table.addColumn(defaultTargetColumnName, columnType);
                for (int j = 0; j < table.getRowSize(); j++) {
                    final DfDataRow row = table.getRow(j);
                    // value is set later
                    row.addValue(defaultTargetColumnName, null);
                }
            }
        }
    }
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfDtsColumnType(org.dbflute.helper.dataset.types.DfDtsColumnType) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Aggregations

DfDtsColumnType (org.dbflute.helper.dataset.types.DfDtsColumnType)4 DfDataRow (org.dbflute.helper.dataset.DfDataRow)2 DfDataTable (org.dbflute.helper.dataset.DfDataTable)2 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1 DfXlsReaderReadFailureException (org.dbflute.exception.DfXlsReaderReadFailureException)1 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)1