Search in sources :

Example 1 with Table

use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.

the class DfLReverseDataExtractor method extractData.

// ===================================================================================
// Extract Data
// ============
/**
 * Extract load-data.
 * @param tableMap The map of table. (NotNull)
 */
public Map<String, DfLReverseDataResult> extractData(Map<String, Table> tableMap) {
    final Map<String, DfLReverseDataResult> loadDataMap = new LinkedHashMap<String, DfLReverseDataResult>();
    for (Entry<String, Table> entry : tableMap.entrySet()) {
        final String tableDbName = entry.getKey();
        final Table table = entry.getValue();
        final DfLReverseDataResult result = selectData(table);
        loadDataMap.put(tableDbName, result);
    }
    return loadDataMap;
}
Also used : Table(org.apache.torque.engine.database.model.Table) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Table

use of org.apache.torque.engine.database.model.Table 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);
    }
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataSet(org.dbflute.helper.dataset.DfDataSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with Table

use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.

the class DfLReverseProcess method toReplaceReverseOrderedMap.

// -----------------------------------------------------
// Replace Reverse
// ---------------
protected Map<File, DfLReverseOutputResource> toReplaceReverseOrderedMap(List<List<Table>> orderedList) {
    final Map<File, DfLReverseOutputResource> orderedMap = DfCollectionUtil.newLinkedHashMap();
    int sectionNo = 1;
    for (List<Table> nestedList : orderedList) {
        final String number = (sectionNo < 10 ? "0" + sectionNo : String.valueOf(sectionNo));
        final String mainName = extractMainName(nestedList);
        final File xlsFile = new File(buildXlsFilePath(number, mainName));
        orderedMap.put(xlsFile, createOutputResource(xlsFile, nestedList, sectionNo, mainName));
        ++sectionNo;
    }
    return orderedMap;
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfDataTable(org.dbflute.helper.dataset.DfDataTable) File(java.io.File)

Example 4 with Table

use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.

the class DfLReverseProcess method toOverrideReverseOrderedMap.

// ===================================================================================
// Ordered Map
// ===========
// -----------------------------------------------------
// Override Reverse
// ----------------
protected Map<File, DfLReverseOutputResource> toOverrideReverseOrderedMap(List<List<Table>> orderedList, File baseDir) {
    final DfLReverseExistingXlsInfo existingXlsInfo = extractExistingXlsInfo(baseDir);
    final Map<File, DfLReverseOutputResource> orderedMap = createOrderedMap();
    final String dataDirPath = resolvePath(baseDir);
    final Map<String, String> tableNameMap = _tableNameProp.getTableNameMap(dataDirPath);
    final Map<String, File> translatedXlsMap = prepareTranslatedXlsMap(existingXlsInfo, tableNameMap);
    final List<Table> addedTableList = DfCollectionUtil.newArrayList();
    int sectionNo = 1;
    for (List<Table> nestedList : orderedList) {
        for (Table table : nestedList) {
            final File existingXls = translatedXlsMap.get(table.getTableDbName());
            if (existingXls == null) {
                addedTableList.add(table);
                continue;
            }
            DfLReverseOutputResource resource = orderedMap.get(existingXls);
            if (resource == null) {
                final String mainName = extractMainName(nestedList);
                final List<Table> initialList = new ArrayList<Table>();
                resource = createOutputResource(existingXls, initialList, sectionNo, mainName);
                orderedMap.put(existingXls, resource);
                ++sectionNo;
            }
            resource.addTable(table);
        }
    }
    registerAddedTableIfExists(orderedMap, addedTableList, sectionNo);
    orderTableByExistingOrder(orderedMap, existingXlsInfo);
    return orderedMap;
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfDataTable(org.dbflute.helper.dataset.DfDataTable) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with Table

use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.

the class DfLReverseProcess method filterTableList.

// ===================================================================================
// Table List
// ==========
protected List<Table> filterTableList(Database database) {
    final List<Table> tableList = database.getTableList();
    final Set<String> commonExistingTableSet = getCommonExistingTableSet();
    final List<Table> filteredList = DfCollectionUtil.newArrayListSized(tableList.size());
    _skippedTableList.clear();
    final List<Table> commonSkippedList = DfCollectionUtil.newArrayList();
    final List<Table> exceptSkippedList = DfCollectionUtil.newArrayList();
    _log.info("...Filtering reversed table: " + tableList.size());
    for (Table table : tableList) {
        if (table.isTypeView() || table.isAdditionalSchema()) {
            // additional schema - tables on main schema only are target
            continue;
        }
        if (commonExistingTableSet.contains(table.getTableDbName())) {
            commonSkippedList.add(table);
            continue;
        }
        if (!isTargetTable(table)) {
            exceptSkippedList.add(table);
            continue;
        }
        filteredList.add(table);
    }
    if (!commonSkippedList.isEmpty()) {
        _log.info("[Common Table] *skipped");
        for (Table table : commonSkippedList) {
            _log.info("  " + table.getTableDbName());
            _skippedTableList.add(table);
        }
    }
    if (!exceptSkippedList.isEmpty()) {
        _log.info("[Except Table] *skipped");
        for (Table table : exceptSkippedList) {
            _log.info("  " + table.getTableDbName());
            _skippedTableList.add(table);
        }
    }
    return filteredList;
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfDataTable(org.dbflute.helper.dataset.DfDataTable)

Aggregations

Table (org.apache.torque.engine.database.model.Table)58 Column (org.apache.torque.engine.database.model.Column)16 ArrayList (java.util.ArrayList)15 List (java.util.List)14 File (java.io.File)11 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)10 ForeignKey (org.apache.torque.engine.database.model.ForeignKey)9 HashSet (java.util.HashSet)8 DfDataTable (org.dbflute.helper.dataset.DfDataTable)8 Database (org.apache.torque.engine.database.model.Database)6 IOException (java.io.IOException)4 Entry (java.util.Map.Entry)4 DfBuildProperties (org.dbflute.DfBuildProperties)4 DfDataSet (org.dbflute.helper.dataset.DfDataSet)4 HashMap (java.util.HashMap)3 Function (java.util.function.Function)3 DfLReverseOutputResource (org.dbflute.logic.doc.lreverse.DfLReverseOutputResource)3 BufferedWriter (java.io.BufferedWriter)2 FileOutputStream (java.io.FileOutputStream)2