Search in sources :

Example 11 with DfBeanDesc

use of org.dbflute.helper.beans.DfBeanDesc in project dbflute-core by dbflute.

the class TnBeanMetaDataFactoryExtension method createModifiedPropertySupport.

// ===================================================================================
// Override for ModifiedProperty
// =============================
@Override
protected TnModifiedPropertySupport createModifiedPropertySupport() {
    return new TnModifiedPropertySupport() {

        public Set<String> getModifiedPropertyNames(Object bean) {
            if (bean instanceof Entity) {
                // all entities of DBFlute are here
                return ((Entity) bean).mymodifiedProperties();
            } else {
                // basically no way on DBFlute (S2Dao's route)
                final DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(bean.getClass());
                final String propertyName = MODIFIED_PROPERTY_PROPERTY_NAME;
                if (!beanDesc.hasPropertyDesc(propertyName)) {
                    return DfCollectionUtil.emptySet();
                } else {
                    final DfPropertyDesc propertyDesc = beanDesc.getPropertyDesc(propertyName);
                    final Object value = propertyDesc.getValue(bean);
                    if (value != null) {
                        @SuppressWarnings("unchecked") final Set<String> extractedSet = (Set<String>) value;
                        return extractedSet;
                    } else {
                        return DfCollectionUtil.emptySet();
                    }
                }
            }
        }
    };
}
Also used : Entity(org.dbflute.Entity) DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) Set(java.util.Set) TnModifiedPropertySupport(org.dbflute.s2dao.metadata.TnModifiedPropertySupport) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 12 with DfBeanDesc

use of org.dbflute.helper.beans.DfBeanDesc in project dbflute-core by dbflute.

the class AbstractConditionQuery method xhelpGettingCQMethod.

protected Method xhelpGettingCQMethod(ConditionQuery cq, String methodName, Class<?>[] argTypes) {
    final Class<? extends ConditionQuery> cqType = cq.getClass();
    final DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(cqType);
    final Method found = beanDesc.getMethodNoException(methodName, argTypes);
    if (found != null) {
        return found;
    }
    // (but cache of Class.class can be available)
    return DfReflectionUtil.getWholeMethod(cqType, methodName, argTypes);
}
Also used : Method(java.lang.reflect.Method) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 13 with DfBeanDesc

use of org.dbflute.helper.beans.DfBeanDesc in project dbflute-core by dbflute.

the class BoundValueTracer method trace.

// ===================================================================================
// Set up
// ======
public void trace(BoundValue boundValue) {
    Object value = boundValue.getFirstValue();
    if (value == null) {
        // if null, do nothing
        return;
    }
    // if value is not null, required
    Class<?> clazz = boundValue.getFirstType();
    // LikeSearchOption handling here is for OutsideSql.
    FilteringBindOption filteringBindOption = null;
    for (int pos = 1; pos < _nameList.size(); pos++) {
        if (value == null) {
            break;
        }
        final String currentName = _nameList.get(pos);
        final DfBeanDesc beanDesc = getBeanDesc(clazz);
        if (hasLikeSearchProperty(beanDesc, currentName, value)) {
            final FilteringBindOption currentOption = getFilteringBindOption(beanDesc, currentName, value);
            if (currentOption != null) {
                // if exists, override option
                filteringBindOption = currentOption;
            }
        }
        if (beanDesc.hasPropertyDesc(currentName)) {
            // main case
            final DfPropertyDesc pd = beanDesc.getPropertyDesc(currentName);
            value = getPropertyValue(clazz, value, currentName, pd);
            clazz = (value != null ? value.getClass() : pd.getPropertyType());
            continue;
        }
        if (MapParameterBean.class.isInstance(value)) {
            // used by union-query internally
            final Map<?, ?> map = ((MapParameterBean<?>) value).getParameterMap();
            // (different specification with Map)
            if (map.containsKey(currentName)) {
                value = map.get(currentName);
                clazz = (value != null ? value.getClass() : null);
                continue;
            }
        }
        if (Map.class.isInstance(value)) {
            final Map<?, ?> map = (Map<?, ?>) value;
            // if the key does not exist, treated same as a null value
            value = map.get(currentName);
            clazz = (value != null ? value.getClass() : null);
            continue;
        }
        if (List.class.isInstance(value)) {
            if (currentName.startsWith("get(") && currentName.endsWith(")")) {
                final List<?> list = (List<?>) value;
                final String exp = Srl.extractScopeFirst(currentName, "get(", ")").getContent();
                try {
                    final Integer index = DfTypeUtil.toInteger(exp);
                    value = list.get(index);
                } catch (NumberFormatException e) {
                    throwListIndexNotNumberException(exp, e);
                } catch (IndexOutOfBoundsException e) {
                    throwListIndexOutOfBoundsException(exp, e);
                }
                clazz = (value != null ? value.getClass() : null);
                continue;
            }
        }
        throwNotFoundPropertyException(clazz, currentName);
    }
    adjustLikeSearchDBWay(filteringBindOption);
    boundValue.setTargetValue(value);
    boundValue.setTargetType(clazz);
    boundValue.setFilteringBindOption(filteringBindOption);
}
Also used : ForCommentListIndexOutOfBoundsException(org.dbflute.twowaysql.exception.ForCommentListIndexOutOfBoundsException) BindVariableCommentListIndexOutOfBoundsException(org.dbflute.twowaysql.exception.BindVariableCommentListIndexOutOfBoundsException) EmbeddedVariableCommentListIndexOutOfBoundsException(org.dbflute.twowaysql.exception.EmbeddedVariableCommentListIndexOutOfBoundsException) DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) MapParameterBean(org.dbflute.twowaysql.pmbean.MapParameterBean) List(java.util.List) Map(java.util.Map) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Aggregations

DfBeanDesc (org.dbflute.helper.beans.DfBeanDesc)13 DfPropertyDesc (org.dbflute.helper.beans.DfPropertyDesc)10 ArrayList (java.util.ArrayList)3 DfBeanIllegalPropertyException (org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException)3 Method (java.lang.reflect.Method)2 List (java.util.List)2 Map (java.util.Map)2 MapParameterBean (org.dbflute.twowaysql.pmbean.MapParameterBean)2 Set (java.util.Set)1 Entity (org.dbflute.Entity)1 DfBeanMethodNotFoundException (org.dbflute.helper.beans.exception.DfBeanMethodNotFoundException)1 DfBeanDescImpl (org.dbflute.helper.beans.impl.DfBeanDescImpl)1 TnModifiedPropertySupport (org.dbflute.s2dao.metadata.TnModifiedPropertySupport)1 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)1 TnRelationPropertyType (org.dbflute.s2dao.metadata.TnRelationPropertyType)1 BindVariableCommentListIndexOutOfBoundsException (org.dbflute.twowaysql.exception.BindVariableCommentListIndexOutOfBoundsException)1 EmbeddedVariableCommentListIndexOutOfBoundsException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentListIndexOutOfBoundsException)1 ForCommentListIndexOutOfBoundsException (org.dbflute.twowaysql.exception.ForCommentListIndexOutOfBoundsException)1 IfCommentListIndexOutOfBoundsException (org.dbflute.twowaysql.exception.IfCommentListIndexOutOfBoundsException)1 ReflectionFailureException (org.dbflute.util.DfReflectionUtil.ReflectionFailureException)1