Search in sources :

Example 6 with Table

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

the class DfLReverseProcess method reverseTableData.

// ===================================================================================
// Reverse Table
// =============
protected void reverseTableData(Map<File, DfLReverseOutputResource> orderedMap, File baseDir, List<String> sectionInfoList) {
    deletePreviousDataFile(baseDir);
    final Integer limit = getLoadDataReverseRecordLimit();
    for (Entry<File, DfLReverseOutputResource> entry : orderedMap.entrySet()) {
        final File xlsFile = entry.getKey();
        final DfLReverseOutputResource resource = entry.getValue();
        final List<Table> tableList = resource.getTableList();
        final Map<String, Table> tableInfoMap = DfCollectionUtil.newLinkedHashMap();
        for (Table table : tableList) {
            tableInfoMap.put(table.getTableDbName(), table);
        }
        final String sectionTitle = "[" + xlsFile.getName() + "]: tables=" + tableList.size();
        _log.info("");
        _log.info(sectionTitle);
        sectionInfoList.add("");
        sectionInfoList.add(sectionTitle);
        _outputHandler.outputData(tableInfoMap, limit, xlsFile, resource, sectionInfoList);
    }
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfDataTable(org.dbflute.helper.dataset.DfDataTable) File(java.io.File)

Example 7 with Table

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

the class DfTableOrderAnalyzer method isSecondLevelGroup.

protected boolean isSecondLevelGroup(List<Table> tableList) {
    if (tableList.size() == 1) {
        return false;
    }
    final Set<String> prefixSet = new HashSet<String>();
    for (Table table : tableList) {
        final String prefix = extractSecondLevelPrefix(table.getName());
        if (prefix == null) {
            return false;
        }
        prefixSet.add(prefix);
    }
    return prefixSet.size() == 1;
}
Also used : Table(org.apache.torque.engine.database.model.Table) HashSet(java.util.HashSet)

Example 8 with Table

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

the class DfTableOrderAnalyzer method isFirstLevelGroup.

protected boolean isFirstLevelGroup(List<Table> tableList) {
    if (tableList.size() == 1) {
        return false;
    }
    final Set<String> prefixSet = new HashSet<String>();
    for (Table table : tableList) {
        final String prefix = extractFirstLevelPrefix(table.getName());
        prefixSet.add(prefix);
    }
    return prefixSet.size() == 1;
}
Also used : Table(org.apache.torque.engine.database.model.Table) HashSet(java.util.HashSet)

Example 9 with Table

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

the class DfTableOrderAnalyzer method deriveMostName.

protected String deriveMostName(List<Table> tableList, boolean secondLevel) {
    final String plusSuffix = "-plus";
    final Map<String, Integer> prefixMap = new HashMap<String, Integer>();
    for (Table table : tableList) {
        final String tableName = table.getName();
        final String prefix;
        if (secondLevel) {
            final String secondLevelPrefix = extractSecondLevelPrefix(tableName);
            if (secondLevelPrefix != null) {
                prefix = secondLevelPrefix;
            } else {
                prefix = extractFirstLevelPrefix(tableName);
            }
        } else {
            prefix = extractFirstLevelPrefix(tableName);
        }
        final Integer size = prefixMap.get(prefix);
        if (size != null) {
            prefixMap.put(prefix, size + 1);
        } else {
            prefixMap.put(prefix, 1);
        }
    }
    if (prefixMap.size() == 1) {
        // no way because of process before
        return prefixMap.keySet().iterator().next().toUpperCase() + plusSuffix;
    } else if (prefixMap.size() >= 2) {
        String mostPrefix = null;
        Integer mostSize = 0;
        for (Entry<String, Integer> entry : prefixMap.entrySet()) {
            final Integer count = entry.getValue();
            if (mostSize < count) {
                mostPrefix = entry.getKey();
                mostSize = count;
            }
        }
        if (secondLevel && mostPrefix.contains("_")) {
            final String firstLevelPrefix = extractFirstLevelPrefix(mostPrefix);
            final Integer firstLevelSize = prefixMap.get(firstLevelPrefix);
            if (firstLevelSize != null && firstLevelSize > 0) {
                return firstLevelPrefix.toUpperCase() + (isFirstLevelGroup(tableList) ? "" : plusSuffix);
            }
        }
        if (mostSize > 1 && mostSize > (tableList.size() / 2)) {
            return mostPrefix.toUpperCase() + plusSuffix;
        }
    }
    return null;
}
Also used : Entry(java.util.Map.Entry) Table(org.apache.torque.engine.database.model.Table) HashMap(java.util.HashMap)

Example 10 with Table

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

the class DfTableOrderAnalyzer method doGroupingCategory.

protected List<List<Table>> doGroupingCategory(List<List<Table>> outputOrderedList, boolean secondLevel) {
    final int standardSize = STANDARD_SIZE;
    final List<List<Table>> groupedList = new ArrayList<List<Table>>();
    for (List<Table> tableList : outputOrderedList) {
        if (secondLevel && (!isFirstLevelGroup(tableList) || tableList.size() <= standardSize)) {
            groupedList.add(new ArrayList<Table>(tableList));
            continue;
        }
        // as initial instance
        List<Table> workTableList = new ArrayList<Table>();
        String currentPrefix = null;
        boolean inGroup = false;
        for (Table table : tableList) {
            final String tableName = table.getName();
            if (currentPrefix != null) {
                if (tableName.startsWith(currentPrefix)) {
                    // grouped
                    inGroup = true;
                    final int workSize = workTableList.size();
                    if (workSize >= 2) {
                        final Table requiredSizeBefore = workTableList.get(workSize - 2);
                        if (!requiredSizeBefore.getName().startsWith(currentPrefix)) {
                            // the work list has non-group elements at the front so split them
                            final Table groupBase = workTableList.remove(workSize - 1);
                            groupedList.add(workTableList);
                            workTableList = new ArrayList<Table>();
                            workTableList.add(groupBase);
                        }
                    }
                    workTableList.add(table);
                } else {
                    if (inGroup) {
                        // switched
                        groupedList.add(workTableList);
                        workTableList = new ArrayList<Table>();
                        inGroup = false;
                    }
                    currentPrefix = null;
                }
            }
            if (currentPrefix == null) {
                if (secondLevel) {
                    currentPrefix = extractSecondLevelPrefix(tableName);
                } else {
                    currentPrefix = extractFirstLevelPrefix(tableName);
                }
                workTableList.add(table);
            }
        }
        if (!workTableList.isEmpty()) {
            groupedList.add(workTableList);
        }
    }
    assertAdjustmentBeforeAfter(outputOrderedList, groupedList);
    return groupedList;
}
Also used : Table(org.apache.torque.engine.database.model.Table) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

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