Search in sources :

Example 1 with DfDataRow

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

the class DfTableXlsReader method prepareLargeDataTable.

// -----------------------------------------------------
// Large Data
// ----------
protected void prepareLargeDataTable() {
    for (int i = 0; i < _workbook.getNumberOfSheets(); ++i) {
        final String sheetName = _workbook.getSheetName(i);
        if (!isLargeDataSheet(sheetName)) {
            continue;
        }
        final Sheet sheet = _workbook.getSheetAt(i);
        // unused
        final String largeTableName = "LARGE_DATA";
        final DfDataTable table = setupTable(sheet, largeTableName, new DfDataTable(largeTableName));
        _largeDataMap = DfCollectionUtil.newLinkedHashMap();
        final Map<Integer, String> indexColumnTitleMap = DfCollectionUtil.newLinkedHashMap();
        for (int columnIndex = 0; columnIndex < table.getColumnSize(); columnIndex++) {
            final DfDataColumn column = table.getColumn(columnIndex);
            final String columnTitle = column.getColumnDbName();
            if (!columnTitle.contains(".")) {
                // should be e.g. MEMBER.MEMBER_NAME
                throwLargeDataInvalidColumnTitleException(sheetName, columnTitle);
            }
            Map<String, String> dataMap = _largeDataMap.get(columnTitle);
            if (dataMap == null) {
                dataMap = DfCollectionUtil.newLinkedHashMap();
            }
            _largeDataMap.put(columnTitle, dataMap);
            indexColumnTitleMap.put(columnIndex, columnTitle);
        }
        for (int rowIndex = 0; rowIndex < table.getRowSize(); rowIndex++) {
            final DfDataRow row = table.getRow(rowIndex);
            for (int columnIndex = 0; columnIndex < table.getColumnSize(); ++columnIndex) {
                final Object obj = row.getValue(columnIndex);
                if (obj == null) {
                    continue;
                }
                // basically String, but just in case
                final String value = obj.toString();
                final String columnTitle = indexColumnTitleMap.get(columnIndex);
                final Map<String, String> dataMap = _largeDataMap.get(columnTitle);
                if (!value.contains(LDATA_KEY_DELIMITER)) {
                    // should be e.g. key(df:delimiter){value}
                    throwLargeDataInvalidManagedDataException(sheetName, columnTitle, row, value);
                }
                final String dataKey = Srl.substringFirstFront(value, LDATA_KEY_DELIMITER);
                final String largeValue = Srl.substringFirstRear(value, LDATA_KEY_DELIMITER);
                final String unquotedValue = Srl.unquoteAnything(largeValue, LDATA_QUOTE_BEGIN, LDATA_QUOTE_END);
                final String existingValue = dataMap.get(dataKey);
                final String realValue = existingValue != null ? existingValue + unquotedValue : unquotedValue;
                dataMap.put(dataKey, realValue);
            }
        }
        // only one
        break;
    }
}
Also used : DfDataColumn(org.dbflute.helper.dataset.DfDataColumn) DfDataTable(org.dbflute.helper.dataset.DfDataTable) RichTextString(org.apache.poi.ss.usermodel.RichTextString) Sheet(org.apache.poi.ss.usermodel.Sheet) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Example 2 with DfDataRow

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

Example 3 with DfDataRow

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

the class DfTableXlsReaderTest method test_read_basic.

// ===================================================================================
// Basic Read
// ==========
public void test_read_basic() throws IOException {
    // ## Arrange ##
    final File xlsFile = prepareTestBasicXlsFile();
    final DfTableXlsReader reader = createTableXlsReader(xlsFile, null, false);
    // ## 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()) {
                        markHere("trimmed_DDD");
                    }
                } else if (columnDbName.equals("EEE")) {
                    assertNotNull(value);
                    String str = (String) value;
                    if (str.length() > str.trim().length()) {
                        markHere("trimmed_EEE");
                    }
                }
            }
        }
    }
    assertMarked("nullBBB");
    assertMarked("trimmed_DDD");
    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 4 with DfDataRow

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

the class DfTableXlsReaderTest method test_read_largeData.

// ===================================================================================
// Large Data
// ==========
public void test_read_largeData() throws IOException {
    // ## Arrange ##
    final File xlsFile = prepareTestLargeDataXlsFile();
    final DfTableXlsReader reader = createTableXlsReader(xlsFile, null, false);
    // ## Act ##
    final DfDataSet dataSet = reader.read();
    // ## Assert ##
    log("[DataSet]:" + ln() + dataSet);
    final String expected1stFoo = "large 1st foo second row";
    final String expected2ndFoo = "large 2nd foo";
    final String expected2ndBar = "large 2nd bar&second row more row starts with space ends with space {brace}{brace} terminal row ";
    int tableSize = dataSet.getTableSize();
    assertTrue(tableSize > 0);
    for (int tableIndex = 0; tableIndex < tableSize; tableIndex++) {
        final DfDataTable table = dataSet.getTable(tableIndex);
        final String tableDbName = table.getTableDbName();
        log("[" + tableDbName + "]");
        final int columnSize = table.getColumnSize();
        final int rowSize = table.getRowSize();
        for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
            final DfDataRow row = table.getRow(rowIndex);
            log("(" + row.getRowNumber() + ")");
            for (int columnIndex = 0; columnIndex < columnSize; columnIndex++) {
                final DfDataColumn column = table.getColumn(columnIndex);
                final String columnDbName = column.getColumnDbName();
                final Object value = row.getValue(columnDbName);
                log(columnDbName + " = " + value);
                if (tableDbName.equals("FIRST_TABLE")) {
                    if (columnDbName.equals("CCC") && value != null && value.equals(expected1stFoo)) {
                        markHere("expected1stFoo");
                    }
                }
                if (tableDbName.equals("SECOND_TABLE")) {
                    if (columnDbName.equals("BBB") && value != null && value.equals(expected2ndFoo)) {
                        markHere("expected2ndFoo");
                    }
                    if (columnDbName.equals("CCC") && value != null && value.equals(expected2ndBar)) {
                        markHere("expected2ndBar");
                    }
                }
            }
        }
    }
    assertMarked("expected1stFoo");
    assertMarked("expected2ndFoo");
    assertMarked("expected2ndBar");
    String actualExp = dataSet.toString();
    assertFalse(actualExp.contains(DfTableXlsReader.LDATA_SHEET_NAME));
    assertFalse(actualExp.contains(DfTableXlsReader.LDATA_KEY_DELIMITER));
    assertFalse(actualExp.contains(DfTableXlsReader.LDATA_REF_PREFIX));
}
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 5 with DfDataRow

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

Aggregations

DfDataRow (org.dbflute.helper.dataset.DfDataRow)10 DfDataTable (org.dbflute.helper.dataset.DfDataTable)7 DfDataColumn (org.dbflute.helper.dataset.DfDataColumn)5 File (java.io.File)3 RichTextString (org.apache.poi.ss.usermodel.RichTextString)3 DfDataSet (org.dbflute.helper.dataset.DfDataSet)3 Cell (org.apache.poi.ss.usermodel.Cell)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)2 BatchUpdateException (java.sql.BatchUpdateException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Row (org.apache.poi.ss.usermodel.Row)1 Column (org.apache.torque.engine.database.model.Column)1 DfDtsRowState (org.dbflute.helper.dataset.states.DfDtsRowState)1 DfDtsColumnType (org.dbflute.helper.dataset.types.DfDtsColumnType)1 LoggingInsertType (org.dbflute.logic.replaceschema.loaddata.impl.dataprop.DfLoadingControlProp.LoggingInsertType)1