use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.
the class DfRelativeDateResolver method invokeMethod.
protected HandyDate invokeMethod(String tableName, String columnName, String relativeDate, HandyDate handyDate, String methodCall) {
if (!methodCall.contains("(") || !methodCall.endsWith(")")) {
throwLoadDataRelativeDateMethodArgPartNotFoundException(tableName, columnName, relativeDate);
}
final String methodName = Srl.substringFirstFront(methodCall, "(");
final String methodArgsPart = Srl.substringFirstFront(Srl.substringFirstRear(methodCall, "("), ")");
final List<String> argElementList;
if (Srl.is_NotNull_and_NotTrimmedEmpty(methodArgsPart)) {
argElementList = Srl.splitListTrimmed(methodArgsPart, ",");
} else {
argElementList = DfCollectionUtil.emptyList();
}
final List<Object> argValueList = DfCollectionUtil.newArrayList();
for (String arg : argElementList) {
if (isNumber(arg)) {
// int only supported (cannot use long)
argValueList.add(DfTypeUtil.toInteger(arg));
} else {
argValueList.add(arg);
}
}
final List<Class<?>> argTypeList = DfCollectionUtil.newArrayList();
for (Object argValue : argValueList) {
final Class<? extends Object> argType = argValue.getClass();
if (Integer.class.equals(argType)) {
// even if the argument value is int type, getClass() returns Integer type
argTypeList.add(int.class);
} else {
argTypeList.add(argType);
}
}
final Class<?>[] argTypes = argTypeList.toArray(new Class<?>[argTypeList.size()]);
final Class<HandyDate> handyDateType = HandyDate.class;
final Method method = DfReflectionUtil.getPublicMethod(handyDateType, methodName, argTypes);
if (method == null) {
throwLoadDataRelativeDateMethodNotFoundException(tableName, columnName, relativeDate, handyDateType, methodName, argTypes);
}
try {
handyDate = (HandyDate) DfReflectionUtil.invoke(method, handyDate, argValueList.toArray());
} catch (ReflectionFailureException e) {
throwLoadDataRelativeDateInvokeFailureException(tableName, columnName, relativeDate, handyDateType, methodName, e);
}
return handyDate;
}
use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.
the class AbstractConditionQuery method invokeOrderBy.
/**
* {@inheritDoc}
*/
public void invokeOrderBy(String columnFlexibleName, boolean isAsc) {
assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", columnFlexibleName);
final PropertyNameCQContainer container = xhelpExtractingPropertyNameCQContainer(columnFlexibleName);
final String flexibleName = container.getFlexibleName();
final ConditionQuery cq = container.getConditionQuery();
final String ascDesc = isAsc ? "Asc" : "Desc";
final DBMeta dbmeta = findDBMeta(cq.asTableDbName());
final String columnCapPropName = initCap(dbmeta.findColumnInfo(flexibleName).getPropertyName());
final String methodName = "addOrderBy_" + columnCapPropName + "_" + ascDesc;
final Method method = xhelpGettingCQMethod(cq, methodName, (Class<?>[]) null);
if (method == null) {
throwConditionInvokingOrderMethodNotFoundException(columnFlexibleName, isAsc, methodName);
}
try {
xhelpInvokingCQMethod(cq, method, (Object[]) null);
} catch (ReflectionFailureException e) {
throwConditionInvokingOrderReflectionFailureException(columnFlexibleName, isAsc, methodName, e);
}
}
use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException 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.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.
the class IfCommentEvaluator method processOneProperty.
protected Object processOneProperty(Object baseObject, String firstProperty, String property) {
if (baseObject == null) {
throwIfCommentNullPointerException(firstProperty);
}
final DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(baseObject.getClass());
if (beanDesc.hasPropertyDesc(property)) {
// main case
final DfPropertyDesc propertyDesc = beanDesc.getPropertyDesc(property);
try {
return propertyDesc.getValue(baseObject);
} catch (DfBeanIllegalPropertyException e) {
throwIfCommentPropertyReadFailureException(baseObject, propertyDesc.getPropertyName(), e);
// unreachable
return null;
}
}
if (property.endsWith(METHOD_SUFFIX)) {
// sub-main case
final String methodName = property.substring(0, property.length() - METHOD_SUFFIX.length());
try {
final Method method = beanDesc.getMethod(methodName);
return DfReflectionUtil.invoke(method, baseObject, (Object[]) null);
} catch (DfBeanMethodNotFoundException e) {
throwIfCommentNotFoundMethodException(baseObject, methodName);
// unreachable
return null;
} catch (ReflectionFailureException e) {
throwIfCommentMethodInvocationFailureException(baseObject, methodName, e);
// unreachable
return null;
}
}
if (MapParameterBean.class.isInstance(baseObject)) {
// used by union-query internally
// if the key does not exist, it does not process
// (different specification with Map)
final Map<?, ?> map = ((MapParameterBean<?>) baseObject).getParameterMap();
if (map.containsKey(property)) {
return map.get(property);
}
}
if (Map.class.isInstance(baseObject)) {
// if the key does not exist, treated same as a null value
final Map<?, ?> map = (Map<?, ?>) baseObject;
return map.get(property);
}
if (List.class.isInstance(baseObject)) {
if (property.startsWith("get(") && property.endsWith(")")) {
final List<?> list = (List<?>) baseObject;
final String exp = Srl.extractScopeFirst(property, "get(", ")").getContent();
try {
final Integer index = DfTypeUtil.toInteger(exp);
return list.get(index);
} catch (NumberFormatException e) {
throwIfCommentListIndexNotNumberException(list, exp, e);
// unreachable
return null;
} catch (IndexOutOfBoundsException e) {
throwIfCommentListIndexOutOfBoundsException(list, exp, e);
// unreachable
return null;
}
}
}
throwIfCommentNotFoundPropertyException(baseObject, property);
// unreachable
return null;
}
use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project lastaflute by lastaflute.
the class RelativeDateScript method invokeMethod.
protected HandyDate invokeMethod(String relativeDate, HandyDate handyDate, String methodCall) {
if (!methodCall.contains("(") || !methodCall.endsWith(")")) {
throwRelativeDateMethodArgPartNotFoundException(relativeDate);
}
final String methodName = Srl.substringFirstFront(methodCall, "(");
final String methodArgsPart = Srl.substringFirstFront(Srl.substringFirstRear(methodCall, "("), ")");
final List<String> argElementList;
if (Srl.is_NotNull_and_NotTrimmedEmpty(methodArgsPart)) {
argElementList = Srl.splitListTrimmed(methodArgsPart, ",");
} else {
argElementList = DfCollectionUtil.emptyList();
}
final List<Object> argValueList = DfCollectionUtil.newArrayList();
for (String arg : argElementList) {
if (isNumber(arg)) {
// int only supported (cannot use long)
argValueList.add(DfTypeUtil.toInteger(arg));
} else {
argValueList.add(arg);
}
}
final List<Class<?>> argTypeList = DfCollectionUtil.newArrayList();
for (Object argValue : argValueList) {
final Class<? extends Object> argType = argValue.getClass();
if (Integer.class.equals(argType)) {
// even if the argument value is int type, getClass() returns Integer type
argTypeList.add(int.class);
} else {
argTypeList.add(argType);
}
}
final Class<?>[] argTypes = argTypeList.toArray(new Class<?>[argTypeList.size()]);
final Class<HandyDate> handyDateType = HandyDate.class;
final Method method = DfReflectionUtil.getPublicMethod(handyDateType, methodName, argTypes);
if (method == null) {
throwRelativeDateMethodNotFoundException(relativeDate, handyDateType, methodName, argTypes);
}
try {
handyDate = (HandyDate) DfReflectionUtil.invoke(method, handyDate, argValueList.toArray());
} catch (ReflectionFailureException e) {
throwRelativeDateInvokeFailureException(relativeDate, handyDateType, methodName, e);
}
return handyDate;
}
Aggregations