Search in sources :

Example 11 with DfDataTable

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);
}
Also used : ArrayList(java.util.ArrayList) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataSet(org.dbflute.helper.dataset.DfDataSet) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) DfTableXlsReader(org.dbflute.helper.io.xls.DfTableXlsReader)

Example 12 with DfDataTable

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);
}
Also used : DfDataColumn(org.dbflute.helper.dataset.DfDataColumn) ArrayList(java.util.ArrayList) DfDataTable(org.dbflute.helper.dataset.DfDataTable)

Example 13 with DfDataTable

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);
}
Also used : DfDataColumn(org.dbflute.helper.dataset.DfDataColumn) ArrayList(java.util.ArrayList) DfDataTable(org.dbflute.helper.dataset.DfDataTable)

Example 14 with DfDataTable

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);
}
Also used : ArrayList(java.util.ArrayList) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataSet(org.dbflute.helper.dataset.DfDataSet) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) DfTableXlsReader(org.dbflute.helper.io.xls.DfTableXlsReader)

Example 15 with DfDataTable

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);
                }
            }
        }
    }
}
Also used : DfDataTable(org.dbflute.helper.dataset.DfDataTable) RichTextString(org.apache.poi.ss.usermodel.RichTextString) Row(org.apache.poi.ss.usermodel.Row) DfDataRow(org.dbflute.helper.dataset.DfDataRow) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Aggregations

DfDataTable (org.dbflute.helper.dataset.DfDataTable)19 DfDataColumn (org.dbflute.helper.dataset.DfDataColumn)9 DfDataRow (org.dbflute.helper.dataset.DfDataRow)9 File (java.io.File)5 ArrayList (java.util.ArrayList)5 DfDataSet (org.dbflute.helper.dataset.DfDataSet)5 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)4 RichTextString (org.apache.poi.ss.usermodel.RichTextString)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 Column (org.apache.torque.engine.database.model.Column)2 DfDtsColumnType (org.dbflute.helper.dataset.types.DfDtsColumnType)2 DfTableXlsReader (org.dbflute.helper.io.xls.DfTableXlsReader)2 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1