Search in sources :

Example 6 with DfDataSet

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

the class DfTableXlsWriterTest method test_write_emptyString_quoted.

// ===================================================================================
// EmptyString
// ===========
public void test_write_emptyString_quoted() throws Exception {
    // ## Arrange ##
    DfTableXlsReader existingReader = createTableXlsReader(prepareTestLargeDataXlsFile());
    DfDataSet baseSet = existingReader.read();
    baseSet.getTable(0).getRow(1).setValue(1, "");
    String baseExp = baseSet.toString();
    log(ln() + baseExp);
    assertContains(baseExp, ", ,");
    assertContains(baseExp, ", null,");
    String fileName = "output-table-xls-large-data-handling.xls";
    String path = getTestCaseBuildDir().getCanonicalPath() + "/../" + fileName;
    File outputFile = new File(path);
    DfTableXlsWriter writer = new DfTableXlsWriter(outputFile);
    writer.largeDataHandling().quoteEmptyString().cellLengthLimit(5);
    // ## Act ##
    writer.write(baseSet);
    // ## Assert ##
    refresh();
    DfTableXlsReader outputReader = createTableXlsReader(outputFile);
    DfDataSet actualSet = outputReader.read();
    log(ln() + actualSet);
    String actualExp = actualSet.toString();
    assertNotSame(baseExp, actualExp);
    assertContains(actualExp, ", \"\",");
    assertContains(actualExp, ", null,");
    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) File(java.io.File)

Example 7 with DfDataSet

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

the class DfLReverseOutputHandler method transferToXls.

/**
 * Transfer data to excel. (state-less)
 * @param tableMap The map of table. (NotNull)
 * @param loadDataMap The map of load data. (NotNull)
 * @param limit The limit of extracted record. (MinusAllowed: if minus, no limit)
 * @param xlsFile The file of XLS. (NotNull)
 * @param resource The resource information of output data. (NotNull)
 * @param sectionInfoList The list of section info. (NotNull)
 */
protected void transferToXls(Map<String, Table> tableMap, Map<String, DfLReverseDataResult> loadDataMap, int limit, File xlsFile, DfLReverseOutputResource resource, List<String> sectionInfoList) {
    final DfDataSet dataSet = new DfDataSet();
    int sheetNumber = 0;
    for (Entry<String, Table> entry : tableMap.entrySet()) {
        ++sheetNumber;
        final String tableDbName = entry.getKey();
        final Table table = entry.getValue();
        final DfLReverseDataResult dataResult = loadDataMap.get(tableDbName);
        if (dataResult.isLargeData()) {
            outputDelimiterData(table, dataResult, limit, resource, sheetNumber, sectionInfoList);
        } else {
            final List<Map<String, String>> extractedList = dataResult.getResultList();
            setupXlsDataTable(dataSet, table, extractedList, sheetNumber, sectionInfoList);
        }
    }
    if (dataSet.getTableSize() > 0) {
        writeXlsData(dataSet, xlsFile);
    }
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataSet(org.dbflute.helper.dataset.DfDataSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 8 with DfDataSet

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

the class DfTableXlsReader method setupWorkbook.

// -----------------------------------------------------
// Set up Workbook
// ---------------
protected void setupWorkbook(Workbook workbook) {
    _workbook = workbook;
    _dataFormat = _workbook.createDataFormat();
    _dataSet = new DfDataSet();
    prepareLargeDataTable();
    for (int i = 0; i < _workbook.getNumberOfSheets(); ++i) {
        final String sheetName = _workbook.getSheetName(i);
        if (isCommentOutSheet(sheetName)) {
            // since 0.7.9
            _log.info("*The sheet has comment-out mark so skip it: " + sheetName);
            continue;
        }
        if (isSkipSheet(sheetName)) {
            // since 0.7.9 for [DBFLUTE-251]
            _log.info("*The sheet name matched skip-sheet specification so skip it: " + sheetName);
            continue;
        }
        if (isLargeDataSheet(sheetName)) {
            // already analyzed here
            continue;
        }
        prepareTable(sheetName, _workbook.getSheetAt(i));
    }
}
Also used : DfDataSet(org.dbflute.helper.dataset.DfDataSet) RichTextString(org.apache.poi.ss.usermodel.RichTextString)

Example 9 with DfDataSet

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

the class DfXlsDataHandlerImpl method writeSeveralData.

// ===================================================================================
// Write
// =====
public void writeSeveralData(DfXlsDataResource resource, DfLoadedDataInfo loadedDataInfo) {
    final String dataDirectory = resource.getDataDirectory();
    final List<File> xlsList = getXlsList(resource);
    if (xlsList.isEmpty()) {
        return;
    }
    final StringBuilder msgSb = new StringBuilder();
    for (File file : xlsList) {
        _log.info("/= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ");
        _log.info("writeData(" + file + ")");
        _log.info("= = = = = = =/");
        final DfTableXlsReader xlsReader = createTableXlsReader(dataDirectory, file);
        final DfDataSet dataSet = xlsReader.read();
        filterValidColumn(dataSet);
        setupDefaultValue(dataDirectory, dataSet);
        doWriteDataSet(resource, file, dataSet, msgSb);
        // this has no warning fixedly
        final boolean warned = false;
        loadedDataInfo.addLoadedFile(resource.getEnvType(), "xls", null, file.getName(), warned);
    }
    prepareImplicitClassificationLazyCheck(loadedDataInfo);
    outputResultMark(resource.getDataDirectory(), msgSb.toString());
}
Also used : DfDataSet(org.dbflute.helper.dataset.DfDataSet) File(java.io.File) DfTableXlsReader(org.dbflute.helper.io.xls.DfTableXlsReader)

Example 10 with DfDataSet

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

the class DfLReverseProcess method extractExistingXlsInfo.

// ===================================================================================
// Existing Xls
// ============
protected DfLReverseExistingXlsInfo extractExistingXlsInfo(File baseDir) {
    final List<File> existingXlsList = extractExistingXlsList(baseDir);
    final Map<File, List<String>> existingXlsTableListMap = DfCollectionUtil.newLinkedHashMap();
    final Map<String, File> tableExistingXlsMap = StringKeyMap.createAsFlexible();
    final String dataDirPath = resolvePath(baseDir);
    final Map<String, String> tableNameMap = _tableNameProp.getTableNameMap(dataDirPath);
    for (File existingXls : existingXlsList) {
        final DfTableXlsReader reader = createTableXlsReader(baseDir, existingXls, tableNameMap);
        final DfDataSet dataSet = reader.read();
        final List<String> tableList = new ArrayList<String>();
        for (int i = 0; i < dataSet.getTableSize(); i++) {
            final DfDataTable dataTable = dataSet.getTable(i);
            final String tableDbName = dataTable.getTableDbName();
            tableList.add(tableDbName);
            if (tableExistingXlsMap.containsKey(tableDbName)) {
                throwLoadDataReverseDuplicateTableException(tableExistingXlsMap, tableDbName);
            }
            tableExistingXlsMap.put(tableDbName, existingXls);
        }
        existingXlsTableListMap.put(existingXls, tableList);
    }
    return new DfLReverseExistingXlsInfo(existingXlsTableListMap, tableExistingXlsMap);
}
Also used : ArrayList(java.util.ArrayList) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataSet(org.dbflute.helper.dataset.DfDataSet) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) DfTableXlsReader(org.dbflute.helper.io.xls.DfTableXlsReader)

Aggregations

DfDataSet (org.dbflute.helper.dataset.DfDataSet)14 File (java.io.File)11 DfDataTable (org.dbflute.helper.dataset.DfDataTable)7 DfTableXlsReader (org.dbflute.helper.io.xls.DfTableXlsReader)5 ArrayList (java.util.ArrayList)3 DfDataColumn (org.dbflute.helper.dataset.DfDataColumn)3 DfDataRow (org.dbflute.helper.dataset.DfDataRow)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Table (org.apache.torque.engine.database.model.Table)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1