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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations