use of org.dbflute.s2dao.jdbc.TnResultSetHandler in project dbflute-core by dbflute.
the class OutsideSqlSelectCursorCommand method createOutsideSqlSelectResultSetHandler.
// ===================================================================================
// SqlExecution Handling
// =====================
@Override
protected TnResultSetHandler createOutsideSqlSelectResultSetHandler() {
return new TnResultSetHandler() {
public Object handle(ResultSet rs) throws SQLException {
if (!OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
String msg = "The context of outside SQL should be required here!";
throw new IllegalStateException(msg);
}
OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
CursorHandler cursorHandler = context.getCursorHandler();
return cursorHandler.handle(rs);
}
};
}
use of org.dbflute.s2dao.jdbc.TnResultSetHandler in project dbflute-core by dbflute.
the class AbstractOutsideSqlSelectCommand method createOutsideSqlSelectExecution.
protected SqlExecution createOutsideSqlSelectExecution(OutsideSqlContext outsideSqlContext) {
// - - - - - - - - - - - - - - - - - - - - - - -
// The attribute of Specified-OutsideSqlContext.
// - - - - - - - - - - - - - - - - - - - - - - -
final Object pmb = outsideSqlContext.getParameterBean();
final String suffix = buildDbmsSuffix();
final String sql = outsideSqlContext.readFilteredOutsideSql(_sqlFileEncoding, suffix);
// - - - - - - - - - - - - -
// Create ResultSetHandler.
// - - - - - - - - - - - - -
final TnResultSetHandler handler = createOutsideSqlSelectResultSetHandler();
// - - - - - - - - - - -
// Create SqlExecution.
// - - - - - - - - - - -
final OutsideSqlSelectExecution execution = createOutsideSqlSelectExecution(pmb, sql, handler);
execution.setRemoveBlockComment(isRemoveBlockComment(outsideSqlContext));
execution.setRemoveLineComment(isRemoveLineComment(outsideSqlContext));
execution.setFormatSql(outsideSqlContext.isFormatSql());
execution.setOutsideSqlFilter(_outsideSqlFilter);
return execution;
}
use of org.dbflute.s2dao.jdbc.TnResultSetHandler in project dbflute-core by dbflute.
the class TnProcedureHandler method handleOutParameter.
/**
* Handle result set for out-parameter.
* @param conn The connection for the database. (NotNull)
* @param cs The statement of procedure. (NotNull)
* @param pmb The parameter bean from arguments. (NotNull)
* @param executed The return value of execute() that means whether the first result is a result set.
* @throws SQLException When it fails to handle the SQL.
*/
protected void handleOutParameter(Connection conn, CallableStatement cs, Object pmb, boolean executed) throws SQLException {
if (pmb == null) {
return;
}
int index = 0;
for (TnProcedureParameterType ppt : _procedureMetaData.getBindParameterTypeList()) {
final ValueType valueType = ppt.getValueType();
if (ppt.isOutType()) {
Object value = valueType.getValue(cs, index + 1);
if (value instanceof ResultSet) {
final ResultSet rs = wrapResultSetIfNeeds(pmb, (ResultSet) value);
final TnResultSetHandler handler = createResultSetHandler(pmb, ppt);
try {
value = handler.handle(rs);
} finally {
if (rs != null) {
rs.close();
}
}
}
ppt.setValue(pmb, value);
}
++index;
}
}
use of org.dbflute.s2dao.jdbc.TnResultSetHandler in project dbflute-core by dbflute.
the class TnProcedureHandler method handleNotParamResult.
/**
* Handle not-parameter result set, for example, MySQL, DB2 and (MS) SQLServer.
* @param conn The connection for the database. (NotNull)
* @param cs The statement of procedure. (NotNull)
* @param pmb The parameter bean from arguments. (NotNull)
* @param executed The return value of execute() that means whether the first result is a result set.
* @throws SQLException When it fails to handle the SQL.
*/
@SuppressWarnings("resource")
protected void handleNotParamResult(Connection conn, CallableStatement cs, Object pmb, boolean executed) throws SQLException {
if (pmb == null) {
return;
}
if (!executed) {
if (!cs.getMoreResults()) {
// just in case
return;
}
}
final List<TnProcedureParameterType> resultList = _procedureMetaData.getNotParamResultTypeList();
ResultSet rs = null;
for (TnProcedureParameterType ppt : resultList) {
try {
rs = cs.getResultSet();
if (rs == null) {
break;
}
rs = wrapResultSetIfNeeds(pmb, rs);
final TnResultSetHandler handler = createResultSetHandler(pmb, ppt);
final Object beanList = handler.handle(rs);
ppt.setValue(pmb, beanList);
if (!cs.getMoreResults()) {
break;
}
} finally {
if (rs != null) {
rs.close();
}
}
}
}
Aggregations