use of org.dbflute.helper.HandyDate 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.helper.HandyDate in project dbflute-core by dbflute.
the class DfRelativeDateResolver method doResolveRelativeDate.
protected String doResolveRelativeDate(String tableName, String columnName, String relativeDate, Date date) {
final String calcPart = relativeDate.trim();
if (calcPart.trim().length() == 0 || date.after(LIMIT_DATE)) {
return DfTypeUtil.toString(date, RESOLVED_PATTERN);
}
final List<String> methodList = Srl.splitListTrimmed(Srl.trim(calcPart, "."), ".");
HandyDate handyDate = new HandyDate(date);
for (String methodCall : methodList) {
handyDate = invokeMethod(tableName, columnName, relativeDate, handyDate, methodCall);
}
return DfTypeUtil.toString(handyDate.getDate(), RESOLVED_PATTERN);
}
Aggregations