Search in sources :

Example 6 with ResourceContext

use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.

the class TnAbstractBasicSqlHandlerTest method prepareMockBehaviorCommand.

protected void prepareMockBehaviorCommand() {
    MockBehaviorCommand behaviorCommand = new MockBehaviorCommand();
    ResourceContext resourceContext = new ResourceContext();
    resourceContext.setBehaviorCommand(behaviorCommand);
    ResourceContext.setResourceContextOnThread(resourceContext);
}
Also used : MockBehaviorCommand(org.dbflute.mock.MockBehaviorCommand) ResourceContext(org.dbflute.bhv.core.context.ResourceContext)

Example 7 with ResourceContext

use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.

the class BehaviorCommandInvokerTest method test_clearContext.

public void test_clearContext() {
    // ## Arrange ##
    BehaviorCommandInvoker invoker = new BehaviorCommandInvoker();
    OutsideSqlContext.setOutsideSqlContextOnThread(new MockOutsideSqlContext());
    FetchAssistContext.setFetchBeanOnThread(new MockConditionBean());
    ConditionBeanContext.setConditionBeanOnThread(new MockConditionBean());
    ConditionBeanContext.setEntityRowHandlerOnThread(new EntityRowHandler<Entity>() {

        public void handle(Entity entity) {
        }
    });
    InternalMapContext.setObject("dummy", new Object());
    ResourceContext.setResourceContextOnThread(new ResourceContext());
    assertTrue(OutsideSqlContext.isExistOutsideSqlContextOnThread());
    assertTrue(FetchAssistContext.isExistFetchNarrowingBeanOnThread());
    assertTrue(ConditionBeanContext.isExistConditionBeanOnThread());
    assertTrue(ConditionBeanContext.isExistEntityRowHandlerOnThread());
    assertTrue(InternalMapContext.isExistInternalMapContextOnThread());
    assertTrue(ResourceContext.isExistResourceContextOnThread());
    // ## Act ##
    invoker.clearAllCurrentContext();
    // ## Assert ##
    assertFalse(OutsideSqlContext.isExistOutsideSqlContextOnThread());
    assertFalse(FetchAssistContext.isExistFetchNarrowingBeanOnThread());
    assertFalse(ConditionBeanContext.isExistConditionBeanOnThread());
    assertFalse(ConditionBeanContext.isExistEntityRowHandlerOnThread());
    assertFalse(InternalMapContext.isExistInternalMapContextOnThread());
    assertFalse(ResourceContext.isExistResourceContextOnThread());
}
Also used : Entity(org.dbflute.Entity) MockOutsideSqlContext(org.dbflute.mock.MockOutsideSqlContext) ResourceContext(org.dbflute.bhv.core.context.ResourceContext) MockConditionBean(org.dbflute.mock.MockConditionBean)

Example 8 with ResourceContext

use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.

the class SequenceCacheHandlerTest method test_filterNextValSql_half_Oracle.

public void test_filterNextValSql_half_Oracle() {
    // ## Arrange ##
    SequenceCacheHandler handler = new SequenceCacheHandler();
    String sql = "select SEQ_MEMBER.nextval from dual";
    ResourceContext context = new ResourceContext();
    context.setCurrentDBDef(DBDef.Oracle);
    ResourceContext.setResourceContextOnThread(context);
    try {
        // ## Act ##
        String actual = handler.filterNextValSql(50, 25, sql);
        // ## Assert ##
        log(actual);
        assertTrue(actual.contains("nextval"));
        assertTrue(actual.contains("select * from dual"));
        assertTrue(actual.contains(" union all"));
        assertTrue(actual.contains(" join_1"));
        assertFalse(actual.contains(" join_2"));
        assertEquals(3, DfStringUtil.splitList(actual, "select * from dual").size());
        assertTrue(actual.contains(" rownum <= 2"));
    } finally {
        ResourceContext.clearResourceContextOnThread();
    }
}
Also used : ResourceContext(org.dbflute.bhv.core.context.ResourceContext)

Example 9 with ResourceContext

use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.

the class SequenceCacheHandlerTest method test_filterNextValSql_same_Oracle.

public void test_filterNextValSql_same_Oracle() {
    // ## Arrange ##
    SequenceCacheHandler handler = new SequenceCacheHandler();
    String sql = "select SEQ_MEMBER.nextval from dual";
    ResourceContext context = new ResourceContext();
    context.setCurrentDBDef(DBDef.Oracle);
    ResourceContext.setResourceContextOnThread(context);
    try {
        // ## Act ##
        String actual = handler.filterNextValSql(50, 50, sql);
        // ## Assert ##
        log(actual);
        assertEquals(sql, actual);
        assertFalse(actual.contains("order by"));
    } finally {
        ResourceContext.clearResourceContextOnThread();
    }
}
Also used : ResourceContext(org.dbflute.bhv.core.context.ResourceContext)

Example 10 with ResourceContext

use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.

the class SequenceCacheHandlerTest method test_filterNextValSql_incrementOne_largeSize_Oracle.

public void test_filterNextValSql_incrementOne_largeSize_Oracle() {
    // ## Arrange ##
    SequenceCacheHandler handler = new SequenceCacheHandler();
    String sql = "select SEQ_MEMBER.nextval from dual";
    ResourceContext context = new ResourceContext();
    context.setCurrentDBDef(DBDef.Oracle);
    ResourceContext.setResourceContextOnThread(context);
    try {
        // ## Act ##
        String actual = handler.filterNextValSql(10000, 1, sql);
        // ## Assert ##
        log(actual);
        assertTrue(actual.contains("nextval"));
        assertTrue(actual.contains("select * from dual"));
        assertTrue(actual.contains(" union all"));
        assertTrue(actual.contains(" join_1"));
        assertTrue(actual.contains(" join_2"));
        assertTrue(actual.contains(" join_3"));
        assertTrue(actual.contains(" join_4"));
        assertFalse(actual.contains(" join_5"));
        assertEquals(41, DfStringUtil.splitList(actual, "select * from dual").size());
        assertTrue(actual.contains(" rownum <= 10000"));
    } finally {
        ResourceContext.clearResourceContextOnThread();
    }
}
Also used : ResourceContext(org.dbflute.bhv.core.context.ResourceContext)

Aggregations

ResourceContext (org.dbflute.bhv.core.context.ResourceContext)11 Entity (org.dbflute.Entity)1 MockBehaviorCommand (org.dbflute.mock.MockBehaviorCommand)1 MockConditionBean (org.dbflute.mock.MockConditionBean)1 MockOutsideSqlContext (org.dbflute.mock.MockOutsideSqlContext)1