Search in sources :

Example 11 with DfSynonymMeta

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

the class DfSchemaXmlSerializer method getPrimaryColumnMetaInfo.

// -----------------------------------------------------
// Primary Key
// -----------
/**
 * Get the meta information of primary key.
 * @param metaData The meta data of a database. (NotNull)
 * @param tableMeta The meta information of table. (NotNull)
 * @return The meta information of primary key. (NotNull)
 * @throws SQLException When it fails to handle the SQL.
 */
protected DfPrimaryKeyMeta getPrimaryColumnMetaInfo(DatabaseMetaData metaData, DfTableMeta tableMeta) throws SQLException {
    final DfPrimaryKeyMeta pkInfo = _uniqueKeyExtractor.getPrimaryKey(metaData, tableMeta);
    final List<String> pkList = pkInfo.getPrimaryKeyList();
    if (!canHandleSynonym(tableMeta) || !pkList.isEmpty()) {
        return pkInfo;
    }
    final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
    if (synonym != null) {
        return synonym.getPrimaryKey();
    } else {
        return pkInfo;
    }
}
Also used : DfPrimaryKeyMeta(org.dbflute.logic.jdbc.metadata.info.DfPrimaryKeyMeta) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta)

Example 12 with DfSynonymMeta

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

the class DfSchemaXmlSerializer method getForeignKeys.

// -----------------------------------------------------
// Foreign Key
// -----------
/**
 * Retrieves a list of foreign key columns for a given table.
 * @param conn The connection for the foreign keys, basically for info cannot be provided from meta data, e.g. to-UQ FK. (NotNull)
 * @param metaData The meta data of a database. (NotNull)
 * @param tableMeta The meta information of table. (NotNull)
 * @return A list of foreign keys in <code>tableName</code>.
 * @throws SQLException When it fails to handle the SQL.
 */
protected Map<String, DfForeignKeyMeta> getForeignKeys(Connection conn, DatabaseMetaData metaData, DfTableMeta tableMeta) throws SQLException {
    final Map<String, DfForeignKeyMeta> foreignKeyMap = _foreignKeyExtractor.getForeignKeyMap(conn, metaData, tableMeta);
    if (!canHandleSynonym(tableMeta) || !foreignKeyMap.isEmpty()) {
        return foreignKeyMap;
    }
    final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
    return synonym != null ? synonym.getForeignKeyMap() : foreignKeyMap;
}
Also used : DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) DfForeignKeyMeta(org.dbflute.logic.jdbc.metadata.info.DfForeignKeyMeta)

Example 13 with DfSynonymMeta

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

the class DfSchemaXmlSerializer method getIndexMap.

// -----------------------------------------------------
// Index
// -----
/**
 * Get index column name list.
 * @param metaData The meta data of a database. (NotNull)
 * @param tableMeta The meta information of table. (NotNull)
 * @param uniqueKeyMap The map of unique key. (NotNull)
 * @return The list of index columns. (NotNull)
 * @throws SQLException When it fails to handle the SQL.
 */
protected Map<String, Map<Integer, String>> getIndexMap(DatabaseMetaData metaData, DfTableMeta tableMeta, Map<String, Map<Integer, String>> uniqueKeyMap) throws SQLException {
    final Map<String, Map<Integer, String>> indexMap = _indexExtractor.getIndexMap(metaData, tableMeta, uniqueKeyMap);
    if (!canHandleSynonym(tableMeta) || !indexMap.isEmpty()) {
        return indexMap;
    }
    final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
    return synonym != null ? synonym.getIndexMap() : indexMap;
}
Also used : DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) 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)

Example 14 with DfSynonymMeta

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

the class DfSchemaXmlSerializer method helpColumnAdjustment.

protected List<DfColumnMeta> helpColumnAdjustment(DatabaseMetaData dbMeta, DfTableMeta tableMeta, List<DfColumnMeta> columnList) {
    if (!canHandleSynonym(tableMeta)) {
        return columnList;
    }
    final DfSynonymMeta synonym = getSynonymMetaInfo(tableMeta);
    if (synonym == null) {
        // means not synonym or no supplementary info
        return columnList;
    }
    final List<DfColumnMeta> metaInfoList = synonym.getColumnMetaInfoList();
    if (metaInfoList.isEmpty()) {
        return metaInfoList;
    }
    if (synonym.isDBLink() && columnList.isEmpty()) {
        columnList = metaInfoList;
    } else if (metaInfoList.size() != columnList.size()) {
        // for Oracle's bug(?), which is following:
        // /- - - - - - - - - - - - - - - - - - - - - - - - - - -
        // For example, Schema A, B are like this:
        // A: FOO table
        // B: FOO table, BAR synonym to A's FOO table
        // BAR synonym's columns are from both A and B's FOO table.
        // (means that BAR synonym has other table's columns)
        // Why? my friend, the Oracle JDBC Driver!
        // - - - - - - - - - -/
        final StringSet columnSet = StringSet.createAsCaseInsensitive();
        for (DfColumnMeta columnMeta : metaInfoList) {
            columnSet.add(columnMeta.getColumnName());
        }
        final List<DfColumnMeta> filteredList = new ArrayList<DfColumnMeta>();
        for (DfColumnMeta columnMeta : columnList) {
            if (columnSet.contains(columnMeta.getColumnName())) {
                filteredList.add(columnMeta);
            }
        }
        columnList = filteredList;
    }
    return columnList;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) StringSet(org.dbflute.helper.StringSet) List(java.util.List) ArrayList(java.util.ArrayList)

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