Search in sources :

Example 6 with HpMobCaseWhenElement

use of org.dbflute.cbean.chelper.HpMobCaseWhenElement in project dbflute-core by dbflute.

the class ManualOrderOption method doBindCaseWhen.

protected HpMobCaseWhenElement doBindCaseWhen(HpManualOrderThemeListHandler handler, HpMobCaseWhenElement element) {
    final ConditionKey conditionKey = element.getConditionKey();
    final Object orderValue = resolveBoundValue(handler, element.getOrderValue(), false);
    final HpMobCaseWhenElement boundElement = createElement(conditionKey, orderValue);
    boundElement.setConnectionMode(element.getConnectionMode());
    boundElement.setThenValue(resolveBoundValue(handler, element.getThenValue(), _suppressThenBinding));
    return boundElement;
}
Also used : ConditionKey(org.dbflute.cbean.ckey.ConditionKey) HpMobCaseWhenElement(org.dbflute.cbean.chelper.HpMobCaseWhenElement)

Example 7 with HpMobCaseWhenElement

use of org.dbflute.cbean.chelper.HpMobCaseWhenElement in project dbflute-core by dbflute.

the class ManualOrderOption method throwManualOrderRequiredElseNotFoundException.

protected void throwManualOrderRequiredElseNotFoundException() {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not found 'else', it needs it (if SwitchOrder).");
    br.addItem("Advice");
    br.addElement("You should set 'else' value if you want to use SwitchOrder.");
    br.addElement("(settings for 'then' value means SwitchOrder)");
    br.addElement("For example:");
    br.addElement("  (x):");
    br.addElement("    ManualOrderOption mob = new ManualOrderOption();");
    br.addElement("    mob.when_GreaterThan(7).then(...);");
    br.addElement("    mob.when_LessThan(3).then(...);");
    br.addElement("    cb.query().addOrderBy_...().withManualOrder(mob); // *NG");
    br.addElement("  (o):");
    br.addElement("    ManualOrderOption mob = new ManualOrderOption();");
    br.addElement("    mob.when_GreaterThan(7).then(...);");
    br.addElement("    mob.when_LessThan(3).then(...);");
    br.addElement("    mob.elseEnd(3); // OK");
    br.addElement("    cb.query().addOrderBy_...().withManualOrder(mob);");
    br.addItem("CaseWhen Element");
    for (HpMobCaseWhenElement element : _caseWhenAcceptedList) {
        br.addElement(element);
    }
    final String msg = br.buildExceptionMessage();
    throw new IllegalConditionBeanOperationException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) HpMobCaseWhenElement(org.dbflute.cbean.chelper.HpMobCaseWhenElement)

Example 8 with HpMobCaseWhenElement

use of org.dbflute.cbean.chelper.HpMobCaseWhenElement in project dbflute-core by dbflute.

the class ManualOrderOption method throwManualOrderUnnecessaryElseNotFoundException.

protected void throwManualOrderUnnecessaryElseNotFoundException() {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Found unnecessary 'else', it doesn't need it (if PriorityOrder).");
    br.addItem("Advice");
    br.addElement("You should NOT set 'else' value if you want to use PriorityOrder.");
    br.addElement("(No 'then' value means PriorityOrder)");
    br.addElement("For example:");
    br.addElement("  (x):");
    br.addElement("    ManualOrderOption mob = new ManualOrderOption();");
    br.addElement("    mob.when_GreaterThan(7);");
    br.addElement("    mob.when_LessThan(3);");
    br.addElement("    mob.elseEnd(3); // *NG");
    br.addElement("  (o):");
    br.addElement("    ManualOrderOption mob = new ManualOrderOption();");
    br.addElement("    mob.when_GreaterThan(7);");
    br.addElement("    mob.when_LessThan(3);");
    br.addElement("    cb.query().addOrderBy_...().withManualOrder(mob); // OK");
    br.addItem("CaseWhen Element");
    for (HpMobCaseWhenElement element : _caseWhenAcceptedList) {
        br.addElement(element);
    }
    final String msg = br.buildExceptionMessage();
    throw new IllegalConditionBeanOperationException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) HpMobCaseWhenElement(org.dbflute.cbean.chelper.HpMobCaseWhenElement)

Example 9 with HpMobCaseWhenElement

use of org.dbflute.cbean.chelper.HpMobCaseWhenElement in project dbflute-core by dbflute.

the class ManualOrderOptionTest method test_DateFromTo.

public void test_DateFromTo() throws Exception {
    // ## Arrange ##
    Date fromDate = DfTypeUtil.toDate("1969/01/01");
    Date toDate = DfTypeUtil.toDate("1970/12/31");
    ManualOrderOption mob = new ManualOrderOption();
    // ## Act ##
    mob.when_FromTo(fromDate, toDate, op -> op.compareAsDate());
    // ## Assert ##
    List<HpMobCaseWhenElement> caseWhenAcceptedList = mob.getCaseWhenAcceptedList();
    {
        assertEquals(1, caseWhenAcceptedList.size());
        final HpMobCaseWhenElement fromElement = caseWhenAcceptedList.get(0);
        assertEquals(ConditionKey.CK_GREATER_EQUAL, fromElement.getConditionKey());
        assertNull(fromElement.getConnectionMode());
        HpMobCaseWhenElement toElement = fromElement.getConnectedElementList().get(0);
        assertEquals(ConditionKey.CK_LESS_THAN, toElement.getConditionKey());
        assertEquals(HpMobConnectionMode.AND, toElement.getConnectionMode());
        assertEquals(0, mob.getCaseWhenBoundList().size());
        String fromExp = DfTypeUtil.toString(fromElement.getOrderValue(), "yyyy/MM/dd");
        String toExp = DfTypeUtil.toString(toElement.getOrderValue(), "yyyy/MM/dd");
        assertEquals("1969/01/01", fromExp);
        assertEquals("1971/01/01", toExp);
    }
    // ## Act ##
    mob.bind(new HpManualOrderThemeListHandler() {

        int index = 0;

        public String register(String themeKey, Object orderValue) {
            ++index;
            return "foo" + index;
        }
    });
    // ## Assert ##
    List<HpMobCaseWhenElement> caseWhenBoundList = mob.getCaseWhenBoundList();
    {
        assertNotSame(0, caseWhenBoundList.size());
        assertEquals(1, caseWhenBoundList.size());
        final HpMobCaseWhenElement fromElement = caseWhenBoundList.get(0);
        assertEquals(ConditionKey.CK_GREATER_EQUAL, fromElement.getConditionKey());
        assertNull(fromElement.getConnectionMode());
        HpMobCaseWhenElement toElement = fromElement.getConnectedElementList().get(0);
        assertEquals(ConditionKey.CK_LESS_THAN, toElement.getConditionKey());
        assertEquals(HpMobConnectionMode.AND, toElement.getConnectionMode());
    }
}
Also used : HpMobCaseWhenElement(org.dbflute.cbean.chelper.HpMobCaseWhenElement) HpManualOrderThemeListHandler(org.dbflute.cbean.chelper.HpManualOrderThemeListHandler) Date(java.util.Date)

Aggregations

HpMobCaseWhenElement (org.dbflute.cbean.chelper.HpMobCaseWhenElement)9 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)3 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)2 Date (java.util.Date)1 ConditionBean (org.dbflute.cbean.ConditionBean)1 HpManualOrderThemeListHandler (org.dbflute.cbean.chelper.HpManualOrderThemeListHandler)1 HpMobConnectionMode (org.dbflute.cbean.chelper.HpMobConnectionMode)1 ConditionKey (org.dbflute.cbean.ckey.ConditionKey)1