Search in sources :

Example 1 with UserTabComments

use of org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserTabComments in project dbflute-core by dbflute.

the class DfSynonymExtractorOracle method setupTableColumnComment.

/**
 * Set up table and column comment. <br>
 * This does not support DB link synonym.
 * @param synonymMap The map of synonym. (NotNull)
 */
protected void setupTableColumnComment(Map<String, DfSynonymMeta> synonymMap) {
    final Map<UnifiedSchema, Set<String>> ownerTabSetMap = createOwnerTableSetMap(synonymMap);
    final Map<UnifiedSchema, Map<String, UserTabComments>> ownerTabCommentMap = newLinkedHashMap();
    final Map<UnifiedSchema, Map<String, Map<String, UserColComments>>> ownerTabColCommentMap = newLinkedHashMap();
    for (UnifiedSchema owner : ownerTabSetMap.keySet()) {
        final Set<String> tableSet = ownerTabSetMap.get(owner);
        final DfDbCommentExtractorOracle extractor = createDbCommentExtractor(owner);
        final Map<String, UserTabComments> tabCommentMap = extractor.extractTableComment(tableSet);
        final Map<String, Map<String, UserColComments>> tabColCommentMap = extractor.extractColumnComment(tableSet);
        ownerTabCommentMap.put(owner, tabCommentMap);
        ownerTabColCommentMap.put(owner, tabColCommentMap);
    }
    for (DfSynonymMeta synonym : synonymMap.values()) {
        final UnifiedSchema owner = synonym.getTableOwner();
        final String tableName = synonym.getTableName();
        final Map<String, UserTabComments> tableCommentMap = ownerTabCommentMap.get(owner);
        if (tableCommentMap != null) {
            final UserTabComments userTabComments = tableCommentMap.get(tableName);
            if (userTabComments != null && userTabComments.hasComments()) {
                synonym.setTableComment(userTabComments.getComments());
            }
        }
        final Map<String, Map<String, UserColComments>> tabColCommentMap = ownerTabColCommentMap.get(owner);
        if (tabColCommentMap != null) {
            final Map<String, UserColComments> colCommentMap = tabColCommentMap.get(tableName);
            if (colCommentMap != null && !colCommentMap.isEmpty()) {
                synonym.setColumnCommentMap(colCommentMap);
            }
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) UserColComments(org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserColComments) UserTabComments(org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserTabComments) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema) DfDbCommentExtractorOracle(org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractorOracle) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 2 with UserTabComments

use of org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserTabComments in project dbflute-core by dbflute.

the class DfSchemaXmlSerializer method doHelpTableComment.

protected void doHelpTableComment(List<DfTableMeta> tableList, UnifiedSchema unifiedSchema) {
    final DfDbCommentExtractor dbCommentExtractor = createDbCommentExtractor(unifiedSchema);
    if (dbCommentExtractor != null) {
        final Set<String> tableSet = new HashSet<String>();
        for (DfTableMeta table : tableList) {
            tableSet.add(table.getTableName());
        }
        try {
            final Map<String, UserTabComments> tableCommentMap = dbCommentExtractor.extractTableComment(tableSet);
            for (DfTableMeta table : tableList) {
                table.acceptTableComment(tableCommentMap);
            // *Synonym Processing is after loading synonyms.
            }
        } catch (RuntimeException ignored) {
            _log.info("Failed to extract table comments: extractor=" + dbCommentExtractor, ignored);
        }
        try {
            if (_columnCommentAllMap == null) {
                _columnCommentAllMap = new LinkedHashMap<UnifiedSchema, Map<String, Map<String, UserColComments>>>();
            }
            final Map<String, Map<String, UserColComments>> columnCommentMap = _columnCommentAllMap.get(unifiedSchema);
            final Map<String, Map<String, UserColComments>> extractedMap = dbCommentExtractor.extractColumnComment(tableSet);
            if (columnCommentMap == null) {
                _columnCommentAllMap.put(unifiedSchema, extractedMap);
            } else {
                // basically no way, schema is unique but just in case
                // merge
                columnCommentMap.putAll(extractedMap);
            }
        } catch (RuntimeException continued) {
            _log.info("Failed to extract column comments: extractor=" + dbCommentExtractor, continued);
        }
    }
}
Also used : UserColComments(org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserColComments) UserTabComments(org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserTabComments) DfDbCommentExtractor(org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor) UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema) DfTableMeta(org.dbflute.logic.jdbc.metadata.info.DfTableMeta) Map(java.util.Map) TypeMap(org.apache.torque.engine.database.model.TypeMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) StringKeyMap(org.dbflute.helper.StringKeyMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 UnifiedSchema (org.apache.torque.engine.database.model.UnifiedSchema)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 UserColComments (org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserColComments)2 UserTabComments (org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor.UserTabComments)2 ResultSet (java.sql.ResultSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 TypeMap (org.apache.torque.engine.database.model.TypeMap)1 DfDbCommentExtractor (org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractor)1 DfDbCommentExtractorOracle (org.dbflute.logic.jdbc.metadata.comment.DfDbCommentExtractorOracle)1 DfSynonymMeta (org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta)1 DfTableMeta (org.dbflute.logic.jdbc.metadata.info.DfTableMeta)1