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();
}
}
}
}
};
}
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);
}
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);
}
Aggregations