Search in sources :

Example 1 with ConditionKeyPrepareResult

use of org.dbflute.cbean.ckey.ConditionKeyPrepareResult in project dbflute-core by dbflute.

the class AbstractConditionQuery method regROO.

// ===================================================================================
// RangeOf Query
// =============
protected void regROO(Number minNumber, Number maxNumber, ConditionValue cvalue, String columnDbName, RangeOfOption option) {
    assertObjectNotNull("option(RangeOfOption)", option);
    if (option.hasCalculationRange()) {
        final ConditionBean dreamCruiseCB = xgetBaseCB().xcreateDreamCruiseCB();
        option.xinitCalculationRange(xgetBaseCB(), dreamCruiseCB);
    }
    // this RangeOf process is very similar to FromTo process
    final ConditionKey minKey = option.getMinNumberConditionKey();
    final ConditionKeyPrepareResult minResult = prepareQueryNoCheck(minKey, minNumber, cvalue, columnDbName);
    final ConditionKey maxKey = option.getMaxNumberConditionKey();
    final ConditionKeyPrepareResult maxResult = prepareQueryNoCheck(maxKey, maxNumber, cvalue, columnDbName);
    final boolean needsAndPart = isOrScopeQueryDirectlyUnder() && minResult.newClause() && maxResult.newClause();
    if (needsAndPart) {
        xgetSqlClause().beginOrScopeQueryAndPart();
    }
    try {
        if (minResult.newClause()) {
            setupConditionValueAndRegisterWhereClause(minKey, minNumber, cvalue, columnDbName, option);
        }
        if (maxResult.newClause()) {
            setupConditionValueAndRegisterWhereClause(maxKey, maxNumber, cvalue, columnDbName, option);
        }
        if (minResult.invalid() && maxResult.invalid()) {
            xhandleRangeOfBothSideInvalidQuery(minNumber, maxNumber, columnDbName, option, minKey, maxKey);
        } else if (minResult.invalid() || maxResult.invalid()) {
            xhandleRangeOfOneSideInvalidQuery(minNumber, maxNumber, columnDbName, option, minKey, maxKey);
        }
    } finally {
        if (needsAndPart) {
            xgetSqlClause().endOrScopeQueryAndPart();
        }
    }
}
Also used : ConditionKeyPrepareResult(org.dbflute.cbean.ckey.ConditionKeyPrepareResult) ConditionKey(org.dbflute.cbean.ckey.ConditionKey)

Example 2 with ConditionKeyPrepareResult

use of org.dbflute.cbean.ckey.ConditionKeyPrepareResult in project dbflute-core by dbflute.

the class AbstractConditionQuery method regFTQ.

// ===================================================================================
// FromTo Query
// ============
protected void regFTQ(Date fromDate, Date toDate, ConditionValue cvalue, String columnDbName, FromToOption option) {
    assertObjectNotNull("option(FromToOption)", option);
    // for fixed option
    filterFromToOption(columnDbName, option);
    // this FromTo process is very similar to RangeOf process
    final Date filteredFromDate = option.filterFromDate(fromDate);
    final ConditionKey fromKey = option.getFromDateConditionKey();
    final ConditionKeyPrepareResult fromResult = prepareQueryNoCheck(fromKey, filteredFromDate, cvalue, columnDbName);
    final Date filteredToDate = option.filterToDate(toDate);
    final ConditionKey toKey = option.getToDateConditionKey();
    final ConditionKeyPrepareResult toResult = prepareQueryNoCheck(toKey, filteredToDate, cvalue, columnDbName);
    final boolean needsAndPart = isOrScopeQueryDirectlyUnder() && fromResult.newClause() && toResult.newClause();
    if (needsAndPart) {
        xgetSqlClause().beginOrScopeQueryAndPart();
    }
    try {
        if (fromResult.newClause()) {
            final Object registered = filterFromToRegisteredDate(option, filteredFromDate, columnDbName);
            setupConditionValueAndRegisterWhereClause(fromKey, registered, cvalue, columnDbName);
        }
        if (toResult.newClause()) {
            final Object registered = filterFromToRegisteredDate(option, filteredToDate, columnDbName);
            setupConditionValueAndRegisterWhereClause(toKey, registered, cvalue, columnDbName);
        }
        if (fromResult.invalid() && toResult.invalid()) {
            xhandleFromToBothSideInvalidQuery(fromDate, toDate, columnDbName, option, fromKey, toKey);
        } else if (fromResult.invalid() || toResult.invalid()) {
            xhandleFromToOneSideInvalidQuery(fromDate, toDate, columnDbName, option, fromKey, toKey);
        }
    } finally {
        if (needsAndPart) {
            xgetSqlClause().endOrScopeQueryAndPart();
        }
    }
}
Also used : ConditionKeyPrepareResult(org.dbflute.cbean.ckey.ConditionKeyPrepareResult) ConditionKey(org.dbflute.cbean.ckey.ConditionKey) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

ConditionKey (org.dbflute.cbean.ckey.ConditionKey)2 ConditionKeyPrepareResult (org.dbflute.cbean.ckey.ConditionKeyPrepareResult)2 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1