use of org.dbflute.helper.dataset.DfDataTable 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);
}
use of org.dbflute.helper.dataset.DfDataTable in project dbflute-core by dbflute.
the class DfDtsCreatedState 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("insert into ");
sb.append(table.getTableSqlName());
sb.append(" (");
int writableColumnSize = 0;
for (int i = 0; i < table.getColumnSize(); ++i) {
final DfDataColumn column = table.getColumn(i);
if (column.isWritable()) {
++writableColumnSize;
sb.append(column.getColumnSqlName());
sb.append(", ");
argList.add(row.getValue(i));
argTypeList.add(column.getColumnType().getType());
}
}
sb.setLength(sb.length() - 2);
sb.append(") values (");
for (int i = 0; i < writableColumnSize; ++i) {
sb.append("?, ");
}
sb.setLength(sb.length() - 2);
sb.append(")");
return createDtsSqlContext(sb.toString(), argList, argTypeList);
}
use of org.dbflute.helper.dataset.DfDataTable in project dbflute-core by dbflute.
the class DfDtsRemovedState 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("delete from ");
sb.append(table.getTableSqlName());
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 DfLReverseExistingFileProvider method extractExistingXlsInfo.
// ===================================================================================
// Existing Xls
// ============
public DfLReverseExistingXlsInfo extractExistingXlsInfo(File baseDir) {
final List<File> existingXlsList = findExistingXlsList(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.findTableNameMap(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);
}
use of org.dbflute.helper.dataset.DfDataTable in project dbflute-core by dbflute.
the class DfTableXlsWriter method setupTableSheet.
// ===================================================================================
// Table Sheet
// ===========
protected void setupTableSheet(DfDataSet dataSet) {
for (int tableIndex = 0; tableIndex < dataSet.getTableSize(); ++tableIndex) {
final DfDataTable table = dataSet.getTable(tableIndex);
final Sheet sheet = _workbook.createSheet();
final String tableName = table.getTableDbName();
try {
_workbook.setSheetName(tableIndex, tableName);
} catch (RuntimeException e) {
String msg = "Failed to set the sheet name: " + tableName;
throw new IllegalStateException(msg, e);
}
final Row headerRow = sheet.createRow(0);
for (int columnIndex = 0; columnIndex < table.getColumnSize(); ++columnIndex) {
final Cell cell = headerRow.createCell(columnIndex);
cell.setCellValue(createRichTextString(_workbook, table.getColumnName(columnIndex)));
}
for (int rowIndex = 0; rowIndex < table.getRowSize(); ++rowIndex) {
final Row row = sheet.createRow(rowIndex + 1);
for (int columnIndex = 0; columnIndex < table.getColumnSize(); ++columnIndex) {
final DfDataRow dataRow = table.getRow(rowIndex);
final Object value = dataRow.getValue(columnIndex);
if (value != null) {
final Cell cell = row.createCell(columnIndex);
setupCellValueOfTableSheet(table, columnIndex, row, cell, value);
}
}
}
}
}
Aggregations