use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfTableOrderAnalyzer method groupingSize.
protected List<List<Table>> groupingSize(List<List<Table>> outputOrderedList) {
final int standardSize = STANDARD_SIZE;
final List<List<Table>> groupedList = new ArrayList<List<Table>>();
for (List<Table> tableList : outputOrderedList) {
final int tableSize = tableList.size();
if (!groupedList.isEmpty() && tableSize < standardSize) {
// handle only-one table
if (tableSize == 1) {
final Table onlyOneTable = tableList.get(0);
final List<ForeignKey> foreignKeyList = onlyOneTable.getForeignKeyList();
final Set<String> foreignTableSet = new HashSet<String>();
for (ForeignKey fk : foreignKeyList) {
if (!fk.hasFixedCondition()) {
// ignore fixed condition
foreignTableSet.add(fk.getForeignTablePureName());
}
}
List<Table> candidatePreviousList = null;
for (int i = groupedList.size() - 1; i >= 0; --i) {
// reverse loop
final List<Table> previousList = groupedList.get(i);
boolean existsFK = false;
for (Table previousTable : previousList) {
if (foreignTableSet.contains(previousTable.getName())) {
existsFK = true;
}
}
if (!isFirstLevelGroup(previousList) && previousList.size() < standardSize) {
// not group and small
candidatePreviousList = previousList;
}
if (existsFK) {
break;
}
}
if (candidatePreviousList != null) {
candidatePreviousList.add(onlyOneTable);
continue;
}
}
// join small sections
final List<Table> lastList = groupedList.get(groupedList.size() - 1);
if (isSecondLevelGroup(lastList) && isSecondLevelGroup(tableList)) {
}
if (isJoinSmallSection(lastList, tableList)) {
lastList.addAll(tableList);
continue;
}
}
// needs new list to manipulate
groupedList.add(new ArrayList<Table>(tableList));
}
assertAdjustmentBeforeAfter(outputOrderedList, groupedList);
return groupedList;
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfSPolicyWholeThemeChecker method determineSameWhatIfSameColumnName.
protected String determineSameWhatIfSameColumnName(Database database, Function<Column, Object> valueProvider, boolean ignoreEmpty) {
final List<Table> myTableList = toTableList(database);
for (Table myTable : myTableList) {
final List<Column> myColumnList = myTable.getColumnList();
for (Column myColumn : myColumnList) {
if (!isTargetColumn(myColumn)) {
continue;
}
for (Table yourTable : myTableList) {
if (myTable.equals(yourTable)) {
continue;
}
final String myColumnName = myColumn.getName();
final Column yourColumn = yourTable.getColumn(myColumnName);
if (yourColumn != null) {
if (!isTargetColumn(yourColumn)) {
continue;
}
final Object myValue = valueProvider.apply(myColumn);
final Object yourValue = valueProvider.apply(yourColumn);
if (ignoreEmpty && eitherEmpty(myValue, yourValue)) {
continue;
}
if (!isEqual(myValue, yourValue)) {
// different in spite of same column name
return toColumnExp(myColumn) + "=" + myValue + ", " + toColumnExp(yourColumn) + "=" + yourValue;
}
}
}
}
}
return null;
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfSPolicyWholeThemeChecker method determineUniqueTableWhat.
protected String determineUniqueTableWhat(Database database, Function<Table, Object> valueProvider) {
final List<Table> myTableList = toTableList(database);
for (Table myTable : myTableList) {
for (Table yourTable : myTableList) {
if (myTable.equals(yourTable)) {
continue;
}
final Object myValue = valueProvider.apply(myTable);
final Object yourValue = valueProvider.apply(yourTable);
if (eitherEmpty(myValue, yourValue)) {
// except non-defined value
continue;
}
if (isEqual(myValue, yourValue)) {
return toTableDisp(myTable) + "=" + myValue + ", " + toTableDisp(yourTable) + "=" + yourValue;
}
}
}
return null;
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfSPolicyWholeThemeChecker method determineSameWhatIfSameColumnAlias.
protected String determineSameWhatIfSameColumnAlias(Database database, Function<Column, Object> valueProvider, boolean ignoreEmpty) {
final List<Table> myTableList = toTableList(database);
for (Table myTable : myTableList) {
final List<Column> myColumnList = myTable.getColumnList();
for (Column myColumn : myColumnList) {
if (!isTargetColumn(myColumn)) {
continue;
}
if (!myColumn.hasAlias()) {
continue;
}
for (Table yourTable : myTableList) {
if (myTable.equals(yourTable)) {
continue;
}
final String myColumnAlias = myColumn.getAlias();
final List<Column> yourColumnList = yourTable.getColumnList();
for (Column yourColumn : yourColumnList) {
if (!isTargetColumn(yourColumn)) {
continue;
}
if (!yourColumn.hasAlias()) {
continue;
}
if (myColumnAlias.equals(yourColumn.getAlias())) {
// same column alias
final Object myValue = valueProvider.apply(myColumn);
final Object yourValue = valueProvider.apply(yourColumn);
if (ignoreEmpty && eitherEmpty(myValue, yourValue)) {
continue;
}
if (!isEqual(myValue, yourValue)) {
// different in spite of same column alias
return toColumnExp(myColumn) + "=" + myValue + ", " + toColumnExp(yourColumn) + "=" + yourValue;
}
}
}
}
}
}
return null;
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfTableNameProp method outputTableNameMap.
// ===================================================================================
// Output Map
// ==========
public void outputTableNameMap(String baseDir, Map<String, Table> tableNameMap) {
final Map<String, String> map = new LinkedHashMap<String, String>();
for (Entry<String, Table> entry : tableNameMap.entrySet()) {
final String sheetName = entry.getKey();
final Table table = entry.getValue();
map.put(sheetName, table.getTableSqlName());
}
final String mapString = new DfMapStyle().toMapString(map);
final File dataPropFile = new File(baseDir + "/tableNameMap.dataprop");
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dataPropFile), "UTF-8"));
bw.write(mapString);
bw.flush();
} catch (IOException e) {
String msg = "Failed to write tableNameMap.dataprop: " + dataPropFile;
throw new IllegalStateException(msg, e);
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException ignored) {
}
}
}
}
Aggregations