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));
}
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);
}
}
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));
}
}
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());
}
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);
}
Aggregations