use of org.dbflute.helper.dataset.DfDataTable 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.DfDataTable 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.DfDataTable in project dbflute-core by dbflute.
the class DfTableXlsReader method prepareLargeDataTable.
// -----------------------------------------------------
// Large Data
// ----------
protected void prepareLargeDataTable() {
for (int i = 0; i < _workbook.getNumberOfSheets(); ++i) {
final String sheetName = _workbook.getSheetName(i);
if (!isLargeDataSheet(sheetName)) {
continue;
}
final Sheet sheet = _workbook.getSheetAt(i);
// unused
final String largeTableName = "LARGE_DATA";
final DfDataTable table = setupTable(sheet, largeTableName, new DfDataTable(largeTableName));
_largeDataMap = DfCollectionUtil.newLinkedHashMap();
final Map<Integer, String> indexColumnTitleMap = DfCollectionUtil.newLinkedHashMap();
for (int columnIndex = 0; columnIndex < table.getColumnSize(); columnIndex++) {
final DfDataColumn column = table.getColumn(columnIndex);
final String columnTitle = column.getColumnDbName();
if (!columnTitle.contains(".")) {
// should be e.g. MEMBER.MEMBER_NAME
throwLargeDataInvalidColumnTitleException(sheetName, columnTitle);
}
Map<String, String> dataMap = _largeDataMap.get(columnTitle);
if (dataMap == null) {
dataMap = DfCollectionUtil.newLinkedHashMap();
}
_largeDataMap.put(columnTitle, dataMap);
indexColumnTitleMap.put(columnIndex, columnTitle);
}
for (int rowIndex = 0; rowIndex < table.getRowSize(); rowIndex++) {
final DfDataRow row = table.getRow(rowIndex);
for (int columnIndex = 0; columnIndex < table.getColumnSize(); ++columnIndex) {
final Object obj = row.getValue(columnIndex);
if (obj == null) {
continue;
}
// basically String, but just in case
final String value = obj.toString();
final String columnTitle = indexColumnTitleMap.get(columnIndex);
final Map<String, String> dataMap = _largeDataMap.get(columnTitle);
if (!value.contains(LDATA_KEY_DELIMITER)) {
// should be e.g. key(df:delimiter){value}
throwLargeDataInvalidManagedDataException(sheetName, columnTitle, row, value);
}
final String dataKey = Srl.substringFirstFront(value, LDATA_KEY_DELIMITER);
final String largeValue = Srl.substringFirstRear(value, LDATA_KEY_DELIMITER);
final String unquotedValue = Srl.unquoteAnything(largeValue, LDATA_QUOTE_BEGIN, LDATA_QUOTE_END);
final String existingValue = dataMap.get(dataKey);
final String realValue = existingValue != null ? existingValue + unquotedValue : unquotedValue;
dataMap.put(dataKey, realValue);
}
}
// only one
break;
}
}
use of org.dbflute.helper.dataset.DfDataTable in project dbflute-core by dbflute.
the class DfDtsModifiedState method getSqlContext.
protected DfDtsSqlContext getSqlContext(DfDataRow row) {
final DfDataTable table = row.getTable();
final StringBuffer sb = new StringBuffer(100);
final List<Object> argList = new ArrayList<Object>();
final List<Class<?>> argTypeList = new ArrayList<Class<?>>();
sb.append("update ");
sb.append(table.getTableSqlName());
sb.append(" set ");
for (int i = 0; i < table.getColumnSize(); ++i) {
final DfDataColumn column = table.getColumn(i);
if (column.isWritable() && !column.isPrimaryKey()) {
sb.append(column.getColumnSqlName());
sb.append(" = ?, ");
argList.add(row.getValue(i));
argTypeList.add(column.getColumnType().getType());
}
}
sb.setLength(sb.length() - 2);
sb.append(" where ");
for (int i = 0; i < table.getColumnSize(); ++i) {
final DfDataColumn column = table.getColumn(i);
if (column.isPrimaryKey()) {
sb.append(column.getColumnSqlName());
sb.append(" = ? and ");
argList.add(row.getValue(i));
argTypeList.add(column.getColumnType().getType());
}
}
sb.setLength(sb.length() - 5);
return createDtsSqlContext(sb.toString(), argList, argTypeList);
}
use of org.dbflute.helper.dataset.DfDataTable in project dbflute-core by dbflute.
the class DfXlsDataHandlerImpl 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);
}
}
}
}
}
Aggregations