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);
}
}
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());
}
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;
}
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);
}
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);
}
Aggregations