Search in sources :

Example 6 with DfBeanDesc

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

the class TnRelationPropertyTypeFactoryImpl method createRelationPropertyTypes.

// ===================================================================================
// Create Relation
// ===============
public TnRelationPropertyType[] createRelationPropertyTypes() {
    final List<TnRelationPropertyType> relList = new ArrayList<TnRelationPropertyType>(RELATION_SIZE_CAPACITY);
    final DfBeanDesc localBeanDesc = getLocalBeanDesc();
    final List<String> proppertyNameList = localBeanDesc.getProppertyNameList();
    for (String proppertyName : proppertyNameList) {
        final DfPropertyDesc propertyDesc = localBeanDesc.getPropertyDesc(proppertyName);
        if (_stopRelationCreation || !isRelationProperty(propertyDesc)) {
            continue;
        }
        relList.add(createRelationPropertyType(propertyDesc));
    }
    return relList.toArray(new TnRelationPropertyType[relList.size()]);
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) ArrayList(java.util.ArrayList) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 7 with DfBeanDesc

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

the class TnBeanMetaDataImpl method initialize.

// ===================================================================================
// Initialize
// ==========
public void initialize() {
    // non thread safe so this is called immediately after creation
    final DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(getBeanClass());
    setupTableName(beanDesc);
    setupProperty();
    setupPrimaryKey();
}
Also used : DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 8 with DfBeanDesc

use of org.dbflute.helper.beans.DfBeanDesc 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;
}
Also used : IfCommentListIndexOutOfBoundsException(org.dbflute.twowaysql.exception.IfCommentListIndexOutOfBoundsException) Method(java.lang.reflect.Method) DfBeanMethodNotFoundException(org.dbflute.helper.beans.exception.DfBeanMethodNotFoundException) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException) DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) DfBeanIllegalPropertyException(org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException) MapParameterBean(org.dbflute.twowaysql.pmbean.MapParameterBean) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 9 with DfBeanDesc

use of org.dbflute.helper.beans.DfBeanDesc 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);
    }
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 10 with DfBeanDesc

use of org.dbflute.helper.beans.DfBeanDesc 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;
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) 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