Search in sources :

Example 1 with HandyDate

use of org.dbflute.helper.HandyDate in project dbflute-core by dbflute.

the class DfLoadingControlProp method analyzeDateAdjustmentMap.

protected void analyzeDateAdjustmentMap(String dataDirectory, Map<String, Object> analyzedMap, String key, Object value) {
    // ; df:originDate = 2013/03/09
    // ; $$ALL$$ = addDay($distance)
    // ; MEMBER = map:{
    // ; BIRTHDATE = addDay(6)
    // }
    final Map<String, Object> flTableMap = StringKeyMap.createAsFlexibleOrdered();
    @SuppressWarnings("unchecked") final Map<String, Object> elementTableMap = (Map<String, Object>) value;
    for (Entry<String, Object> elementTableEntry : elementTableMap.entrySet()) {
        final String tableName = elementTableEntry.getKey();
        final Object elementTableValue = elementTableEntry.getValue();
        final Object registeredTableValue;
        if (elementTableValue != null) {
            if (KEY_ORIGIN_DATE.equalsIgnoreCase(tableName)) {
                final String originExp = elementTableValue.toString();
                final HandyDate originDate;
                try {
                    originDate = new HandyDate(originExp);
                } catch (ParseDateExpressionFailureException e) {
                    throwLoadingControlOriginDateParseFailureException(dataDirectory, originExp, e);
                    // unreachable
                    return;
                }
                final java.util.Date currentDate = DBFluteSystem.currentDate();
                registeredTableValue = originDate.getDate();
                flTableMap.put(KEY_DISTANCE_YEARS, originDate.calculateCalendarDistanceYears(currentDate));
                flTableMap.put(KEY_DISTANCE_MONTHS, originDate.calculateCalendarDistanceMonths(currentDate));
                flTableMap.put(KEY_DISTANCE_DAYS, originDate.calculateCalendarDistanceDays(currentDate));
            } else if (KEY_MILLIS_COLUMN_LIST.equalsIgnoreCase(tableName)) {
                // not need filter
                registeredTableValue = elementTableValue;
            } else {
                @SuppressWarnings("unchecked") final Map<String, Object> elementColumnMap = (Map<String, Object>) elementTableValue;
                final Map<String, Object> flColumnMap = StringKeyMap.createAsFlexibleOrdered();
                flColumnMap.putAll(elementColumnMap);
                registeredTableValue = flColumnMap;
            }
        } else {
            registeredTableValue = null;
        }
        flTableMap.put(tableName, registeredTableValue);
    }
    analyzedMap.put(key, flTableMap);
}
Also used : HandyDate(org.dbflute.helper.HandyDate) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) ParseDateExpressionFailureException(org.dbflute.exception.ParseDateExpressionFailureException)

Example 2 with HandyDate

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;
}
Also used : HandyDate(org.dbflute.helper.HandyDate) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException)

Example 3 with HandyDate

use of org.dbflute.helper.HandyDate in project dbflute-core by dbflute.

the class DfSPolicyFirstDateSecretary method doDetermineFirstDate.

protected boolean doDetermineFirstDate(DfSPolicyStatement statement, String ifValue, boolean notIfValue, Predicate<Date> determiner) {
    if (notIfValue) {
        // "is not" is unsupported for firstDate
        throwSchemaPolicyCheckIllegalFirstDateException(statement, ifValue);
        // unreachable
        return false;
    }
    if (ifValue.startsWith("after:")) {
        // e.g. if firstDate is after:2018/05/03
        final String dateExp = Srl.substringFirstRear(ifValue, "after:").trim();
        if (dateExp.length() > EXAMPLE_DATE_EXPRESSION.length()) {
            // e.g. has time part
            throwSchemaPolicyCheckIllegalDateExpressionFormatException(statement, dateExp, null);
        }
        final Date targetDate;
        try {
            targetDate = new HandyDate(dateExp).getDate();
        } catch (ParseDateExpressionFailureException e) {
            throwSchemaPolicyCheckIllegalDateExpressionFormatException(statement, dateExp, e);
            // unreachable
            return false;
        }
        return determiner.test(targetDate);
    } else {
        // only "after:" supported because other patterns might not be needed
        // (and difficult logic needs because of no-existing firstDate tables)
        throwSchemaPolicyCheckIllegalFirstDateException(statement, ifValue);
        // unreachable
        return false;
    }
}
Also used : HandyDate(org.dbflute.helper.HandyDate) Date(java.util.Date) HandyDate(org.dbflute.helper.HandyDate) ParseDateExpressionFailureException(org.dbflute.exception.ParseDateExpressionFailureException)

Example 4 with HandyDate

use of org.dbflute.helper.HandyDate in project dbflute-core by dbflute.

the class DfLReverseOriginDateSynchronizer method handleOriginDateSyncLine.

protected boolean handleOriginDateSyncLine(File mapFile, StringBuilder sb, String line, StringBuilder resultSb) {
    final String keyOriginDate = DfLoadingControlProp.KEY_ORIGIN_DATE;
    boolean handled = false;
    if (!line.trim().startsWith("#") && line.contains(keyOriginDate)) {
        final String frontStr = Srl.substringFirstFront(line, keyOriginDate);
        final String rearStr = Srl.substringFirstRear(line, keyOriginDate).trim();
        if (!rearStr.startsWith("=")) {
            throwLoadingControlMapOriginDateParseFailureException(mapFile, line);
        }
        // keep space e.g. 2013/04/12 ...
        final String equalRear = Srl.substringFirstRear(rearStr, "=");
        // e.g. 2013/04/12
        final String originDate = Srl.substringFirstFront(equalRear, ";", "}").trim();
        // keep space e.g. "; ...", "}"
        final String lastRearStr = Srl.substringFirstRear(equalRear, originDate);
        if (originDate.trim().length() == 0) {
            throwLoadingControlMapOriginDateParseFailureException(mapFile, line);
        }
        // can be synchronized here
        final Date currentDate = DBFluteSystem.currentDate();
        final String newDateExp = new HandyDate(currentDate).toDisp("yyyy/MM/dd");
        sb.append(frontStr).append(keyOriginDate).append(" = ").append(newDateExp);
        sb.append(lastRearStr);
        handled = true;
        resultSb.append(originDate).append(" -> ").append(newDateExp);
    } else {
        sb.append(line);
    }
    sb.append("\n");
    return handled;
}
Also used : HandyDate(org.dbflute.helper.HandyDate) Date(java.util.Date) HandyDate(org.dbflute.helper.HandyDate)

Example 5 with HandyDate

use of org.dbflute.helper.HandyDate in project dbflute-core by dbflute.

the class DfLoadingControlProp method analyzeDateAdjustmentMap.

protected void analyzeDateAdjustmentMap(String dataDirectory, Map<String, Object> analyzedMap, String key, Object value) {
    // ; df:originDate = 2013/03/09
    // ; $$ALL$$ = addDay($distance)
    // ; MEMBER = map:{
    // ; BIRTHDATE = addDay(6)
    // }
    final Map<String, Object> flTableMap = StringKeyMap.createAsFlexibleOrdered();
    @SuppressWarnings("unchecked") final Map<String, Object> elementTableMap = (Map<String, Object>) value;
    for (Entry<String, Object> elementTableEntry : elementTableMap.entrySet()) {
        final String tableName = elementTableEntry.getKey();
        final Object elementTableValue = elementTableEntry.getValue();
        final Object registeredTableValue;
        if (elementTableValue != null) {
            if (KEY_ORIGIN_DATE.equalsIgnoreCase(tableName)) {
                final String originExp = elementTableValue.toString();
                final HandyDate originDate;
                try {
                    originDate = new HandyDate(originExp);
                } catch (ParseDateExpressionFailureException e) {
                    throwLoadingControlOriginDateParseFailureException(dataDirectory, originExp, e);
                    // unreachable
                    return;
                }
                final java.util.Date currentDate = DBFluteSystem.currentDate();
                registeredTableValue = originDate.getDate();
                flTableMap.put(KEY_DISTANCE_YEARS, originDate.calculateCalendarDistanceYears(currentDate));
                flTableMap.put(KEY_DISTANCE_MONTHS, originDate.calculateCalendarDistanceMonths(currentDate));
                flTableMap.put(KEY_DISTANCE_DAYS, originDate.calculateCalendarDistanceDays(currentDate));
            } else if (KEY_MILLIS_COLUMN_LIST.equalsIgnoreCase(tableName)) {
                // not need filter
                registeredTableValue = elementTableValue;
            } else {
                @SuppressWarnings("unchecked") final Map<String, Object> elementColumnMap = (Map<String, Object>) elementTableValue;
                final Map<String, Object> flColumnMap = StringKeyMap.createAsFlexibleOrdered();
                flColumnMap.putAll(elementColumnMap);
                registeredTableValue = flColumnMap;
            }
        } else {
            registeredTableValue = null;
        }
        flTableMap.put(tableName, registeredTableValue);
    }
    analyzedMap.put(key, flTableMap);
}
Also used : HandyDate(org.dbflute.helper.HandyDate) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) ParseDateExpressionFailureException(org.dbflute.exception.ParseDateExpressionFailureException)

Aggregations

HandyDate (org.dbflute.helper.HandyDate)17 Date (java.util.Date)5 Method (java.lang.reflect.Method)3 LocalDateTime (java.time.LocalDateTime)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ParseDateExpressionFailureException (org.dbflute.exception.ParseDateExpressionFailureException)3 ReflectionFailureException (org.dbflute.util.DfReflectionUtil.ReflectionFailureException)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 DfTableMeta (org.dbflute.logic.jdbc.metadata.info.DfTableMeta)1 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)1