use of org.dbflute.helper.dataset.DfDataTable in project dbflute-core by dbflute.
the class DfTableXlsReader method prepareTable.
// -----------------------------------------------------
// Data Table
// ----------
protected DfDataTable prepareTable(String sheetName, Sheet sheet) {
String tableName = sheetName;
if (_tableNameMap != null && !_tableNameMap.isEmpty() && sheetName.startsWith("$")) {
String realTableName = _tableNameMap.get(sheetName);
if (realTableName == null) {
realTableName = _tableNameMap.get(sheetName.substring("$".length()));
if (realTableName == null) {
throwXlsReaderMappingTableNotFoundException(sheetName);
}
}
tableName = realTableName;
}
final DfDataTable table = _dataSet.addTable(tableName);
return setupTable(sheet, tableName, table);
}
use of org.dbflute.helper.dataset.DfDataTable 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");
}
use of org.dbflute.helper.dataset.DfDataTable in project dbflute-core by dbflute.
the class DfXlsDataHandlingWriter method setupDefaultValue.
protected void setupDefaultValue(String dataDirectory, final DfDataSet dataSet) {
final Map<String, String> defaultValueMap = getDefaultValueMap(dataDirectory);
for (int i = 0; i < dataSet.getTableSize(); i++) {
final DfDataTable table = dataSet.getTable(i);
final Set<String> defaultValueMapKeySet = defaultValueMap.keySet();
final String tableName = table.getTableDbName();
final Map<String, DfColumnMeta> metaMetaMap = getColumnMetaMap(tableName);
for (String defaultTargetColumnName : defaultValueMapKeySet) {
final String defaultValue = defaultValueMap.get(defaultTargetColumnName);
if (metaMetaMap.containsKey(defaultTargetColumnName) && !table.hasColumn(defaultTargetColumnName)) {
// values are resolved later so resolve type only here
final DfDtsColumnType columnType;
if (defaultValue.equalsIgnoreCase("sysdate")) {
columnType = DfDtsColumnTypes.TIMESTAMP;
} else {
columnType = DfDtsColumnTypes.STRING;
}
table.addColumn(defaultTargetColumnName, columnType);
for (int j = 0; j < table.getRowSize(); j++) {
final DfDataRow row = table.getRow(j);
// value is set later
row.addValue(defaultTargetColumnName, null);
}
}
}
}
}
use of org.dbflute.helper.dataset.DfDataTable 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);
}
Aggregations