Search in sources :

Example 1 with IllegalConditionBeanOperationException

use of org.dbflute.exception.IllegalConditionBeanOperationException in project dbflute-core by dbflute.

the class AbstractConditionQuery method doInvokeQuery.

protected void doInvokeQuery(String colName, String ckey, Object value, ConditionOption option) {
    assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", colName);
    assertStringNotNullAndNotTrimmedEmpty("conditionKeyName", ckey);
    final boolean noArg = Srl.equalsIgnoreCase(ckey, "IsNull", "IsNotNull", "IsNullOrEmpty", "EmptyString");
    if (!noArg && (value == null || "".equals(value))) {
        if (xgetSqlClause().isNullOrEmptyQueryChecked()) {
            // as default
            String msg = "The conditionValue is required but null or empty: column=" + colName + " value=" + value;
            throw new IllegalConditionBeanOperationException(msg);
        } else {
            // e.g. when cb.ignoreNullOrEmptyQuery()
            return;
        }
    }
    final PropertyNameCQContainer container = xhelpExtractingPropertyNameCQContainer(colName);
    final String flexibleName = container.getFlexibleName();
    final ConditionQuery cq = container.getConditionQuery();
    final DBMeta dbmeta = findDBMeta(cq.asTableDbName());
    final ColumnInfo columnInfo;
    try {
        columnInfo = dbmeta.findColumnInfo(flexibleName);
    } catch (RuntimeException e) {
        throwConditionInvokingColumnFindFailureException(colName, ckey, value, option, e);
        // unreachable (to avoid compile error)
        return;
    }
    final String columnCapPropName = initCap(columnInfo.getPropertyName());
    final boolean rangeOf = Srl.equalsIgnoreCase(ckey, "RangeOf");
    final boolean fromTo = Srl.equalsIgnoreCase(ckey, "FromTo", "DateFromTo");
    final boolean inScope = Srl.equalsIgnoreCase(ckey, "InScope");
    if (!noArg) {
        try {
            // convert type
            value = columnInfo.convertToObjectNativeType(value);
        } catch (RuntimeException e) {
            throwConditionInvokingValueConvertFailureException(colName, ckey, value, option, e);
        }
    }
    final String methodName = xbuildQuerySetMethodName(ckey, columnCapPropName);
    final List<Class<?>> typeList = newArrayListSized(4);
    final Class<?> propertyType = columnInfo.getObjectNativeType();
    if (fromTo) {
        if (LocalDate.class.isAssignableFrom(propertyType)) {
            // #date_parade
            typeList.add(propertyType);
            typeList.add(propertyType);
        } else if (LocalDateTime.class.isAssignableFrom(propertyType)) {
            typeList.add(propertyType);
            typeList.add(propertyType);
        } else {
            // fixedly util.Date
            typeList.add(Date.class);
            typeList.add(Date.class);
        }
    } else if (rangeOf) {
        typeList.add(propertyType);
        typeList.add(propertyType);
    } else {
        if (!noArg) {
            final Class<?> instanceType = value.getClass();
            if (inScope && Collection.class.isAssignableFrom(instanceType)) {
                // double check just in case
                // inScope's argument is fixed type
                typeList.add(Collection.class);
            } else {
                typeList.add(instanceType);
            }
        }
    }
    if (option != null) {
        typeList.add(option.getClass());
    }
    final List<Class<?>> filteredTypeList = newArrayListSized(typeList.size());
    for (Class<?> parameterType : typeList) {
        filteredTypeList.add(xfilterInvokeQueryParameterType(colName, ckey, parameterType));
    }
    final Class<?>[] parameterTypes = filteredTypeList.toArray(new Class<?>[filteredTypeList.size()]);
    final Method method = xhelpGettingCQMethod(cq, methodName, parameterTypes);
    if (method == null) {
        throwConditionInvokingSetMethodNotFoundException(colName, ckey, value, option, methodName, parameterTypes);
    }
    try {
        final List<Object> argList = newArrayList();
        if (fromTo || rangeOf) {
            if (!(value instanceof List<?>)) {
                // check type
                throwConditionInvokingDateFromToValueInvalidException(colName, ckey, value, option, methodName, parameterTypes);
            }
            argList.addAll((List<?>) value);
        } else {
            if (!noArg) {
                argList.add(value);
            }
        }
        if (option != null) {
            argList.add(option);
        }
        final List<Object> filteredArgList = newArrayListSized(argList.size());
        for (Object arg : argList) {
            filteredArgList.add(xfilterInvokeQueryParameterValue(colName, ckey, arg));
        }
        xhelpInvokingCQMethod(cq, method, filteredArgList.toArray());
    } catch (ReflectionFailureException e) {
        throwConditionInvokingSetReflectionFailureException(colName, ckey, value, option, methodName, parameterTypes, e);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException) Date(java.util.Date) LocalDate(java.time.LocalDate) DBMeta(org.dbflute.dbmeta.DBMeta) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with IllegalConditionBeanOperationException

use of org.dbflute.exception.IllegalConditionBeanOperationException in project dbflute-core by dbflute.

the class AbstractConditionQuery method innerJoin.

// ===================================================================================
// Inner Join
// ==========
/**
 * Change the join type for this relation to inner join. <br>
 * This method is for PERFORMANCE TUNING basically.
 */
public void innerJoin() {
    if (isBaseQuery()) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("The method 'innerJoin()' should be called for a relation query.");
        br.addItem("Advice");
        br.addElement("Please confirm your program.");
        br.addElement("For example:");
        br.addElement("  (x) - cb.query().innerJoin();");
        br.addElement("  (o) - cb.query().queryMemberStatus().innerJoin();");
        br.addItem("Base Table");
        br.addElement(asTableDbName());
        final String msg = br.buildExceptionMessage();
        throw new IllegalConditionBeanOperationException(msg);
    }
    xgetSqlClause().changeToInnerJoin(xgetAliasName());
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException)

Example 3 with IllegalConditionBeanOperationException

use of org.dbflute.exception.IllegalConditionBeanOperationException in project dbflute-core by dbflute.

the class AbstractConditionBean method enablePagingSelectAndQuerySplit.

/**
 * Enable that it splits the SQL execute select and query of paging. <br>
 * You should confirm that the executed SQL on log matches with your expectation. <br>
 * It is very difficult internal logic so it also has simplistic logic. Be careful!
 * <pre>
 * Cannot use this:
 *  o if no PK or compound PK table (exception is thrown)
 *  o if SpecifiedDerivedOrderBy or not Paging (but no exception)
 *
 * Automatically Changed:
 *  o disable PagingCountLater (to suppress rows calculation)
 * </pre>
 * @deprecated This is rare handling for performance tuning so don't use this easily.
 */
public void enablePagingSelectAndQuerySplit() {
    assertOptionThatBadTiming("enablePagingSelectAndQuerySplit()");
    final DBMeta dbmeta = asDBMeta();
    if (!dbmeta.hasPrimaryKey() || dbmeta.getPrimaryInfo().isCompoundKey()) {
        String msg = "The PagingSelectAndQuerySplit needs only-one column key table: " + asTableDbName();
        throw new IllegalConditionBeanOperationException(msg);
    }
    // MySQL's rows calculation is not fit with this function
    // e.g.
    // paging : select PK only by business condition with sql_calc_found_rows
    // paging : select business data by PK without no sql_calc_found_rows
    // count  : select found_rows() -> returns latest count, why?
    disablePagingCountLater();
    _pagingSelectAndQuerySplit = true;
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException)

Example 4 with IllegalConditionBeanOperationException

use of org.dbflute.exception.IllegalConditionBeanOperationException in project dbflute-core by dbflute.

the class HpCalcSpecification method buildStatementAsSqlName.

// ===================================================================================
// Statement
// =========
/**
 * {@inheritDoc}
 */
public String buildStatementAsSqlName(String aliasName) {
    // e.g. VaryingUpdate, VaryingQueryUdpate
    final ColumnSqlName columnSqlName = getResolvedSpecifiedColumnSqlName();
    if (columnSqlName == null) {
        // very rare case, e.g. DreamCruise
        String msg = "Specified column is not found or too many columns are specified: " + aliasName;
        throw new IllegalConditionBeanOperationException(msg);
    }
    final String columnExp = (aliasName != null ? aliasName : "") + columnSqlName.toString();
    final boolean removeCalcAlias = aliasName == null;
    return doBuildStatement(columnExp, null, removeCalcAlias);
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException)

Example 5 with IllegalConditionBeanOperationException

use of org.dbflute.exception.IllegalConditionBeanOperationException in project dbflute-core by dbflute.

the class HpQDRParameter method throwRangeOfMaxNumberOnlyNullNotAllowedException.

protected void throwRangeOfMaxNumberOnlyNullNotAllowedException(Number minNumber, RangeOfOption option) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("The max-mumber of range-of for (Query)DerivedReferrer were null.");
    br.addItem("Advice");
    br.addElement("Basically it cannot allow max-mumber to be null.");
    br.addElement("If you need to specify null, use allowOneSide() option.");
    br.addItem("minNumber");
    br.addElement(minNumber);
    br.addItem("RangeOfOption");
    br.addElement(option);
    final String msg = br.buildExceptionMessage();
    throw new IllegalConditionBeanOperationException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException)

Aggregations

IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)36 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)24 HpMobCaseWhenElement (org.dbflute.cbean.chelper.HpMobCaseWhenElement)3 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)3 DBMeta (org.dbflute.dbmeta.DBMeta)3 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)3 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)3 ArrayList (java.util.ArrayList)2 Method (java.lang.reflect.Method)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Entity (org.dbflute.Entity)1 HpCBPurpose (org.dbflute.cbean.chelper.HpCBPurpose)1 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)1 OrderByClause (org.dbflute.cbean.sqlclause.orderby.OrderByClause)1 OrderByElement (org.dbflute.cbean.sqlclause.orderby.OrderByElement)1 ColumnRealName (org.dbflute.dbmeta.name.ColumnRealName)1