Search in sources :

Example 1 with BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta 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 BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta 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 BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta 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 4 with BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta 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 5 with BehaviorCommandMeta

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

the class SelectCBExecution method doFilterExecutedSqlByCallbackFilter.

protected String doFilterExecutedSqlByCallbackFilter(String executedSql) {
    final SqlStringFilter sqlStringFilter = getSqlStringFilter();
    if (sqlStringFilter != null) {
        final BehaviorCommandMeta meta = ResourceContext.behaviorCommand();
        final String filteredSql = sqlStringFilter.filterSelectCB(meta, executedSql);
        return filteredSql != null ? filteredSql : executedSql;
    }
    return executedSql;
}
Also used : SqlStringFilter(org.dbflute.hook.SqlStringFilter) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Aggregations

BehaviorCommandMeta (org.dbflute.bhv.core.BehaviorCommandMeta)13 BehaviorCommandHook (org.dbflute.bhv.core.BehaviorCommandHook)6 SqlStringFilter (org.dbflute.hook.SqlStringFilter)5 InheritableBehaviorCommandHook (org.dbflute.hook.CallbackContext.InheritableBehaviorCommandHook)3 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Entity (org.dbflute.Entity)1 BehaviorCommand (org.dbflute.bhv.core.BehaviorCommand)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 ExecutionTimeInfo (org.dbflute.jdbc.ExecutionTimeInfo)1 DfCollectionUtil (org.dbflute.util.DfCollectionUtil)1 RomanticTransaction (org.lastaflute.db.jta.RomanticTransaction)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1