Search in sources :

Example 6 with DfSynonymMeta

use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.

the class DfSchemaXmlSerializer method isAutoIncrementColumn.

// -----------------------------------------------------
// Auto Increment
// --------------
/**
 * Get auto-increment column name.
 * @param tableMeta The meta information of table from which to retrieve PK information.
 * @param primaryKeyColumnInfo The meta information of primary-key column.
 * @param conn Connection.
 * @return Auto-increment column name. (NullAllowed)
 * @throws SQLException When it fails to handle the SQL.
 */
protected boolean isAutoIncrementColumn(Connection conn, DfTableMeta tableMeta, DfColumnMeta primaryKeyColumnInfo) throws SQLException {
    if (_autoIncrementExtractor.isAutoIncrementColumn(conn, tableMeta, primaryKeyColumnInfo)) {
        return true;
    }
    if (canHandleSynonym(tableMeta)) {
        final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
        if (synonym != null && synonym.isAutoIncrement()) {
            return true;
        }
    }
    if (_identityMap == null) {
        return false;
    }
    final String primaryKeyColumnName = primaryKeyColumnInfo.getColumnName();
    final String columnName = _identityMap.get(tableMeta.getTableName());
    return primaryKeyColumnName.equals(columnName);
}
Also used : DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta)

Example 7 with DfSynonymMeta

use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.

the class DfSchemaXmlSerializer method loadSupplementarySynonymInfoIfNeeds.

// -----------------------------------------------------
// Synonym
// -------
protected void loadSupplementarySynonymInfoIfNeeds() {
    // is only for main schema
    final DfSynonymExtractor extractor = createSynonymExtractor();
    if (extractor == null) {
        return;
    }
    try {
        _log.info("...Loading supplementary synonym informations");
        _supplementarySynonymInfoMap = extractor.extractSynonymMap();
        final StringBuilder sb = new StringBuilder();
        sb.append("Finished loading synonyms:").append(ln()).append("[Supplementary Synonyms]");
        final Set<Entry<String, DfSynonymMeta>> entrySet = _supplementarySynonymInfoMap.entrySet();
        for (Entry<String, DfSynonymMeta> entry : entrySet) {
            sb.append(ln()).append(" ").append(entry.getValue().toString());
        }
        _log.info(sb.toString());
    } catch (RuntimeException ignored) {
        _log.info("DfSynonymExtractor.extractSynonymMap() threw the exception!", ignored);
    }
}
Also used : Entry(java.util.Map.Entry) DfSynonymExtractor(org.dbflute.logic.jdbc.metadata.synonym.DfSynonymExtractor) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta)

Example 8 with DfSynonymMeta

use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.

the class DfProcedureExtractor method isSynonymAllowedSchema.

protected boolean isSynonymAllowedSchema(DfProcedureSynonymMeta procedureSynonymMetaInfo) {
    final DfSynonymMeta synonymMetaInfo = procedureSynonymMetaInfo.getSynonymMetaInfo();
    final UnifiedSchema synonymOwner = synonymMetaInfo.getSynonymOwner();
    final DfDatabaseProperties databaseProperties = getProperties().getDatabaseProperties();
    final DfAdditionalSchemaInfo additionalSchemaInfo = databaseProperties.getAdditionalSchemaInfo(synonymOwner);
    if (additionalSchemaInfo != null) {
        return additionalSchemaInfo.hasObjectTypeSynonym();
    } else {
        // as main schema
        return databaseProperties.hasObjectTypeSynonym();
    }
}
Also used : DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) DfAdditionalSchemaInfo(org.dbflute.properties.assistant.database.DfAdditionalSchemaInfo) UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema) DfDatabaseProperties(org.dbflute.properties.DfDatabaseProperties)

Example 9 with DfSynonymMeta

use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.

the class DfSynonymExtractorOracle method extractSynonymMap.

// ===================================================================================
// Extract
// =======
public Map<String, DfSynonymMeta> extractSynonymMap() {
    final Map<String, DfSynonymMeta> synonymMap = StringKeyMap.createAsFlexibleOrdered();
    Map<String, Map<String, SynonymNativeInfo>> dbLinkSynonymNativeMap = null;
    final String sql = buildSynonymSelect();
    Connection conn = null;
    Statement statement = null;
    ResultSet rs = null;
    try {
        conn = _dataSource.getConnection();
        statement = conn.createStatement();
        _log.info(sql);
        rs = statement.executeQuery(sql);
        while (rs.next()) {
            final UnifiedSchema synonymOwner = createAsDynamicSchema(null, rs.getString("OWNER"));
            final String synonymName = rs.getString("SYNONYM_NAME");
            final UnifiedSchema tableOwner = createAsDynamicSchema(null, rs.getString("TABLE_OWNER"));
            final String tableName = rs.getString("TABLE_NAME");
            final String dbLinkName = rs.getString("DB_LINK");
            if (_tableExtractor.isTableExcept(synonymOwner, synonymName)) {
                // because it is not necessary to handle excepted tables
                continue;
            }
            final DfSynonymMeta info = new DfSynonymMeta();
            // Basic
            info.setSynonymOwner(synonymOwner);
            info.setSynonymName(synonymName);
            info.setTableOwner(tableOwner);
            info.setTableName(tableName);
            info.setDBLinkName(dbLinkName);
            // Select-able?
            judgeSynonymSelectable(info);
            if (info.isSelectable()) {
                // e.g. procedure synonym
                // set up column definition for supplement info
                final List<DfColumnMeta> columnMetaInfoList = getSynonymColumns(conn, synonymOwner, synonymName);
                info.setColumnMetaInfoList(columnMetaInfoList);
            }
            if (dbLinkName != null && dbLinkName.trim().length() > 0) {
                if (dbLinkSynonymNativeMap == null) {
                    // lazy load
                    dbLinkSynonymNativeMap = extractDBLinkSynonymNativeMap();
                }
                // = = = = = = = = = = = =
                try {
                    final String synonymKey = buildSynonymMapKey(synonymOwner, synonymName);
                    synonymMap.put(synonymKey, setupDBLinkSynonym(conn, info, dbLinkSynonymNativeMap));
                } catch (Exception continued) {
                    _log.info("Failed to get meta data of " + synonymName + ": " + continued.getMessage());
                }
                continue;
            }
            if (!tableOwner.hasSchema()) {
                // basically no way because it may be for DB Link Synonym
                continue;
            }
            // PK, ID, UQ, FK, Index
            try {
                setupBasicConstraintInfo(info, tableOwner, tableName, conn);
            } catch (Exception continued) {
                _log.info("Failed to get meta data of " + synonymName + ": " + continued.getMessage());
                continue;
            }
            final String synonymKey = buildSynonymMapKey(synonymOwner, synonymName);
            synonymMap.put(synonymKey, info);
        }
    } catch (SQLException e) {
        throw new IllegalStateException(e);
    } finally {
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException ignored) {
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException ignored) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ignored) {
            }
        }
    }
    // It translates foreign key meta informations.
    translateFKTable(synonymMap);
    setupTableColumnComment(synonymMap);
    return synonymMap;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLException(java.sql.SQLException) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema) ResultSet(java.sql.ResultSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 10 with DfSynonymMeta

use of org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta in project dbflute-core by dbflute.

the class DfSynonymExtractorOracle method createOwnerTableSetMap.

protected Map<UnifiedSchema, Set<String>> createOwnerTableSetMap(Map<String, DfSynonymMeta> synonymMap) {
    final Map<UnifiedSchema, Set<String>> ownerTabSetMap = newLinkedHashMap();
    for (DfSynonymMeta synonym : synonymMap.values()) {
        final UnifiedSchema owner = synonym.getTableOwner();
        if (synonym.isDBLink()) {
            // Synonym of DB Link is out of target!
            continue;
        }
        Set<String> tableSet = ownerTabSetMap.get(owner);
        if (tableSet == null) {
            tableSet = new LinkedHashSet<String>();
            ownerTabSetMap.put(owner, tableSet);
        }
        tableSet.add(synonym.getTableName());
    }
    return ownerTabSetMap;
}
Also used : ResultSet(java.sql.ResultSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema)

Aggregations

DfSynonymMeta (org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta)14 UnifiedSchema (org.apache.torque.engine.database.model.UnifiedSchema)6 LinkedHashMap (java.util.LinkedHashMap)5 ResultSet (java.sql.ResultSet)4 Map (java.util.Map)4 StringKeyMap (org.dbflute.helper.StringKeyMap)4 ArrayList (java.util.ArrayList)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 TypeMap (org.apache.torque.engine.database.model.TypeMap)2 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)2 DfForeignKeyMeta (org.dbflute.logic.jdbc.metadata.info.DfForeignKeyMeta)2 Entry (java.util.Map.Entry)1 SQLFailureException (org.dbflute.exception.SQLFailureException)1 StringSet (org.dbflute.helper.StringSet)1