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);
}
}
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);
}
}
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;
}
}
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);
}
}
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);
}
Aggregations