Search in sources :

Example 6 with DfDataColumn

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

the class DfXlsDataHandlingWriter method filterValidColumn.

protected void filterValidColumn(final DfDataSet dataSet) {
    for (int i = 0; i < dataSet.getTableSize(); i++) {
        final DfDataTable table = dataSet.getTable(i);
        final String tableName = table.getTableDbName();
        final Map<String, DfColumnMeta> metaMetaMap = getColumnMetaMap(tableName);
        for (int j = 0; j < table.getColumnSize(); j++) {
            final DfDataColumn dataColumn = table.getColumn(j);
            if (!metaMetaMap.containsKey(dataColumn.getColumnDbName())) {
                dataColumn.setWritable(false);
            }
        }
    }
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfDataColumn(org.dbflute.helper.dataset.DfDataColumn) DfDataTable(org.dbflute.helper.dataset.DfDataTable)

Example 7 with DfDataColumn

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

the class DfXlsDataHandlingWriter method checkHeaderColumnIfNeeds.

protected void checkHeaderColumnIfNeeds(DfXlsDataResource resource, File file, DfDataTable dataTable, Map<String, DfColumnMeta> columnMetaMap) {
    final String dataDirectory = resource.getDataDirectory();
    if (!isCheckColumnDef(dataDirectory)) {
        return;
    }
    final List<String> columnDefNameList = new ArrayList<String>();
    for (int i = 0; i < dataTable.getColumnSize(); i++) {
        // all columns are target
        final DfDataColumn dataColumn = dataTable.getColumn(i);
        final String columnName = dataColumn.getColumnDbName();
        columnDefNameList.add(columnName);
    }
    // use columnMetaMap to check (not use DataTable's meta data here)
    // at old age, columnMetaMap is not required but required now
    checkColumnDef(file, dataTable.getTableDbName(), columnDefNameList, columnMetaMap);
}
Also used : DfDataColumn(org.dbflute.helper.dataset.DfDataColumn) ArrayList(java.util.ArrayList)

Example 8 with DfDataColumn

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

the class DfXlsDataHandlingWriter method createColumnContainer.

// ===================================================================================
// Column Container
// ================
protected ColumnContainer createColumnContainer(DfDataTable dataTable, DfDataRow dataRow) {
    final ColumnContainer container = new ColumnContainer();
    for (int i = 0; i < dataTable.getColumnSize(); i++) {
        final DfDataColumn dataColumn = dataTable.getColumn(i);
        if (!dataColumn.isWritable()) {
            continue;
        }
        final Object columnValue = dataRow.getValue(i);
        final String columnName = dataColumn.getColumnDbName();
        container.addColumnValue(columnName, columnValue);
        container.addColumnObject(columnName, dataColumn);
    }
    return container;
}
Also used : DfDataColumn(org.dbflute.helper.dataset.DfDataColumn)

Example 9 with DfDataColumn

use of org.dbflute.helper.dataset.DfDataColumn 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 10 with DfDataColumn

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

Aggregations

DfDataColumn (org.dbflute.helper.dataset.DfDataColumn)22 DfDataTable (org.dbflute.helper.dataset.DfDataTable)9 ArrayList (java.util.ArrayList)7 RichTextString (org.apache.poi.ss.usermodel.RichTextString)6 DfDataRow (org.dbflute.helper.dataset.DfDataRow)5 File (java.io.File)3 DfDataSet (org.dbflute.helper.dataset.DfDataSet)3 DfXlsDataEmptyColumnDefException (org.dbflute.exception.DfXlsDataEmptyColumnDefException)2 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)2 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)2 List (java.util.List)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)1