Search in sources :

Example 1 with BehaviorCommandHook

use of org.dbflute.bhv.core.BehaviorCommandHook in project dbflute-core by dbflute.

the class CallbackContextTest method test_BehaviorCommandHook_twiceSet_noInherits.

// ===================================================================================
// BehaviorCommandHook
// ===================
public void test_BehaviorCommandHook_twiceSet_noInherits() throws Exception {
    // ## Arrange ##
    CallbackContext context = new CallbackContext();
    assertNull(context.getBehaviorCommandHook());
    // ## Act ##
    context.setBehaviorCommandHook(new BehaviorCommandHook() {

        public void hookBefore(BehaviorCommandMeta meta) {
            fail();
        }

        public void hookFinally(BehaviorCommandMeta meta, RuntimeException cause) {
            fail();
        }
    });
    context.setBehaviorCommandHook(new BehaviorCommandHook() {

        public void hookBefore(BehaviorCommandMeta meta) {
            log("2");
            markHere("secondBefore");
        }

        public void hookFinally(BehaviorCommandMeta meta, RuntimeException cause) {
            log("3");
            markHere("secondFinally");
        }

        @Override
        public boolean inheritsExistingHook() {
            return false;
        }
    });
    // ## Assert ##
    BehaviorCommandHook hook = context.getBehaviorCommandHook();
    assertFalse(hook.inheritsExistingHook());
    hook.hookBefore(null);
    hook.hookFinally(null, null);
    assertMarked("secondBefore");
    assertMarked("secondFinally");
}
Also used : BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Example 2 with BehaviorCommandHook

use of org.dbflute.bhv.core.BehaviorCommandHook in project dbflute-core by dbflute.

the class CallbackContextTest method test_BehaviorCommandHook_twiceSet_inherits.

public void test_BehaviorCommandHook_twiceSet_inherits() throws Exception {
    // ## Arrange ##
    CallbackContext context = new CallbackContext();
    assertNull(context.getBehaviorCommandHook());
    // ## Act ##
    context.setBehaviorCommandHook(new BehaviorCommandHook() {

        public void hookBefore(BehaviorCommandMeta meta) {
            log("1");
            markHere("firstBefore");
        }

        public void hookFinally(BehaviorCommandMeta meta, RuntimeException cause) {
            log("4");
            markHere("firstFinally");
        }
    });
    context.setBehaviorCommandHook(new BehaviorCommandHook() {

        public void hookBefore(BehaviorCommandMeta meta) {
            log("2");
            markHere("secondBefore");
        }

        public void hookFinally(BehaviorCommandMeta meta, RuntimeException cause) {
            log("3");
            markHere("secondFinally");
        }

        @Override
        public boolean inheritsExistingHook() {
            return true;
        }
    });
    // ## Assert ##
    BehaviorCommandHook hook = context.getBehaviorCommandHook();
    assertTrue(hook.inheritsExistingHook());
    hook.hookBefore(null);
    hook.hookFinally(null, null);
    assertMarked("firstBefore");
    assertMarked("secondBefore");
    assertMarked("secondFinally");
    assertMarked("firstFinally");
}
Also used : BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Example 3 with BehaviorCommandHook

use of org.dbflute.bhv.core.BehaviorCommandHook in project lastaflute by lastaflute.

the class SimpleAsyncManager method doInheritCallbackContext.

protected CallbackContext doInheritCallbackContext(ConcurrentAsyncCall call) {
    // null allowed
    final CallbackContext src = CallbackContext.getCallbackContextOnThread();
    if (src == null) {
        return null;
    }
    final CallbackContext dest = newCallbackContext();
    final ConcurrentAsyncOption option = call.option();
    final ConcurrentAsyncOption defaultOption = defaultConcurrentAsyncOption;
    if (isInherit(option.getBehaviorCommandHookType(), defaultOption.getBehaviorCommandHookType())) {
        final BehaviorCommandHook hook = src.getBehaviorCommandHook();
        if (hook != null) {
            dest.setBehaviorCommandHook(hook);
        }
    }
    if (isInherit(option.getSqlFireHookType(), defaultOption.getSqlFireHookType())) {
        final SqlFireHook hook = src.getSqlFireHook();
        if (hook != null) {
            dest.setSqlFireHook(hook);
        }
    } else {
        // as default
        dest.setSqlFireHook(createDefaultSqlFireHook(call));
    }
    if (isInherit(option.getSqlLogHandlerType(), defaultOption.getSqlLogHandlerType())) {
        final SqlLogHandler handler = src.getSqlLogHandler();
        if (handler != null) {
            dest.setSqlLogHandler(handler);
        }
    }
    if (isInherit(option.getSqlResultHandlerType(), defaultOption.getSqlResultHandlerType())) {
        final SqlResultHandler handler = src.getSqlResultHandler();
        if (handler != null) {
            dest.setSqlResultHandler(handler);
        }
    } else {
        dest.setSqlResultHandler(createDefaultSqlResultHandler(call));
    }
    if (isInherit(option.getSqlStringFilterType(), defaultOption.getSqlStringFilterType())) {
        final SqlStringFilter filter = src.getSqlStringFilter();
        if (filter != null) {
            dest.setSqlStringFilter(filter);
        }
    } else {
        // as default
        dest.setSqlStringFilter(createDefaultSqlStringFilter(call));
    }
    return dest;
}
Also used : SqlLogHandler(org.dbflute.hook.SqlLogHandler) SqlResultHandler(org.dbflute.hook.SqlResultHandler) RomanticTraceableSqlResultHandler(org.lastaflute.db.dbflute.callbackcontext.traceablesql.RomanticTraceableSqlResultHandler) RomanticTraceableSqlStringFilter(org.lastaflute.db.dbflute.callbackcontext.traceablesql.RomanticTraceableSqlStringFilter) SqlStringFilter(org.dbflute.hook.SqlStringFilter) BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook) CallbackContext(org.dbflute.hook.CallbackContext) RomanticTraceableSqlFireHook(org.lastaflute.db.dbflute.callbackcontext.traceablesql.RomanticTraceableSqlFireHook) SqlFireHook(org.dbflute.hook.SqlFireHook)

Example 4 with BehaviorCommandHook

use of org.dbflute.bhv.core.BehaviorCommandHook in project dbflute-core by dbflute.

the class CallbackContextWholeTest method setupTwoBehaviorCommandHook.

private void setupTwoBehaviorCommandHook() {
    CallbackContext.setBehaviorCommandHookOnThread(new BehaviorCommandHook() {

        public void hookBefore(BehaviorCommandMeta meta) {
            log("firstBefore");
            markHere("firstBefore");
        }

        public void hookFinally(BehaviorCommandMeta meta, RuntimeException cause) {
            log("firstFinally");
            markHere("firstFinally");
        }
    });
    CallbackContext.setBehaviorCommandHookOnThread(new BehaviorCommandHook() {

        public void hookBefore(BehaviorCommandMeta meta) {
            log("secondBefore");
            markHere("secondBefore");
        }

        public void hookFinally(BehaviorCommandMeta meta, RuntimeException cause) {
            log("secondFinally");
            markHere("secondFinally");
        }
    });
}
Also used : BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Example 5 with BehaviorCommandHook

use of org.dbflute.bhv.core.BehaviorCommandHook in project dbflute-core by dbflute.

the class CallbackContextWholeTest method assertTwoBehaviorCommandHook.

private void assertTwoBehaviorCommandHook(boolean finalCallback) {
    BehaviorCommandHook hook = CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook();
    assertTrue(hook.inheritsExistingHook());
    hook.hookBefore(null);
    hook.hookFinally(null, null);
    assertMarked("firstBefore");
    assertMarked("secondBefore");
    assertMarked("secondFinally");
    assertMarked("firstFinally");
    assertEquals(hook, CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook());
    CallbackContext.terminateLastBehaviorCommandHookOnThread();
    assertNotNull(CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook());
    assertNotSame(hook, CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook());
    CallbackContext.terminateLastBehaviorCommandHookOnThread();
    if (finalCallback) {
        assertNull(CallbackContext.getCallbackContextOnThread());
    } else {
        assertNull(CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook());
    }
}
Also used : BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook)

Aggregations

BehaviorCommandHook (org.dbflute.bhv.core.BehaviorCommandHook)13 InheritableBehaviorCommandHook (org.dbflute.hook.CallbackContext.InheritableBehaviorCommandHook)7 BehaviorCommandMeta (org.dbflute.bhv.core.BehaviorCommandMeta)6 CallbackContext (org.dbflute.hook.CallbackContext)1 SqlFireHook (org.dbflute.hook.SqlFireHook)1 SqlLogHandler (org.dbflute.hook.SqlLogHandler)1 SqlResultHandler (org.dbflute.hook.SqlResultHandler)1 SqlStringFilter (org.dbflute.hook.SqlStringFilter)1 RomanticTraceableSqlFireHook (org.lastaflute.db.dbflute.callbackcontext.traceablesql.RomanticTraceableSqlFireHook)1 RomanticTraceableSqlResultHandler (org.lastaflute.db.dbflute.callbackcontext.traceablesql.RomanticTraceableSqlResultHandler)1 RomanticTraceableSqlStringFilter (org.lastaflute.db.dbflute.callbackcontext.traceablesql.RomanticTraceableSqlStringFilter)1