Search in sources :

Example 6 with OutsideSqlContext

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

the class BehaviorCommandInvoker method createUnknownInvokeNameResult.

protected BehaviorInvokeNameResult createUnknownInvokeNameResult() {
    // basically no way
    final String unknownKeyword;
    if (OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
        // e.g. OutsideSql engine use
        final OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
        unknownKeyword = context.getTableDbName();
    } else {
        unknownKeyword = "Unknown";
    }
    final String expNoMethodSuffix = unknownKeyword + ".invoke";
    return new BehaviorInvokeNameResult(expNoMethodSuffix + "()", expNoMethodSuffix, null, null);
}
Also used : OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) BehaviorInvokeNameResult(org.dbflute.bhv.logging.invoke.BehaviorInvokeNameResult)

Example 7 with OutsideSqlContext

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

the class BehaviorCommandInvoker method logInvocation.

// ===================================================================================
// Log Invocation
// ==============
protected <RESULT> void logInvocation(BehaviorCommand<RESULT> behaviorCommand, boolean saveOnly) {
    final StackTraceElement[] stackTrace = new Exception().getStackTrace();
    final BehaviorInvokeNameResult behaviorInvokeNameResult = extractBehaviorInvoke(behaviorCommand, stackTrace);
    saveBehaviorInvokeName(behaviorInvokeNameResult);
    final BehaviorInvokePathResult invokePathResult = buildInvokePath(behaviorCommand, stackTrace, behaviorInvokeNameResult);
    if (invokePathResult != null) {
        saveClientInvokeName(invokePathResult);
        saveByPassInvokeName(invokePathResult);
        saveInvokePath(invokePathResult);
    }
    if (saveOnly) {
        // e.g. log level is INFO and invocation path ready
        return;
    }
    final String expNoMethodSuffix = behaviorInvokeNameResult.getInvocationExpNoMethodSuffix();
    final String equalBorder = buildFitBorder("", "=", expNoMethodSuffix, false);
    final String frameBase = "/=====================================================";
    final String spaceBase = "                                                      ";
    log(frameBase + equalBorder + "==");
    log(spaceBase + behaviorInvokeNameResult.getInvocationExp());
    log(spaceBase + equalBorder + "=/");
    if (invokePathResult != null) {
        final String invokePath = invokePathResult.getInvokePath();
        if (Srl.is_NotNull_and_NotTrimmedEmpty(invokePath)) {
            // just in case
            log(invokePath);
        }
    }
    if (behaviorCommand.isOutsideSql() && !behaviorCommand.isProcedure()) {
        final OutsideSqlContext outsideSqlContext = getOutsideSqlContext();
        if (outsideSqlContext != null) {
            log("path: " + behaviorCommand.getOutsideSqlPath());
            log("option: " + behaviorCommand.getOutsideSqlOption());
        }
    }
}
Also used : OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) BehaviorInvokePathResult(org.dbflute.bhv.logging.invoke.BehaviorInvokePathResult) SQLException(java.sql.SQLException) SQLFailureException(org.dbflute.exception.SQLFailureException) BehaviorInvokeNameResult(org.dbflute.bhv.logging.invoke.BehaviorInvokeNameResult)

Example 8 with OutsideSqlContext

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

the class BehaviorCommandInvoker method extractBehaviorInvoke.

// -----------------------------------------------------
// Extract BehaviorInvoke
// ----------------------
protected <RESULT> BehaviorInvokeNameResult extractBehaviorInvoke(BehaviorCommand<RESULT> behaviorCommand, StackTraceElement[] stackTrace) {
    final DBMeta dbmeta = ResourceContext.provideDBMeta(behaviorCommand.getTableDbName());
    if (dbmeta == null) {
        // basically no way, only direct invoking
        return createUnknownInvokeNameResult();
    }
    Class<?> outsideSqlResultType = null;
    boolean outsideSqlAutoPaging = false;
    if (behaviorCommand.isOutsideSql()) {
        final OutsideSqlContext outsideSqlContext = getOutsideSqlContext();
        outsideSqlResultType = outsideSqlContext.getResultType();
        outsideSqlAutoPaging = outsideSqlContext.isAutoPagingLogging();
    }
    final BehaviorInvokeNameExtractor extractor = createBehaviorInvokeNameExtractor(dbmeta, outsideSqlResultType, outsideSqlAutoPaging);
    return extractor.extractBehaviorInvoke(stackTrace);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) BehaviorInvokeNameExtractor(org.dbflute.bhv.logging.invoke.BehaviorInvokeNameExtractor)

Example 9 with OutsideSqlContext

use of org.dbflute.outsidesql.OutsideSqlContext 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 10 with OutsideSqlContext

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

the class ContextStack method restoreAllContextOnThreadIfExists.

public static void restoreAllContextOnThreadIfExists() {
    if (!isExistContextStackOnThread()) {
        return;
    }
    final Stack<ContextStack> stackOnThread = getContextStackOnThread();
    if (stackOnThread.isEmpty()) {
        clearContextStackOnThread();
        return;
    }
    final ContextStack contextStack = stackOnThread.pop();
    final ConditionBean cb = contextStack.getConditionBean();
    if (cb != null) {
        ConditionBeanContext.setConditionBeanOnThread(cb);
    }
    final EntityRowHandler<? extends Entity> entityRowHandler = contextStack.getEntityRowHandler();
    if (entityRowHandler != null) {
        ConditionBeanContext.setEntityRowHandlerOnThread(entityRowHandler);
    }
    final OutsideSqlContext outsideSqlContext = contextStack.getOutsideSqlContext();
    if (outsideSqlContext != null) {
        OutsideSqlContext.setOutsideSqlContextOnThread(outsideSqlContext);
    }
    final FetchBean fetchBean = contextStack.getFetchBean();
    if (fetchBean != null) {
        FetchAssistContext.setFetchBeanOnThread(fetchBean);
    }
    final Map<String, Object> internalMap = contextStack.getInternalMap();
    if (internalMap != null) {
        InternalMapContext.clearInternalMapContextOnThread();
        final Set<Entry<String, Object>> entrySet = internalMap.entrySet();
        for (Entry<String, Object> entry : entrySet) {
            InternalMapContext.setObject(entry.getKey(), entry.getValue());
        }
    }
    final ResourceContext resourceContext = contextStack.getResourceContext();
    if (resourceContext != null) {
        ResourceContext.setResourceContextOnThread(resourceContext);
    }
}
Also used : FetchBean(org.dbflute.jdbc.FetchBean) ConditionBean(org.dbflute.cbean.ConditionBean) Entry(java.util.Map.Entry) OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext)

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