Search in sources :

Example 16 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc 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 17 with DfPropertyDesc

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

the class TnIdentifierAbstractGenerator method reflectIdentifier.

protected void reflectIdentifier(Object bean, Object value) {
    final DfPropertyDesc pd = _propertyType.getPropertyDesc();
    // setting by reflection here
    pd.setValue(bean, value);
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc)

Example 18 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc 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)

Example 19 with DfPropertyDesc

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

the class TnAbstractEntityHandler method updateTimestampIfNeed.

protected void updateTimestampIfNeed(Object bean, int index) {
    final List<Timestamp> newTimestampList = _newTimestampList;
    if (newTimestampList == null || newTimestampList.isEmpty()) {
        return;
    }
    final DfPropertyDesc pd = getBeanMetaData().getTimestampPropertyType().getPropertyDesc();
    final Timestamp timestamp = newTimestampList.get(index);
    final boolean localDateTime = pd.getPropertyType().isAssignableFrom(LocalDateTime.class);
    final Object realValue = localDateTime ? DfTypeUtil.toLocalDateTime(timestamp) : timestamp;
    pd.setValue(bean, realValue);
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) Timestamp(java.sql.Timestamp)

Example 20 with DfPropertyDesc

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

the class TnAbstractEntityHandler method updateVersionNoIfNeed.

protected void updateVersionNoIfNeed(Object bean, int index) {
    final List<Long> newVersionNoList = _newVersionNoList;
    if (newVersionNoList == null || newVersionNoList.isEmpty()) {
        return;
    }
    final DfPropertyDesc pd = getBeanMetaData().getVersionNoPropertyType().getPropertyDesc();
    pd.setValue(bean, newVersionNoList.get(index));
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc)

Aggregations

DfPropertyDesc (org.dbflute.helper.beans.DfPropertyDesc)22 DfBeanDesc (org.dbflute.helper.beans.DfBeanDesc)10 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 List (java.util.List)3 DfBeanIllegalPropertyException (org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException)3 MapParameterBean (org.dbflute.twowaysql.pmbean.MapParameterBean)3 TnIdentifierGenerator (org.dbflute.s2dao.identity.TnIdentifierGenerator)2 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Timestamp (java.sql.Timestamp)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Entity (org.dbflute.Entity)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 DfBeanMethodNotFoundException (org.dbflute.helper.beans.exception.DfBeanMethodNotFoundException)1 TnBeanMetaData (org.dbflute.s2dao.metadata.TnBeanMetaData)1 TnModifiedPropertySupport (org.dbflute.s2dao.metadata.TnModifiedPropertySupport)1 TnRelationPropertyType (org.dbflute.s2dao.metadata.TnRelationPropertyType)1