use of org.apache.torque.engine.database.model.ForeignKey in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method buildOrderByClause.
protected String buildOrderByClause(Table table) {
final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
final String orderBy;
if (selfReferenceFK != null && selfReferenceFK.isSimpleKeyFK()) {
final Column firstColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
final String firstName = firstColumn.getColumnSqlNameDirectUse();
orderBy = buildOrderByNullsFirst(firstName);
} else {
orderBy = "";
}
return orderBy;
}
use of org.apache.torque.engine.database.model.ForeignKey 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.ForeignKey in project dbflute-core by dbflute.
the class DfLReverseTableOrder 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.ForeignKey in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method buildSelfReferenceExtractingTrySqlList.
// ===================================================================================
// Extraction SQL
// ==============
// -----------------------------------------------------
// Self Reference
// --------------
protected OptionalThing<List<String>> buildSelfReferenceExtractingTrySqlList(Table table) {
final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
if (selfReferenceFK == null || !selfReferenceFK.isSimpleKeyFK()) {
return OptionalThing.empty();
}
final String tableSqlName = table.getTableSqlNameDirectUse();
final Column firstLocalColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
final String firstLocalName = firstLocalColumn.getColumnSqlNameDirectUse();
final Column firstForeignColumn = table.getColumn(selfReferenceFK.getFirstForeignColumnName());
final String firstForeignName = firstForeignColumn.getColumnSqlNameDirectUse();
final List<String> sqlList = DfCollectionUtil.newArrayList();
sqlList.add(doBuildSelfReferenceRecursiveSql(table, tableSqlName, firstLocalName, firstForeignName));
sqlList.add(doBuildSelfReferenceJoinJoinSql(table, tableSqlName, firstLocalName, firstForeignName));
return OptionalThing.of(sqlList);
}
use of org.apache.torque.engine.database.model.ForeignKey in project dbflute-core by dbflute.
the class DfLReverseDataExtractor method buildOrderByClause.
protected String buildOrderByClause(Table table) {
final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
final String orderBy;
if (selfReferenceFK != null && selfReferenceFK.isSimpleKeyFK()) {
final Column firstColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
final String firstName = firstColumn.getColumnSqlNameDirectUse();
orderBy = buildOrderByNullsFirst(firstName);
} else {
orderBy = "";
}
return orderBy;
}
Aggregations