Search in sources :

Example 51 with Table

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

the class DfLReverseDataExtractor method extractData.

// ===================================================================================
// Extract Data
// ============
/**
 * Extract load-data.
 * @param tableMap The map of table. (NotNull)
 */
public Map<String, DfLReverseDataResult> extractData(Map<String, Table> tableMap) {
    final Map<String, DfLReverseDataResult> loadDataMap = new LinkedHashMap<String, DfLReverseDataResult>();
    for (Entry<String, Table> entry : tableMap.entrySet()) {
        final String tableDbName = entry.getKey();
        final Table table = entry.getValue();
        final DfLReverseDataResult result = selectData(table);
        loadDataMap.put(tableDbName, result);
    }
    return loadDataMap;
}
Also used : Table(org.apache.torque.engine.database.model.Table) LinkedHashMap(java.util.LinkedHashMap)

Example 52 with Table

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

the class DfLReverseTableData method reverseTableData.

// ===================================================================================
// Reverse Table
// =============
public void reverseTableData(Map<File, DfLReverseOutputResource> orderedMap, File baseDir, List<String> sectionInfoList) {
    deletePreviousDataFile(baseDir);
    final Integer limit = getRecordLimit();
    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 : DfLReverseOutputResource(org.dbflute.logic.doc.lreverse.DfLReverseOutputResource) Table(org.apache.torque.engine.database.model.Table) File(java.io.File)

Example 53 with Table

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

the class DfLReverseSchemaTableFilter method filterTableList.

// ===================================================================================
// Filter Table
// ============
public List<Table> filterTableList(Database database) {
    final List<Table> tableList = database.getTableList();
    final Set<String> commonExistingTableSet = getCommonExistingTableSet();
    final List<Table> filteredList = DfCollectionUtil.newArrayListSized(tableList.size());
    _skippedTableList.clear();
    final List<Table> commonSkippedList = DfCollectionUtil.newArrayList();
    final List<Table> exceptSkippedList = DfCollectionUtil.newArrayList();
    _log.info("...Filtering reversed table: " + tableList.size());
    for (Table table : tableList) {
        if (table.isTypeView() || table.isAdditionalSchema()) {
            // additional schema - tables on main schema only are target
            continue;
        }
        if (commonExistingTableSet.contains(table.getTableDbName())) {
            commonSkippedList.add(table);
            continue;
        }
        if (!isTargetTable(table)) {
            exceptSkippedList.add(table);
            continue;
        }
        filteredList.add(table);
    }
    if (!commonSkippedList.isEmpty()) {
        _log.info("[Common Table] *skipped");
        for (Table table : commonSkippedList) {
            _log.info("  " + table.getTableDbName());
            _skippedTableList.add(table);
        }
    }
    if (!exceptSkippedList.isEmpty()) {
        _log.info("[Except Table] *skipped");
        for (Table table : exceptSkippedList) {
            _log.info("  " + table.getTableDbName());
            _skippedTableList.add(table);
        }
    }
    return filteredList;
}
Also used : Table(org.apache.torque.engine.database.model.Table)

Example 54 with Table

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

the class DfSchemaDiff method processChangedTable.

// -----------------------------------------------------
// Changed
// -------
protected void processChangedTable() {
    final List<Table> tableList = _nextDb.getTableList();
    for (Table next : tableList) {
        final Table previous = findPreviousTable(next);
        if (previous == null || !isSameTableName(next, previous)) {
            continue;
        }
        // found
        final DfTableDiff tableDiff = DfTableDiff.createChanged(next.getTableDbName());
        // direct attributes
        processUnifiedSchema(next, previous, tableDiff);
        processObjectType(next, previous, tableDiff);
        processColumnDefOrder(next, previous, tableDiff);
        processTableComment(next, previous, tableDiff);
        // nested attributes
        processColumn(tableDiff, next, previous);
        processPrimaryKey(tableDiff, next, previous);
        processForeignKey(tableDiff, next, previous);
        processUniqueKey(tableDiff, next, previous);
        processIndex(tableDiff, next, previous);
        if (tableDiff.hasDiff()) {
            // changed
            addTableDiff(tableDiff);
        }
    }
}
Also used : Table(org.apache.torque.engine.database.model.Table)

Example 55 with Table

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

the class DfSql2EntityTask method setupSql2EntityRelatedTable.

protected Table setupSql2EntityRelatedTable(String entityName, DfCustomizeEntityInfo entityInfo, Map<String, DfColumnMeta> metaMap, String columnName, Column column, String pkRelatedTableName) {
    final DfColumnMeta columnMeta = metaMap.get(columnName);
    final String sql2EntityRelatedTableName = columnMeta.getSql2EntityRelatedTableName();
    // first attack
    Table relatedTable = getRelatedTable(sql2EntityRelatedTableName);
    if (relatedTable == null) {
        if (pkRelatedTableName != null) {
            // second attack using PK-related
            relatedTable = getRelatedTable(pkRelatedTableName);
            if (relatedTable == null) {
                throwTableRelatedPrimaryKeyNotFoundException(entityName, entityInfo, pkRelatedTableName, columnName);
            }
        } else {
            return null;
        }
    } else {
        if (pkRelatedTableName != null) {
            if (!Srl.equalsFlexible(sql2EntityRelatedTableName, pkRelatedTableName)) {
                throwTableRelatedPrimaryKeyDifferentException(entityName, entityInfo, sql2EntityRelatedTableName, pkRelatedTableName, columnName);
            }
        }
    }
    column.setSql2EntityRelatedTable(relatedTable);
    return relatedTable;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) Table(org.apache.torque.engine.database.model.Table)

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