Search in sources :

Example 16 with DfDataTable

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

the class DfTableXlsReader method prepareTable.

// -----------------------------------------------------
// Data Table
// ----------
protected DfDataTable prepareTable(String sheetName, Sheet sheet) {
    String tableName = sheetName;
    if (_tableNameMap != null && !_tableNameMap.isEmpty() && sheetName.startsWith("$")) {
        String realTableName = _tableNameMap.get(sheetName);
        if (realTableName == null) {
            realTableName = _tableNameMap.get(sheetName.substring("$".length()));
            if (realTableName == null) {
                throwXlsReaderMappingTableNotFoundException(sheetName);
            }
        }
        tableName = realTableName;
    }
    final DfDataTable table = _dataSet.addTable(tableName);
    return setupTable(sheet, tableName, table);
}
Also used : DfDataTable(org.dbflute.helper.dataset.DfDataTable) RichTextString(org.apache.poi.ss.usermodel.RichTextString)

Example 17 with DfDataTable

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

the class DfTableXlsReaderTest method test_read_rtrim.

public void test_read_rtrim() throws IOException {
    // ## Arrange ##
    final File xlsFile = prepareTestBasicXlsFile();
    final DfTableXlsReader reader = createTableXlsReader(xlsFile, null, true);
    // ## Act ##
    final DfDataSet dataSet = reader.read();
    // ## Assert ##
    log("[DataSet]:" + ln() + dataSet);
    final int tableSize = dataSet.getTableSize();
    assertTrue(tableSize > 0);
    for (int tableIndex = 0; tableIndex < tableSize; tableIndex++) {
        final DfDataTable table = dataSet.getTable(tableIndex);
        final int columnSize = table.getColumnSize();
        assertTrue(columnSize > 0);
        final int rowSize = table.getRowSize();
        assertTrue(rowSize > 0);
        for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
            final DfDataRow row = table.getRow(rowIndex);
            for (int columnIndex = 0; columnIndex < columnSize; columnIndex++) {
                final DfDataColumn column = table.getColumn(columnIndex);
                final String columnDbName = column.getColumnDbName();
                final Object value = row.getValue(columnDbName);
                if (columnDbName.equals("AAA")) {
                    assertNotNull(value);
                } else if (columnDbName.equals("BBB")) {
                    markHere("nullBBB");
                } else if (columnDbName.equals("CCC")) {
                    assertNotNull(value);
                } else if (columnDbName.equals("DDD")) {
                    assertNotNull(value);
                    String str = (String) value;
                    if (str.length() > str.trim().length()) {
                        fail();
                    }
                } else if (columnDbName.equals("EEE")) {
                    assertNotNull(value);
                    String str = (String) value;
                    if (str.length() > str.trim().length()) {
                        // because of not trimmed column
                        markHere("trimmed_EEE");
                    }
                }
            }
        }
    }
    assertMarked("nullBBB");
    assertMarked("trimmed_EEE");
}
Also used : DfDataSet(org.dbflute.helper.dataset.DfDataSet) DfDataColumn(org.dbflute.helper.dataset.DfDataColumn) DfDataTable(org.dbflute.helper.dataset.DfDataTable) File(java.io.File) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Example 18 with DfDataTable

use of org.dbflute.helper.dataset.DfDataTable 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)

Example 19 with DfDataTable

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

the class DfLReverseOutputHandler method setupXlsDataTable.

// ===================================================================================
// Xls Data
// ========
protected void setupXlsDataTable(DfDataSet dataSet, Table table, List<Map<String, String>> extractedList, int sheetNumber, List<String> sectionInfoList) {
    final List<Map<String, String>> recordList;
    {
        final String tableInfo = "  " + table.getTableDispName() + " (" + extractedList.size() + ")";
        _log.info(tableInfo);
        sectionInfoList.add(tableInfo);
        if (extractedList.size() > _xlsLimit) {
            // just in case
            recordList = extractedList.subList(0, _xlsLimit);
        } else {
            recordList = extractedList;
        }
    }
    final DfDataTable dataTable = new DfDataTable(resolveSheetName(table, sheetNumber));
    final List<Column> columnList = table.getColumnList();
    for (Column column : columnList) {
        if (isExceptCommonColumn(column)) {
            continue;
        }
        dataTable.addColumn(column.getName(), DfDtsColumnTypes.STRING);
    }
    for (Map<String, String> recordMap : recordList) {
        final Set<String> columnNameSet = recordMap.keySet();
        final DfDataRow dataRow = dataTable.addRow();
        for (String columnName : columnNameSet) {
            if (!dataTable.hasColumn(columnName)) {
                // basically excepted common columns
                continue;
            }
            final String value = recordMap.get(columnName);
            dataRow.addValue(columnName, value);
        }
    }
    dataSet.addTable(dataTable);
}
Also used : Column(org.apache.torque.engine.database.model.Column) DfDataTable(org.dbflute.helper.dataset.DfDataTable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Aggregations

DfDataTable (org.dbflute.helper.dataset.DfDataTable)19 DfDataColumn (org.dbflute.helper.dataset.DfDataColumn)9 DfDataRow (org.dbflute.helper.dataset.DfDataRow)9 File (java.io.File)5 ArrayList (java.util.ArrayList)5 DfDataSet (org.dbflute.helper.dataset.DfDataSet)5 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)4 RichTextString (org.apache.poi.ss.usermodel.RichTextString)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 Column (org.apache.torque.engine.database.model.Column)2 DfDtsColumnType (org.dbflute.helper.dataset.types.DfDtsColumnType)2 DfTableXlsReader (org.dbflute.helper.io.xls.DfTableXlsReader)2 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1