Search in sources :

Example 1 with SQLFailureException

use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.

the class DfAlterCheckProcess method reflectTakeFinallyResultToFinalInfo.

protected void reflectTakeFinallyResultToFinalInfo(DfAlterCheckFinalInfo finalInfo, DfTakeFinallyFinalInfo takeFinally) {
    final List<String> detailMessageList = takeFinally.getDetailMessageList();
    for (String detailMessage : detailMessageList) {
        finalInfo.addDetailMessage(detailMessage);
    }
    final SQLFailureException breakCause = takeFinally.getBreakCause();
    if (breakCause != null) {
        finalInfo.setBreakCause(breakCause);
    }
    final DfTakeFinallyAssertionFailureException assertionEx = takeFinally.getAssertionEx();
    if (assertionEx != null) {
        finalInfo.setTakeFinallyAssertionEx(assertionEx);
    }
    if (takeFinally.isFailure()) {
        finalInfo.setFailure(true);
    }
}
Also used : DfTakeFinallyAssertionFailureException(org.dbflute.exception.DfTakeFinallyAssertionFailureException) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 2 with SQLFailureException

use of org.dbflute.exception.SQLFailureException 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 3 with SQLFailureException

use of org.dbflute.exception.SQLFailureException 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)

Example 4 with SQLFailureException

use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.

the class DfSchemaInitializerJdbc method callbackDropForeignKeyByJdbc.

protected void callbackDropForeignKeyByJdbc(Connection conn, List<DfTableMeta> tableMetaList, DfDropForeignKeyByJdbcCallback callback) {
    Statement st = null;
    try {
        st = conn.createStatement();
        for (DfTableMeta tableMeta : tableMetaList) {
            if (isSkipDropForeignKey(tableMeta)) {
                continue;
            }
            final DfForeignKeyExtractor extractor = new DfForeignKeyExtractor();
            extractor.suppressExceptTarget();
            final DatabaseMetaData dbMetaData = conn.getMetaData();
            final Map<String, DfForeignKeyMeta> foreignKeyMetaInfoMap = extractor.getForeignKeyMap(conn, dbMetaData, tableMeta);
            final Set<String> keySet = foreignKeyMetaInfoMap.keySet();
            for (String foreignKeyName : keySet) {
                final DfForeignKeyMeta foreignKeyMetaInfo = foreignKeyMetaInfoMap.get(foreignKeyName);
                final String dropForeignKeySql = callback.buildDropForeignKeySql(foreignKeyMetaInfo);
                logReplaceSql(dropForeignKeySql);
                st.execute(dropForeignKeySql);
            }
        }
    } catch (SQLException e) {
        String msg = "Failed to drop foreign keys!";
        throw new SQLFailureException(msg, e);
    } finally {
        closeStatement(st);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) DfForeignKeyMeta(org.dbflute.logic.jdbc.metadata.info.DfForeignKeyMeta) DfTableMeta(org.dbflute.logic.jdbc.metadata.info.DfTableMeta) DatabaseMetaData(java.sql.DatabaseMetaData) DfForeignKeyExtractor(org.dbflute.logic.jdbc.metadata.basic.DfForeignKeyExtractor) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 5 with SQLFailureException

use of org.dbflute.exception.SQLFailureException in project dbflute-core by dbflute.

the class SQLExceptionHandler method throwSQLFailureException.

protected void throwSQLFailureException(SQLException e, SQLExceptionResource resource) {
    final ExceptionMessageBuilder br = createExceptionMessageBuilder();
    final List<String> noticeList = resource.getNoticeList();
    if (!noticeList.isEmpty()) {
        for (String notice : noticeList) {
            br.addNotice(notice);
        }
    } else {
        // as default
        br.addNotice("The SQL failed to execute.");
    }
    br.addItem("Advice");
    br.addElement("Read the SQLException message.");
    final String advice = askAdvice(e, ResourceContext.currentDBDef());
    if (advice != null && advice.trim().length() > 0) {
        br.addElement("*" + advice);
    }
    setupCommonElement(br, e, resource);
    final String msg = br.buildExceptionMessage();
    throw new SQLFailureException(msg, e);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) SQLFailureException(org.dbflute.exception.SQLFailureException)

Aggregations

SQLFailureException (org.dbflute.exception.SQLFailureException)31 SQLException (java.sql.SQLException)19 Statement (java.sql.Statement)9 ResultSet (java.sql.ResultSet)7 LinkedHashMap (java.util.LinkedHashMap)5 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)5 ArrayList (java.util.ArrayList)4 Connection (java.sql.Connection)3 DatabaseMetaData (java.sql.DatabaseMetaData)3 DfTakeFinallyAssertionFailureException (org.dbflute.exception.DfTakeFinallyAssertionFailureException)3 DfProcedureMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)3 DfTableMeta (org.dbflute.logic.jdbc.metadata.info.DfTableMeta)3 File (java.io.File)2 Map (java.util.Map)2 ErrorContinuedSql (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerResult.ErrorContinuedSql)2 DfProcedureExtractor (org.dbflute.logic.jdbc.metadata.basic.DfProcedureExtractor)2 DfTableExtractor (org.dbflute.logic.jdbc.metadata.basic.DfTableExtractor)2 DfTakeFinallyProcess (org.dbflute.logic.replaceschema.process.DfTakeFinallyProcess)2 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)2 DfClassificationJdbcCloser (org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser)2