Search in sources :

Example 1 with DfProcedureMeta

use of org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta 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 DfProcedureMeta

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

the class DfProcedureSynonymExtractorOracle method findProcedureMeta.

protected DfProcedureMeta findProcedureMeta(UnifiedSchema tableOwner, String tableName, Map<String, DfProcedureMeta> procedureMap) {
    final String procedureKey = tableOwner.buildSchemaQualifiedName(tableName);
    DfProcedureMeta procedureMeta = procedureMap.get(procedureKey);
    if (procedureMeta == null) {
        // (Synonym meta data does not have its schema info)
        for (UnifiedSchema schema : _targetSchemaList) {
            procedureMeta = procedureMap.get(schema.getPureSchema() + "." + procedureKey);
            if (procedureMeta != null) {
                // comes first
                break;
            }
        }
    // but Oracle cannot execute Synonym for Package Procedure *fundamental problem
    }
    return procedureMeta;
}
Also used : UnifiedSchema(org.apache.torque.engine.database.model.UnifiedSchema) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)

Example 3 with DfProcedureMeta

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

the class DfProcedurePmbSetupper method getAvailableProcedureList.

// ===================================================================================
// Procedure List
// ==============
protected List<DfProcedureMeta> getAvailableProcedureList() throws SQLException {
    _procedureExtractor.includeProcedureSynonym(_dataSource);
    _procedureExtractor.includeProcedureToDBLink(_dataSource);
    final List<DfProcedureMeta> procedureList = _procedureExtractor.getAvailableProcedureList(_dataSource);
    if (getOutsideSqlProperties().isGenerateProcedureCustomizeEntity()) {
        final DfProcedureExecutionMetaExtractor executionMetaHandler = new DfProcedureExecutionMetaExtractor();
        executionMetaHandler.extractExecutionMetaData(_dataSource, procedureList);
        _continuedFailureMessageMap.putAll(executionMetaHandler.getContinuedFailureMessageMap());
    }
    return procedureList;
}
Also used : DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta) DfProcedureExecutionMetaExtractor(org.dbflute.logic.sql2entity.cmentity.DfProcedureExecutionMetaExtractor)

Example 4 with DfProcedureMeta

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

the class DfProcedureExecutionMetaExtractor method extractExecutionMetaData.

// ===================================================================================
// Process
// =======
public void extractExecutionMetaData(DataSource dataSource, List<DfProcedureMeta> procedureList) throws SQLException {
    final DfOutsideSqlProperties prop = getProperties().getOutsideSqlProperties();
    for (DfProcedureMeta procedure : procedureList) {
        final String procedureFullQualifiedName = procedure.getProcedureFullQualifiedName();
        final String procedureSchemaQualifiedName = procedure.getProcedureSchemaQualifiedName();
        final String procedureName = procedure.getProcedureName();
        if (prop.isExecutionMetaProcedureName(procedureFullQualifiedName) || prop.isExecutionMetaProcedureName(procedureSchemaQualifiedName) || prop.isExecutionMetaProcedureName(procedureName)) {
            doExtractExecutionMetaData(dataSource, procedure);
        }
    }
}
Also used : DfOutsideSqlProperties(org.dbflute.properties.DfOutsideSqlProperties) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)

Example 5 with DfProcedureMeta

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

the class DfSchemaInitializerJdbc method callbackDropProcedureByJdbc.

protected void callbackDropProcedureByJdbc(Connection conn, List<DfProcedureMeta> procedureMetaList, DfDropProcedureByJdbcCallback callback) {
    String currentSql = null;
    Statement st = null;
    try {
        st = conn.createStatement();
        for (DfProcedureMeta procedureMeta : procedureMetaList) {
            if (isProcedureExcept(procedureMeta.getProcedureName())) {
                continue;
            }
            if (procedureMeta.isPackageProcdure()) {
                currentSql = callback.buildDropPackageSql(procedureMeta);
                handlePackageProcedure(procedureMeta, st, currentSql);
                continue;
            }
            final String dropFirstSql = buildDropProcedureFirstSql(callback, procedureMeta);
            currentSql = dropFirstSql;
            logReplaceSql(dropFirstSql);
            try {
                st.execute(dropFirstSql);
            } catch (SQLException e) {
                final String dropSecondSql = buildDropProcedureSecondSql(callback, procedureMeta);
                try {
                    st.execute(dropSecondSql);
                    logReplaceSql("  (o) retry: " + dropSecondSql);
                } catch (SQLException ignored) {
                    logReplaceSql("  (x) retry: " + dropSecondSql);
                    throw e;
                }
            }
        }
    } catch (SQLException e) {
        String msg = "Failed to drop the procedure: " + currentSql;
        throw new SQLFailureException(msg, e);
    } finally {
        closeStatement(st);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta) SQLFailureException(org.dbflute.exception.SQLFailureException)

Aggregations

DfProcedureMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)24 UnifiedSchema (org.apache.torque.engine.database.model.UnifiedSchema)8 SQLException (java.sql.SQLException)5 DfProcedureColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureColumnMeta)5 ArrayList (java.util.ArrayList)4 DfOutsideSqlProperties (org.dbflute.properties.DfOutsideSqlProperties)4 SQLFailureException (org.dbflute.exception.SQLFailureException)3 DfProcedureExtractor (org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 List (java.util.List)2 DfProcedureSynonymMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureSynonymMeta)2 DfProcedureNativeTranslatorOracle (org.dbflute.logic.jdbc.metadata.procedure.DfProcedureNativeTranslatorOracle)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Entry (java.util.Map.Entry)1 DfProcedureArgumentInfo (org.dbflute.logic.jdbc.metadata.info.DfProcedureArgumentInfo)1 DfProcedureColumnType (org.dbflute.logic.jdbc.metadata.info.DfProcedureColumnMeta.DfProcedureColumnType)1