Search in sources :

Example 26 with SQLFailureException

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

the class DfSchemaInitializerJdbc method callbackDropTableByJdbc.

protected void callbackDropTableByJdbc(Connection conn, List<DfTableMeta> tableMetaList, DfDropTableByJdbcCallback callback) {
    String currentSql = null;
    Statement st = null;
    try {
        st = conn.createStatement();
        for (DfTableMeta tableMeta : tableMetaList) {
            final String dropTableSql = callback.buildDropTableSql(tableMeta);
            currentSql = dropTableSql;
            logReplaceSql(dropTableSql);
            try {
                st.execute(dropTableSql);
            } catch (SQLException e) {
                handleDroppingRetry(callback, st, tableMeta, e);
            }
        }
    } catch (SQLException e) {
        String msg = "Failed to drop the table: " + currentSql;
        throw new SQLFailureException(msg, e);
    } finally {
        closeStatement(st);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) DfTableMeta(org.dbflute.logic.jdbc.metadata.info.DfTableMeta) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 27 with SQLFailureException

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

the class DfSchemaInitializerJdbc method initializeSchema.

// ===================================================================================
// Initialize Schema
// =================
public void initializeSchema() {
    Connection conn = null;
    try {
        try {
            conn = _dataSource.getConnection();
        } catch (SQLException e) {
            if (_suppressConnectionFailure) {
                handleSuppressedConnectionFailure(e);
                return;
            } else {
                throw e;
            }
        }
        final List<DfTableMeta> tableMetaList;
        try {
            final DatabaseMetaData metaData = conn.getMetaData();
            final DfTableExtractor tableExtractor = createDropTableExtractor();
            tableMetaList = tableExtractor.getTableList(metaData, _unifiedSchema);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        executeObject(conn, tableMetaList);
    } catch (SQLException e) {
        String msg = "Failed to the initialize schema: " + _unifiedSchema;
        throw new SQLFailureException(msg, e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ignored) {
                _log.info("connection.close() threw the exception!", ignored);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) DfTableExtractor(org.dbflute.logic.jdbc.metadata.basic.DfTableExtractor) Connection(java.sql.Connection) DfTableMeta(org.dbflute.logic.jdbc.metadata.info.DfTableMeta) DatabaseMetaData(java.sql.DatabaseMetaData) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 28 with SQLFailureException

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

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

the class DfSchemaInitializerOracle method dropDicObject.

// ===================================================================================
// Assist Helper
// =============
protected boolean dropDicObject(Connection conn, String titleName, String sqlName, String tableName, String ownerColumnName, String targetColumnName, String orderBy, boolean schemaPrefix, boolean errorContinue, ObjectExceptCallback callback) {
    if (!_unifiedSchema.hasSchema()) {
        return true;
    }
    final String schema = _unifiedSchema.getPureSchema();
    final List<String> objectNameList = new ArrayList<String>();
    final StringBuilder sb = new StringBuilder();
    sb.append("select * from ").append(tableName);
    sb.append(" where ").append(ownerColumnName).append(" = '").append(schema).append("'");
    if (Srl.is_NotNull_and_NotTrimmedEmpty(orderBy)) {
        sb.append(" order by ").append(orderBy);
    }
    final String metaSql = sb.toString();
    Statement st = null;
    ResultSet rs = null;
    try {
        st = conn.createStatement();
        _log.info("...Executing helper SQL:" + ln() + metaSql);
        rs = st.executeQuery(metaSql);
        while (rs.next()) {
            final String objectName = rs.getString(targetColumnName);
            objectNameList.add(objectName);
        }
    } catch (SQLException continued) {
        // if the data dictionary table is not found,
        // it continues because it might be a version difference
        String msg = "*Failed to the SQL:" + ln();
        msg = msg + (continued.getMessage() != null ? continued.getMessage() : null) + ln();
        msg = msg + metaSql;
        _log.info(metaSql);
        return true;
    } finally {
        closeResource(rs, st);
    }
    try {
        boolean complete = true;
        st = conn.createStatement();
        for (String objectName : objectNameList) {
            if (callback != null && callback.isExcept(objectName)) {
                continue;
            }
            final String prefix = schemaPrefix ? schema + "." : "";
            final String dropSql = "drop " + sqlName + " " + prefix + objectName;
            logReplaceSql(dropSql);
            try {
                st.execute(dropSql);
            } catch (SQLException e) {
                if (errorContinue) {
                    complete = false;
                    continue;
                }
                throw e;
            }
        }
        return complete;
    } catch (SQLException e) {
        String msg = "Failed to drop " + titleName + ": " + objectNameList;
        throw new SQLFailureException(msg, e);
    } finally {
        closeStatement(st);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) SQLFailureException(org.dbflute.exception.SQLFailureException)

Example 30 with SQLFailureException

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

the class DfReplaceSchemaTask method takeFinally.

// -----------------------------------------------------
// Take Finally
// ------------
protected void takeFinally(String sqlRootDir, boolean previous) {
    final DfTakeFinallyProcess process = createTakeFinallyProcess(sqlRootDir, previous);
    _takeFinallyFinalInfo = process.execute();
    final SQLFailureException breakCause = _takeFinallyFinalInfo.getBreakCause();
    if (breakCause != null) {
        // high priority exception
        throw breakCause;
    }
    final DfTakeFinallyAssertionFailureException assertionEx = _takeFinallyFinalInfo.getAssertionEx();
    if (assertionEx != null) {
        // high priority exception
        throw assertionEx;
    }
}
Also used : DfTakeFinallyAssertionFailureException(org.dbflute.exception.DfTakeFinallyAssertionFailureException) DfTakeFinallyProcess(org.dbflute.logic.replaceschema.process.DfTakeFinallyProcess) 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