Search in sources :

Example 1 with SQLExceptionResource

use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.

the class TnIdentityAdjustmentSqlHandler method doExecute.

@Override
protected Object doExecute(Connection conn, Object[] args, Class<?>[] argTypes) {
    logSql(args, argTypes);
    Statement st = null;
    try {
        // PreparedStatement is not used here
        // because SQLServer do not work by PreparedStatement
        // but it do work well by Statement
        st = conn.createStatement();
        return st.executeUpdate(_sql);
    } catch (SQLException e) {
        final SQLExceptionResource resource = createSQLExceptionResource();
        resource.setNotice("Failed to execute the SQL to adjust identity.");
        handleSQLException(e, resource);
        // unreachable
        return 0;
    } finally {
        close(st);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) SQLExceptionResource(org.dbflute.bhv.exception.SQLExceptionResource)

Example 2 with SQLExceptionResource

use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.

the class TnAbstractBasicSqlHandler method executeBatch.

protected int[] executeBatch(PreparedStatement ps, List<?> list) {
    final boolean saveMillis = isSaveMillis();
    if (saveMillis) {
        saveBeforeSqlTimeMillis();
    }
    hookSqlFireBefore();
    int[] batchResult = null;
    SQLException nativeCause = null;
    try {
        batchResult = ps.executeBatch();
        if (saveMillis) {
            saveAfterSqlTimeMillis();
        }
        return batchResult;
    } catch (SQLException e) {
        nativeCause = e;
        final SQLExceptionResource resource = createSQLExceptionResource();
        final String processTitle = getBatchUpdateSQLFailureProcessTitle();
        resource.setNotice("Failed to execute the SQL for " + processTitle + ".");
        resource.enableUniqueConstraintHandling();
        resource.enableDisplaySqlPartHandling();
        handleSQLException(e, resource);
        // unreachable
        return null;
    } finally {
        hookSqlFireFinally(batchResult, nativeCause);
    }
}
Also used : SQLException(java.sql.SQLException) SQLExceptionResource(org.dbflute.bhv.exception.SQLExceptionResource)

Example 3 with SQLExceptionResource

use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.

the class TnAbstractBasicSqlHandler method getConnection.

// ===================================================================================
// JDBC Handling
// =============
// -----------------------------------------------------
// Connection
// ----------
/**
 * Get the database connection from data source. <br>
 * getting connection for SQL executions is only here. <br>
 * (for meta data is at TnBeanMetaDataFactoryImpl)
 * @return The new-created or inherited instance of connection. (NotNull)
 */
protected Connection getConnection() {
    try {
        final ManualThreadDataSourceHandler handler = getManualThreadDataSourceHandler();
        if (handler != null) {
            return handler.getConnection(_dataSource);
        }
        final Connection conn = _dataSource.getConnection();
        return conn;
    } catch (SQLException e) {
        final SQLExceptionResource resource = createSQLExceptionResource();
        resource.setNotice("Failed to get database connection.");
        handleSQLException(e, resource);
        // unreachable
        return null;
    }
}
Also used : SQLException(java.sql.SQLException) SQLExceptionResource(org.dbflute.bhv.exception.SQLExceptionResource) Connection(java.sql.Connection) ManualThreadDataSourceHandler(org.dbflute.jdbc.ManualThreadDataSourceHandler)

Example 4 with SQLExceptionResource

use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.

the class TnProcedureHandler method execute.

// ===================================================================================
// Execute
// =======
public Object execute(final Object[] args) {
    final Class<?>[] argTypes = getArgTypes(args);
    final Object pmb = getParameterBean(args);
    logSql(args, argTypes);
    Connection conn = null;
    CallableStatement cs = null;
    try {
        conn = getConnection();
        cs = prepareCall(conn);
        bindArgs(conn, cs, pmb);
        // Execute the procedure!
        // The return means whether the first result is a (not-parameter) result set.
        final boolean executed = executeProcedure(cs);
        // should be before out-parameter handling
        handleNotParamResult(conn, cs, pmb, executed);
        handleOutParameter(conn, cs, pmb, executed);
        return pmb;
    } catch (SQLException e) {
        final SQLExceptionResource resource = createSQLExceptionResource();
        resource.setNotice("Failed to execute the procedure.");
        resource.enableUniqueConstraintHandling();
        handleSQLException(e, resource);
        // unreachable
        return null;
    } finally {
        close(cs);
        close(conn);
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) SQLExceptionResource(org.dbflute.bhv.exception.SQLExceptionResource) Connection(java.sql.Connection)

Example 5 with SQLExceptionResource

use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.

the class BehaviorCommandInvoker method handleSQLException.

protected void handleSQLException(SQLException e) {
    final SQLExceptionResource resource = new SQLExceptionResource();
    ResourceContext.createSQLExceptionHandler().handleSQLException(e, resource);
}
Also used : SQLExceptionResource(org.dbflute.bhv.exception.SQLExceptionResource)

Aggregations

SQLExceptionResource (org.dbflute.bhv.exception.SQLExceptionResource)9 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)2 ValueType (org.dbflute.jdbc.ValueType)2 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 ManualThreadDataSourceHandler (org.dbflute.jdbc.ManualThreadDataSourceHandler)1