Search in sources :

Example 1 with TnResultSetHandler

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);
        }
    };
}
Also used : CursorHandler(org.dbflute.jdbc.CursorHandler) OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) TnResultSetHandler(org.dbflute.s2dao.jdbc.TnResultSetHandler) ResultSet(java.sql.ResultSet)

Example 2 with TnResultSetHandler

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;
}
Also used : TnResultSetHandler(org.dbflute.s2dao.jdbc.TnResultSetHandler) OutsideSqlSelectExecution(org.dbflute.bhv.core.execution.OutsideSqlSelectExecution)

Example 3 with TnResultSetHandler

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;
    }
}
Also used : ValueType(org.dbflute.jdbc.ValueType) ResultSet(java.sql.ResultSet) TnFetchAssistResultSet(org.dbflute.s2dao.jdbc.TnFetchAssistResultSet) TnResultSetHandler(org.dbflute.s2dao.jdbc.TnResultSetHandler) TnProcedureParameterType(org.dbflute.s2dao.metadata.TnProcedureParameterType)

Example 4 with TnResultSetHandler

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();
            }
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) TnFetchAssistResultSet(org.dbflute.s2dao.jdbc.TnFetchAssistResultSet) TnResultSetHandler(org.dbflute.s2dao.jdbc.TnResultSetHandler) TnProcedureParameterType(org.dbflute.s2dao.metadata.TnProcedureParameterType)

Aggregations

TnResultSetHandler (org.dbflute.s2dao.jdbc.TnResultSetHandler)4 ResultSet (java.sql.ResultSet)3 TnFetchAssistResultSet (org.dbflute.s2dao.jdbc.TnFetchAssistResultSet)2 TnProcedureParameterType (org.dbflute.s2dao.metadata.TnProcedureParameterType)2 OutsideSqlSelectExecution (org.dbflute.bhv.core.execution.OutsideSqlSelectExecution)1 CursorHandler (org.dbflute.jdbc.CursorHandler)1 ValueType (org.dbflute.jdbc.ValueType)1 OutsideSqlContext (org.dbflute.outsidesql.OutsideSqlContext)1