Search in sources :

Example 11 with Table

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;
}
Also used : Table(org.apache.torque.engine.database.model.Table) ArrayList(java.util.ArrayList) ForeignKey(org.apache.torque.engine.database.model.ForeignKey) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 12 with Table

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;
}
Also used : Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column)

Example 13 with Table

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;
}
Also used : Table(org.apache.torque.engine.database.model.Table)

Example 14 with Table

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;
}
Also used : Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column)

Example 15 with Table

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) {
            }
        }
    }
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfMapStyle(org.dbflute.helper.dfmap.DfMapStyle) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) BufferedWriter(java.io.BufferedWriter)

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