Search in sources :

Example 6 with BehaviorCommandHook

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

the class CallbackContextTest method test_BehaviorCommandHook_twoSet_terminateLast.

public void test_BehaviorCommandHook_twoSet_terminateLast() throws Exception {
    // ## Arrange ##
    CallbackContext context = new CallbackContext();
    assertNull(context.getBehaviorCommandHook());
    setupTwoBehaviorCommandHook(context);
    assertNotNull(context.getBehaviorCommandHook());
    assertTrue(context.getBehaviorCommandHook() instanceof InheritableBehaviorCommandHook);
    assertEquals(2, ((InheritableBehaviorCommandHook) context.getBehaviorCommandHook()).countManagedHook());
    // ## Act ##
    context.terminateLastBehaviorCommandHook();
    // ## Assert ##
    BehaviorCommandHook hook = context.getBehaviorCommandHook();
    assertNotNull(hook);
    hook.hookBefore(null);
    hook.hookFinally(null, null);
    assertMarked("firstBefore");
    assertMarked("firstFinally");
    assertFalse(context.getBehaviorCommandHook() instanceof InheritableBehaviorCommandHook);
}
Also used : InheritableBehaviorCommandHook(org.dbflute.hook.CallbackContext.InheritableBehaviorCommandHook) BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook) InheritableBehaviorCommandHook(org.dbflute.hook.CallbackContext.InheritableBehaviorCommandHook)

Example 7 with BehaviorCommandHook

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

the class CallbackContextTest method setupTwoBehaviorCommandHook.

private void setupTwoBehaviorCommandHook(CallbackContext context) {
    context.setBehaviorCommandHook(new BehaviorCommandHook() {

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

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

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

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

Example 8 with BehaviorCommandHook

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

the class CallbackContextTest method test_BehaviorCommandHook_twoSet_inherits.

// ===================================================================================
// BehaviorCommandHook
// ===================
// -----------------------------------------------------
// Two Set
// -------
public void test_BehaviorCommandHook_twoSet_inherits() throws Exception {
    // ## Arrange ##
    CallbackContext context = new CallbackContext();
    assertNull(context.getBehaviorCommandHook());
    // ## Act ##
    setupTwoBehaviorCommandHook(context);
    // ## Assert ##
    BehaviorCommandHook hook = context.getBehaviorCommandHook();
    assertTrue(hook.inheritsExistingHook());
    hook.hookBefore(null);
    hook.hookFinally(null, null);
    assertMarked("firstBefore");
    assertMarked("secondBefore");
    assertMarked("secondFinally");
    assertMarked("firstFinally");
    context.terminateLastBehaviorCommandHook();
    assertNotNull(context.getBehaviorCommandHook());
    context.terminateLastBehaviorCommandHook();
    assertNull(context.getBehaviorCommandHook());
}
Also used : BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook) InheritableBehaviorCommandHook(org.dbflute.hook.CallbackContext.InheritableBehaviorCommandHook)

Example 9 with BehaviorCommandHook

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

the class CallbackContextWholeTest method test_BehaviorCommandHook_whole_clear.

// -----------------------------------------------------
// Clear
// -----
public void test_BehaviorCommandHook_whole_clear() throws Exception {
    // ## Arrange ##
    // ## Act ##
    setupTwoBehaviorCommandHook();
    // ## Assert ##
    BehaviorCommandHook hook = CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook();
    assertTrue(hook.inheritsExistingHook());
    hook.hookBefore(null);
    hook.hookFinally(null, null);
    assertMarked("firstBefore");
    assertMarked("secondBefore");
    assertMarked("secondFinally");
    assertMarked("firstFinally");
    CallbackContext.clearBehaviorCommandHookOnThread();
    assertNull(CallbackContext.getCallbackContextOnThread());
}
Also used : BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook)

Example 10 with BehaviorCommandHook

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

the class CallbackContextTest method setupThreeBehaviorCommandHook.

private void setupThreeBehaviorCommandHook(CallbackContext context) {
    setupTwoBehaviorCommandHook(context);
    context.setBehaviorCommandHook(new BehaviorCommandHook() {

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

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

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