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 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 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");
}
use of org.dbflute.helper.dataset.DfDataSet 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));
}
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));
}
Aggregations