use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.
the class TnBasicSelectHandler method doExecute.
// ===================================================================================
// Execute
// =======
@Override
protected Object doExecute(Connection conn, Object[] args, Class<?>[] argTypes) {
logSql(args, argTypes);
PreparedStatement ps = null;
try {
ps = prepareStatement(conn);
bindArgs(conn, ps, args, argTypes);
return queryResult(ps);
} catch (SQLException e) {
final SQLExceptionResource resource = createSQLExceptionResource();
resource.setNotice("Failed to execute the SQL for select.");
handleSQLException(e, resource);
// unreachable
return null;
} finally {
close(ps);
}
}
use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.
the class TnAbstractBasicSqlHandler method bindArgs.
// ===================================================================================
// Common Logic
// ============
// -----------------------------------------------------
// Arguments Handling
// ------------------
/**
* @param conn The connection for the database. (NotNull)
* @param ps The prepared statement for the SQL. (NotNull)
* @param args The arguments for binding. (NullAllowed)
* @param valueTypes The types of binding value. (NotNull)
*/
protected void bindArgs(Connection conn, PreparedStatement ps, Object[] args, ValueType[] valueTypes) {
if (args == null) {
return;
}
Object current = null;
try {
for (int i = 0; i < args.length; ++i) {
final ValueType valueType = valueTypes[i];
current = args[i];
valueType.bindValue(conn, ps, i + 1, current);
}
} catch (SQLException e) {
final SQLExceptionResource resource = createSQLExceptionResource();
resource.setNotice("Failed to bind the value.");
if (current != null) {
resource.addResource("Bound Value", current);
}
handleSQLException(e, resource);
}
}
use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.
the class TnAbstractBasicSqlHandler method bindArgs.
/**
* @param conn The connection for the database. (NotNull)
* @param ps The prepared statement for the SQL. (NotNull)
* @param args The arguments for binding. (NullAllowed)
* @param argTypes The types of arguments. (NullAllowed: if args is null, this is also null)
* @param beginIndex The index for beginning of binding.
*/
protected void bindArgs(Connection conn, PreparedStatement ps, Object[] args, Class<?>[] argTypes, int beginIndex) {
if (args == null) {
return;
}
Object current = null;
try {
for (int i = beginIndex; i < args.length; ++i) {
current = args[i];
final ValueType valueType = findValueType(argTypes[i], current);
valueType.bindValue(conn, ps, i + 1, current);
}
} catch (SQLException e) {
final SQLExceptionResource resource = createSQLExceptionResource();
resource.setNotice("Failed to bind the value.");
if (current != null) {
resource.addResource("Bound Value", current);
}
handleSQLException(e, resource);
}
}
use of org.dbflute.bhv.exception.SQLExceptionResource in project dbflute-core by dbflute.
the class TnAbstractBasicSqlHandler method executeUpdate.
protected int executeUpdate(PreparedStatement ps) {
// with SQLException handling
final boolean saveMillis = isSaveMillis();
if (saveMillis) {
saveBeforeSqlTimeMillis();
}
hookSqlFireBefore();
Integer updated = null;
SQLException nativeCause = null;
try {
updated = ps.executeUpdate();
if (saveMillis) {
saveAfterSqlTimeMillis();
}
return updated;
} catch (SQLException e) {
nativeCause = e;
final SQLExceptionResource resource = createSQLExceptionResource();
final String processTitle = getUpdateSQLFailureProcessTitle();
resource.setNotice("Failed to execute the SQL for " + processTitle + ".");
resource.enableUniqueConstraintHandling();
handleSQLException(e, resource);
// unreachable
return -1;
} finally {
hookSqlFireFinally(updated, nativeCause);
}
}
Aggregations