use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class TnAbstractEntityHandler method doRegisterUpdateWhereBindVariable.
protected void doRegisterUpdateWhereBindVariable(List<Object> varList, List<ValueType> varValueTypeList, Object bean, TnPropertyType pt) {
final DfPropertyDesc pd = pt.getPropertyDesc();
varList.add(pd.getValue(bean));
varValueTypeList.add(pt.getValueType());
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class IfCommentEvaluator method processOneProperty.
protected Object processOneProperty(Object baseObject, String firstProperty, String property) {
if (baseObject == null) {
throwIfCommentNullPointerException(firstProperty);
}
final DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(baseObject.getClass());
if (beanDesc.hasPropertyDesc(property)) {
// main case
final DfPropertyDesc propertyDesc = beanDesc.getPropertyDesc(property);
try {
return propertyDesc.getValue(baseObject);
} catch (DfBeanIllegalPropertyException e) {
throwIfCommentPropertyReadFailureException(baseObject, propertyDesc.getPropertyName(), e);
// unreachable
return null;
}
}
if (property.endsWith(METHOD_SUFFIX)) {
// sub-main case
final String methodName = property.substring(0, property.length() - METHOD_SUFFIX.length());
try {
final Method method = beanDesc.getMethod(methodName);
return DfReflectionUtil.invoke(method, baseObject, (Object[]) null);
} catch (DfBeanMethodNotFoundException e) {
throwIfCommentNotFoundMethodException(baseObject, methodName);
// unreachable
return null;
} catch (ReflectionFailureException e) {
throwIfCommentMethodInvocationFailureException(baseObject, methodName, e);
// unreachable
return null;
}
}
if (MapParameterBean.class.isInstance(baseObject)) {
// used by union-query internally
// if the key does not exist, it does not process
// (different specification with Map)
final Map<?, ?> map = ((MapParameterBean<?>) baseObject).getParameterMap();
if (map.containsKey(property)) {
return map.get(property);
}
}
if (Map.class.isInstance(baseObject)) {
// if the key does not exist, treated same as a null value
final Map<?, ?> map = (Map<?, ?>) baseObject;
return map.get(property);
}
if (List.class.isInstance(baseObject)) {
if (property.startsWith("get(") && property.endsWith(")")) {
final List<?> list = (List<?>) baseObject;
final String exp = Srl.extractScopeFirst(property, "get(", ")").getContent();
try {
final Integer index = DfTypeUtil.toInteger(exp);
return list.get(index);
} catch (NumberFormatException e) {
throwIfCommentListIndexNotNumberException(list, exp, e);
// unreachable
return null;
} catch (IndexOutOfBoundsException e) {
throwIfCommentListIndexOutOfBoundsException(list, exp, e);
// unreachable
return null;
}
}
}
throwIfCommentNotFoundPropertyException(baseObject, property);
// unreachable
return null;
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class BoundValueTracer method getFilteringBindOption.
protected FilteringBindOption getFilteringBindOption(DfBeanDesc beanDesc, String currentName, Object pmb) {
final String propertyName = buildLikeSearchPropertyName(currentName);
final FilteringBindOption option;
if (beanDesc.hasPropertyDesc(propertyName)) {
// main case
final DfPropertyDesc pb = beanDesc.getPropertyDesc(propertyName);
option = (FilteringBindOption) pb.getValue(pmb);
} else if (MapParameterBean.class.isInstance(pmb)) {
final Map<?, ?> map = ((MapParameterBean<?>) pmb).getParameterMap();
option = (FilteringBindOption) map.get(propertyName);
} else if (Map.class.isInstance(pmb)) {
option = (FilteringBindOption) ((Map<?, ?>) pmb).get(propertyName);
} else {
// no way
String msg = "Not found the like-search property: name=" + propertyName;
throw new IllegalStateException(msg);
}
// (parameter-bean checks option's existence and wrong operation)
return option;
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class AbstractBehaviorReadable method assertSpecifyDerivedReferrerEntityProperty.
protected <RESULT extends ENTITY> void assertSpecifyDerivedReferrerEntityProperty(ConditionBean cb, Class<RESULT> entityType) {
final List<String> aliasList = cb.getSqlClause().getSpecifiedDerivingAliasList();
if (aliasList.isEmpty()) {
return;
}
final DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(entityType);
for (String alias : aliasList) {
if (isEntityDerivedMappable() && alias.startsWith(DERIVED_MAPPABLE_ALIAS_PREFIX)) {
continue;
}
DfPropertyDesc pd = null;
if (beanDesc.hasPropertyDesc(alias)) {
// case insensitive
pd = beanDesc.getPropertyDesc(alias);
} else {
final String noUnsco = Srl.replace(alias, "_", "");
if (beanDesc.hasPropertyDesc(noUnsco)) {
// flexible name
pd = beanDesc.getPropertyDesc(noUnsco);
}
}
if (pd != null && pd.hasWriteMethod()) {
continue;
}
throwSpecifyDerivedReferrerEntityPropertyNotFoundException(alias, entityType);
}
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class TnProcedureMetaDataFactory method createProcedureMetaData.
// ===================================================================================
// Main
// ====
public TnProcedureMetaData createProcedureMetaData(String procedureName, Class<?> pmbType) {
final TnProcedureMetaData procedureMetaData = new TnProcedureMetaData(procedureName);
if (pmbType == null) {
return procedureMetaData;
} else {
if (!isDtoType(pmbType)) {
throw new IllegalStateException("The pmb type was Not DTO type: " + pmbType.getName());
}
}
final DfBeanDesc pmbDesc = DfBeanDescFactory.getBeanDesc(pmbType);
final List<String> proppertyNameList = pmbDesc.getProppertyNameList();
for (String propertyName : proppertyNameList) {
final DfPropertyDesc parameterDesc = pmbDesc.getPropertyDesc(propertyName);
if (parameterDesc.isReadable() && parameterDesc.isWritable()) {
registerParameterType(procedureMetaData, parameterDesc);
}
}
procedureMetaData.fix();
return procedureMetaData;
}
Aggregations