Search in sources :

Example 1 with OutsideSqlContext

use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.

the class AbstractOutsideSqlCommand method createOutsideSqlContext.

// ===================================================================================
// OutsideSql Element
// ==================
protected OutsideSqlContext createOutsideSqlContext() {
    final DBMetaProvider dbmetaProvider = ResourceContext.dbmetaProvider();
    final String outsideSqlPackage = ResourceContext.getOutsideSqlPackage();
    final OutsideSqlContext context = _outsideSqlContextFactory.createContext(dbmetaProvider, outsideSqlPackage);
    setupOutsideSqlContextProperty(context);
    context.setupBehaviorQueryPathIfNeeds();
    return context;
}
Also used : OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) DBMetaProvider(org.dbflute.dbmeta.DBMetaProvider)

Example 2 with OutsideSqlContext

use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.

the class TnBeanListResultSetHandler method mappingBean.

protected void mappingBean(ResultSet rs, BeanRowHandler handler) throws SQLException {
    // lazy initialization because if the result is zero, the resources are unused
    Map<String, String> selectColumnMap = null;
    Map<String, TnPropertyMapping> propertyCache = null;
    // key is relationNoSuffix, columnName
    Map<String, Map<String, TnPropertyMapping>> relPropCache = null;
    TnRelationRowCache relRowCache = null;
    TnRelationSelector relSelector = null;
    final TnBeanMetaData basePointBmd = getBeanMetaData();
    // condition-bean info (variable for minimum thread local access)
    final boolean hasCB = hasConditionBean();
    final ConditionBean cb = hasCB ? getConditionBean() : null;
    // outsideSql info (also variable for minimum thread local access)
    final boolean hasOql = hasOutsideSqlContext();
    final OutsideSqlContext oqlCtx = OutsideSqlContext.getOutsideSqlContextOnThread();
    final boolean checkNonSp = checkNonSpecifiedColumnAccess(hasCB, cb, hasOql, oqlCtx);
    final boolean colNullObj = isUseColumnNullObjectHandling(hasCB, cb);
    final boolean skipRelationLoop;
    {
        final boolean emptyRelationCB = hasCB && isSelectedRelationEmpty(cb);
        final boolean specifiedOutsideSql = hasOql && isSpecifiedOutsideSql(oqlCtx);
        // if it has condition-bean that has no relation to get
        // or it has outside SQL context that is specified outside-SQL,
        // they are unnecessary to do relation loop
        skipRelationLoop = emptyRelationCB || specifiedOutsideSql;
    }
    // null allowed
    final Map<String, Map<String, Integer>> selectIndexMap = ResourceContext.getSelectIndexMap();
    while (rs.next()) {
        if (selectColumnMap == null) {
            selectColumnMap = createSelectColumnMap(rs);
        }
        if (propertyCache == null) {
            propertyCache = createPropertyCache(selectColumnMap, selectIndexMap);
        }
        // create row instance of base table by row property cache
        final Object row = createRow(rs, selectIndexMap, propertyCache, cb);
        if (skipRelationLoop) {
            adjustCreatedRow(row, checkNonSp, colNullObj, basePointBmd, cb);
            final boolean continueToNext = handler.handle(row);
            if (!continueToNext) {
                // skip rear records (basically for cursor select)
                break;
            }
            continue;
        }
        if (relSelector == null) {
            relSelector = createRelationSelector(hasCB, cb);
        }
        if (relPropCache == null) {
            relPropCache = createRelationPropertyCache(selectColumnMap, selectIndexMap, relSelector);
        }
        if (relRowCache == null) {
            relRowCache = createRelationRowCache(hasCB, cb);
        }
        final List<TnRelationPropertyType> rptList = basePointBmd.getRelationPropertyTypeList();
        for (TnRelationPropertyType rpt : rptList) {
            if (relSelector.isNonSelectedRelation(rpt.getRelationNoSuffixPart())) {
                continue;
            }
            mappingFirstRelation(rs, row, rpt, selectColumnMap, selectIndexMap, relPropCache, relRowCache, relSelector);
        }
        adjustCreatedRow(row, checkNonSp, colNullObj, basePointBmd, cb);
        final boolean continueToNext = handler.handle(row);
        if (!continueToNext) {
            // skip rear records (basically for cursor select)
            break;
        }
    }
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) ConditionBean(org.dbflute.cbean.ConditionBean) TnPropertyMapping(org.dbflute.s2dao.metadata.TnPropertyMapping) TnRelationRowCache(org.dbflute.s2dao.rowcreator.TnRelationRowCache) OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData) Map(java.util.Map) TnRelationSelector(org.dbflute.s2dao.rowcreator.TnRelationSelector)

Example 3 with OutsideSqlContext

use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.

the class TnStatementFactoryImpl method findStatementConfigOnThread.

// -----------------------------------------------------
// StatementConfig
// ---------------
protected StatementConfig findStatementConfigOnThread() {
    final StatementConfig config;
    if (ConditionBeanContext.isExistConditionBeanOnThread()) {
        final ConditionBean cb = ConditionBeanContext.getConditionBeanOnThread();
        config = cb.getStatementConfig();
    } else if (OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
        final OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
        config = context.getStatementConfig();
    } else {
        // update or no exist
        config = InternalMapContext.getUpdateStatementConfig();
    }
    return config;
}
Also used : OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) ConditionBean(org.dbflute.cbean.ConditionBean) StatementConfig(org.dbflute.jdbc.StatementConfig)

Example 4 with OutsideSqlContext

use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.

the class TnBasicSelectHandler method isUseFunctionalResultSet.

protected boolean isUseFunctionalResultSet() {
    // for safety result
    final FetchBean fcbean = FetchAssistContext.getFetchBeanOnThread();
    if (fcbean != null && fcbean.getSafetyMaxResultSize() > 0) {
        // priority one
        return true;
    }
    final FetchNarrowingBean fnbean = FetchAssistContext.getFetchNarrowingBeanOnThread();
    if (fnbean != null && fnbean.isFetchNarrowingEffective()) {
        // for unsupported paging (ConditionBean)
        if (fnbean.isFetchNarrowingSkipStartIndexEffective() || fnbean.isFetchNarrowingLoopCountEffective()) {
            // priority two
            return true;
        }
        // for auto paging (OutsideSql)
        if (OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
            final OutsideSqlContext outsideSqlContext = OutsideSqlContext.getOutsideSqlContextOnThread();
            if (outsideSqlContext.isOffsetByCursorForcedly() || outsideSqlContext.isLimitByCursorForcedly()) {
                // priority three
                return true;
            }
        }
    }
    return false;
}
Also used : FetchBean(org.dbflute.jdbc.FetchBean) OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) FetchNarrowingBean(org.dbflute.cbean.paging.FetchNarrowingBean)

Example 5 with OutsideSqlContext

use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.

the class TnBasicSelectHandler method doQueryResult.

protected ResultSet doQueryResult(PreparedStatement ps) throws SQLException {
    // /- - - - - - - - - - - - - - - - - - - - - - - - - - -
    // All select statements on DBFlute use this result set.
    // - - - - - - - - - -/
    final ResultSet rs = executeQuery(ps);
    if (!isUseFunctionalResultSet()) {
        return rs;
    }
    if (isInternalDebugEnabled()) {
        _log.debug("...Wrapping result set by functional one");
    }
    final FetchBean selbean = FetchAssistContext.getFetchBeanOnThread();
    final TnFetchAssistResultSet wrapper;
    if (OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
        final OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
        final boolean offsetByCursorForcedly = context.isOffsetByCursorForcedly();
        final boolean limitByCursorForcedly = context.isLimitByCursorForcedly();
        wrapper = createFunctionalResultSet(rs, selbean, offsetByCursorForcedly, limitByCursorForcedly);
    } else {
        wrapper = createFunctionalResultSet(rs, selbean, false, false);
    }
    return wrapper;
}
Also used : FetchBean(org.dbflute.jdbc.FetchBean) OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) ResultSet(java.sql.ResultSet) TnFetchAssistResultSet(org.dbflute.s2dao.jdbc.TnFetchAssistResultSet) TnFetchAssistResultSet(org.dbflute.s2dao.jdbc.TnFetchAssistResultSet)

Aggregations

OutsideSqlContext (org.dbflute.outsidesql.OutsideSqlContext)11 ConditionBean (org.dbflute.cbean.ConditionBean)3 FetchBean (org.dbflute.jdbc.FetchBean)3 ResultSet (java.sql.ResultSet)2 BehaviorInvokeNameResult (org.dbflute.bhv.logging.invoke.BehaviorInvokeNameResult)2 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 BehaviorInvokeNameExtractor (org.dbflute.bhv.logging.invoke.BehaviorInvokeNameExtractor)1 BehaviorInvokePathResult (org.dbflute.bhv.logging.invoke.BehaviorInvokePathResult)1 FetchNarrowingBean (org.dbflute.cbean.paging.FetchNarrowingBean)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 DBMetaProvider (org.dbflute.dbmeta.DBMetaProvider)1 SQLFailureException (org.dbflute.exception.SQLFailureException)1 CursorHandler (org.dbflute.jdbc.CursorHandler)1 StatementConfig (org.dbflute.jdbc.StatementConfig)1 TnFetchAssistResultSet (org.dbflute.s2dao.jdbc.TnFetchAssistResultSet)1 TnResultSetHandler (org.dbflute.s2dao.jdbc.TnResultSetHandler)1 TnBeanMetaData (org.dbflute.s2dao.metadata.TnBeanMetaData)1 TnPropertyMapping (org.dbflute.s2dao.metadata.TnPropertyMapping)1