Search in sources :

Example 1 with DfProcedureExtractor

use of org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor in project dbflute-core by dbflute.

the class DfProcedureSynonymExtractorOracle method extractProcedureSynonymMap.

// ===================================================================================
// Extract
// =======
public Map<String, DfProcedureSynonymMeta> extractProcedureSynonymMap() {
    _log.info("...Extracting procedure synonym");
    final Map<String, DfProcedureSynonymMeta> procedureSynonymMap = StringKeyMap.createAsFlexibleOrdered();
    final String sql = buildSynonymSelect();
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    try {
        conn = _dataSource.getConnection();
        final Map<String, DfProcedureMeta> procedureMap = new LinkedHashMap<String, DfProcedureMeta>();
        final List<DfProcedureMeta> procedureList = new ArrayList<DfProcedureMeta>();
        final DfProcedureExtractor extractor = new DfProcedureExtractor();
        extractor.suppressLogging();
        for (UnifiedSchema unifiedSchema : _targetSchemaList) {
            // get new procedure list because different instances is needed at this process
            procedureList.addAll(extractor.getPlainProcedureList(_dataSource, unifiedSchema));
        }
        for (DfProcedureMeta metaInfo : procedureList) {
            final String procedureKeyName = metaInfo.getProcedureFullQualifiedName();
            procedureMap.put(procedureKeyName, metaInfo);
        }
        DfProcedureNativeTranslatorOracle translator = null;
        st = conn.createStatement();
        _log.info(sql);
        rs = st.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");
            final DfSynonymMeta synonymMetaInfo = new DfSynonymMeta();
            // Basic
            synonymMetaInfo.setSynonymOwner(synonymOwner);
            synonymMetaInfo.setSynonymName(synonymName);
            synonymMetaInfo.setTableOwner(tableOwner);
            synonymMetaInfo.setTableName(tableName);
            synonymMetaInfo.setDBLinkName(dbLinkName);
            // Select-able?
            judgeSynonymSelectable(synonymMetaInfo);
            if (synonymMetaInfo.isSelectable()) {
                // select-able synonyms are out of target
                continue;
            }
            DfProcedureMeta procedureMeta = null;
            if (dbLinkName != null && dbLinkName.trim().length() > 0) {
                // synonym for DB link
                if (translator == null) {
                    translator = new DfProcedureNativeTranslatorOracle(_dataSource);
                }
                procedureMeta = prepareProcedureToDBLink(tableOwner, tableName, dbLinkName, extractor, translator);
            } else {
                procedureMeta = findProcedureMeta(tableOwner, tableName, procedureMap);
            }
            if (procedureMeta == null) {
                // may be package procedure or other schema's one
                continue;
            }
            procedureMeta.setProcedureSynonym(true);
            final DfProcedureSynonymMeta procedureSynonymMetaInfo = new DfProcedureSynonymMeta();
            procedureSynonymMetaInfo.setProcedureMetaInfo(procedureMeta);
            procedureSynonymMetaInfo.setSynonymMetaInfo(synonymMetaInfo);
            final String synonymKey = buildSynonymMapKey(synonymOwner, synonymName);
            procedureSynonymMap.put(synonymKey, procedureSynonymMetaInfo);
        }
    } catch (SQLException e) {
        String msg = "Failed to get procedure synonyms: sql=" + sql;
        throw new SQLFailureException(msg, e);
    } finally {
        if (st != null) {
            try {
                st.close();
            } catch (SQLException ignored) {
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException ignored) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ignored) {
            }
        }
    }
    return procedureSynonymMap;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SQLFailureException(org.dbflute.exception.SQLFailureException) DfProcedureSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureSynonymMeta) DfProcedureExtractor(org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor) DfSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta) UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema) ResultSet(java.sql.ResultSet) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta) DfProcedureNativeTranslatorOracle(org.dbflute.logic.jdbc.metadata.procedure.DfProcedureNativeTranslatorOracle)

Example 2 with DfProcedureExtractor

use of org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor in project dbflute-core by dbflute.

the class DfSchemaInitializerJdbc method dropProcedure.

// ===================================================================================
// Drop Procedure
// ==============
protected void dropProcedure(Connection conn, List<DfTableMeta> tableMetaList) {
    final DfProcedureExtractor handler = new DfProcedureExtractor();
    handler.suppressAdditionalSchema();
    handler.suppressLogging();
    final List<DfProcedureMeta> procedureList;
    try {
        procedureList = handler.getPlainProcedureList(_dataSource, _unifiedSchema);
    } catch (SQLException e) {
        String msg = "Failed to get procedure meta data: " + _unifiedSchema;
        throw new SQLFailureException(msg, e);
    }
    callbackDropProcedureByJdbc(conn, procedureList, createDropProcedureByJdbcCallback());
}
Also used : SQLException(java.sql.SQLException) DfProcedureExtractor(org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 3 with DfProcedureExtractor

use of org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor in project dbflute-core by dbflute.

the class DfSchemaXmlSerializer method extractProcedureMap.

protected Map<String, DfProcedureMeta> extractProcedureMap() {
    final DfProcedureExtractor procedureExtractor = createProcedureExtractor();
    Map<String, DfProcedureMeta> procedureMap = null;
    try {
        procedureMap = procedureExtractor.getAvailableProcedureMap(_dataSource);
    } catch (SQLException continued) {
        // because of supplement
        _log.info("*Failed to get procedure map: " + continued.getMessage());
    } catch (RuntimeException continued) {
        // because of supplement
        _log.info("*Failed to get procedure map: " + continued.getMessage());
    }
    return procedureMap;
}
Also used : SQLException(java.sql.SQLException) DfProcedureExtractor(org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)

Example 4 with DfProcedureExtractor

use of org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor in project dbflute-core by dbflute.

the class DfSchemaXmlSerializer method createProcedureExtractor.

protected DfProcedureExtractor createProcedureExtractor() {
    final DfProcedureExtractor extractor = new DfProcedureExtractor();
    if (_suppressExceptTarget) {
        extractor.suppressFilterByProperty();
    }
    if (_suppressAdditionalSchema) {
        extractor.suppressAdditionalSchema();
    }
    extractor.suppressGenerationRestriction();
    return extractor;
}
Also used : DfProcedureExtractor(org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor)

Example 5 with DfProcedureExtractor

use of org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor in project dbflute-core by dbflute.

the class DfSchemaHtmlProcedure method getAvailableProcedureList.

// ===================================================================================
// Available Procedure
// ===================
public List<DfProcedureMeta> getAvailableProcedureList(Supplier<DfSchemaSource> dataSourceProvider) throws SQLException {
    if (_procedureMetaInfoList != null) {
        return _procedureMetaInfoList;
    }
    _log.info(" ");
    _log.info("...Setting up procedures for documents");
    final DfProcedureExtractor handler = new DfProcedureExtractor();
    final DfSchemaSource dataSource = dataSourceProvider.get();
    handler.includeProcedureSynonym(dataSource);
    handler.includeProcedureToDBLink(dataSource);
    if (getDocumentProperties().isShowSchemaHtmlProcedureRegardlessOfGeneration()) {
        handler.suppressGenerationRestriction();
    }
    // ordered by schema
    _procedureMetaInfoList = handler.getAvailableProcedureList(dataSource);
    return _procedureMetaInfoList;
}
Also used : DfSchemaSource(org.dbflute.helper.jdbc.context.DfSchemaSource) DfProcedureExtractor(org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor)

Aggregations

DfProcedureExtractor (org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor)5 SQLException (java.sql.SQLException)3 DfProcedureMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)3 SQLFailureException (org.dbflute.exception.SQLFailureException)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 UnifiedSchema (org.apache.torque.engine.database.model.UnifiedSchema)1 DfSchemaSource (org.dbflute.helper.jdbc.context.DfSchemaSource)1 DfProcedureSynonymMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureSynonymMeta)1 DfSynonymMeta (org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta)1 DfProcedureNativeTranslatorOracle (org.dbflute.logic.jdbc.metadata.procedure.DfProcedureNativeTranslatorOracle)1