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");
}
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");
}
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;
}
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");
}
});
}
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());
}
}
Aggregations