Search in sources :

Example 6 with ReflectionFailureException

use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.

the class AbstractConditionBean method invokeSpecifyColumn.

/**
 * {@inheritDoc}
 */
public SpecifiedColumn invokeSpecifyColumn(String columnPropertyPath) {
    final String delimiter = ".";
    Object currentObj = localSp();
    String remainder = columnPropertyPath;
    boolean last = false;
    while (true) {
        final int deimiterIndex = remainder.indexOf(delimiter);
        final String propertyName;
        if (deimiterIndex < 0) {
            // hard to get relation DB meta so plain name
            propertyName = remainder;
            last = true;
        } else {
            propertyName = remainder.substring(0, deimiterIndex);
            remainder = remainder.substring(deimiterIndex + delimiter.length(), remainder.length());
        }
        final Class<?> targetType = currentObj.getClass();
        final String methodName = (last ? "column" : "specify") + initCap(propertyName);
        final Method method = xhelpGettingCBChainMethod(targetType, methodName, (Class<?>[]) null);
        if (method == null) {
            String msg = "Not found the method for SpecifyColumn:";
            msg = msg + " columnPropertyPath=" + columnPropertyPath + " targetType=" + targetType + " methodName=" + methodName;
            throw new ConditionInvokingFailureException(msg);
        }
        try {
            currentObj = DfReflectionUtil.invoke(method, currentObj, (Object[]) null);
        } catch (ReflectionFailureException e) {
            String msg = "Failed to invoke the method:";
            msg = msg + " columnPropertyPath=" + columnPropertyPath + " targetType=" + targetType + " methodName=" + methodName;
            throw new ConditionInvokingFailureException(msg, e);
        }
        if (last) {
            break;
        }
    }
    return (SpecifiedColumn) currentObj;
}
Also used : ConditionInvokingFailureException(org.dbflute.exception.ConditionInvokingFailureException) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 7 with ReflectionFailureException

use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.

the class AbstractConditionBean method invokeSetupSelect.

// ===================================================================================
// Reflection Invoking
// ===================
/**
 * {@inheritDoc}
 */
public void invokeSetupSelect(String foreignPropertyNamePath) {
    assertStringNotNullAndNotTrimmedEmpty("foreignPropertyNamePath", foreignPropertyNamePath);
    final String delimiter = ".";
    Object currentObj = this;
    String remainder = foreignPropertyNamePath;
    int count = 0;
    boolean last = false;
    while (true) {
        final int deimiterIndex = remainder.indexOf(delimiter);
        final String propertyName;
        if (deimiterIndex < 0) {
            propertyName = remainder;
            last = true;
        } else {
            propertyName = remainder.substring(0, deimiterIndex);
            remainder = remainder.substring(deimiterIndex + delimiter.length(), remainder.length());
        }
        final Class<?> targetType = currentObj.getClass();
        final String methodName = (count == 0 ? "setupSelect_" : "with") + initCap(propertyName);
        final Method method = xhelpGettingCBChainMethod(targetType, methodName, (Class<?>[]) null);
        if (method == null) {
            String msg = "Not found the method for setupSelect:";
            msg = msg + " foreignPropertyNamePath=" + foreignPropertyNamePath;
            msg = msg + " targetType=" + targetType + " methodName=" + methodName;
            throw new ConditionInvokingFailureException(msg);
        }
        try {
            currentObj = DfReflectionUtil.invoke(method, currentObj, (Object[]) null);
        } catch (ReflectionFailureException e) {
            String msg = "Failed to invoke the method:";
            msg = msg + " foreignPropertyNamePath=" + foreignPropertyNamePath;
            msg = msg + " targetType=" + targetType + " methodName=" + methodName;
            throw new ConditionInvokingFailureException(msg, e);
        }
        ++count;
        if (last) {
            break;
        }
    }
}
Also used : ConditionInvokingFailureException(org.dbflute.exception.ConditionInvokingFailureException) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException)

Example 8 with ReflectionFailureException

use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.

the class AbstractConditionQuery method doInvokeHasForeignCQ.

protected boolean doInvokeHasForeignCQ(ConditionQuery cq, String foreignPropertyName) {
    assertStringNotNullAndNotTrimmedEmpty("foreignPropertyName", foreignPropertyName);
    final String methodName = "hasConditionQuery" + initCap(foreignPropertyName);
    final Method method = xhelpGettingCQMethod(cq, methodName, (Class<?>[]) null);
    if (method == null) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("Not found the method for determining a foreign condition query.");
        br.addItem("Table");
        br.addElement(cq.asTableDbName());
        br.addItem("foreignPropertyName");
        br.addElement(foreignPropertyName);
        br.addItem("methodName");
        br.addElement(methodName);
        br.addItem("ConditionQuery");
        br.addElement(DfTypeUtil.toClassTitle(cq));
        final String msg = br.buildExceptionMessage();
        throw new ConditionInvokingFailureException(msg);
    }
    try {
        return (Boolean) xhelpInvokingCQMethod(cq, method, (Object[]) null);
    } catch (ReflectionFailureException e) {
        String msg = "Failed to invoke the method for determining a condition(query):";
        msg = msg + " foreignPropertyName=" + foreignPropertyName;
        msg = msg + " methodName=" + methodName + " table=" + asTableDbName();
        throw new ConditionInvokingFailureException(msg, e);
    }
}
Also used : ConditionInvokingFailureException(org.dbflute.exception.ConditionInvokingFailureException) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException)

Example 9 with ReflectionFailureException

use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.

the class AbstractConditionQuery method invokeValue.

// ===================================================================================
// Reflection Invoking
// ===================
/**
 * {@inheritDoc}
 */
public ConditionValue invokeValue(String columnFlexibleName) {
    assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", columnFlexibleName);
    final DBMeta dbmeta = xgetLocalDBMeta();
    final String columnCapPropName = initCap(dbmeta.findColumnInfo(columnFlexibleName).getPropertyName());
    final String methodName = "xdfget" + columnCapPropName;
    final Method method = xhelpGettingCQMethod(this, methodName, (Class<?>[]) null);
    if (method == null) {
        throwConditionInvokingGetMethodNotFoundException(columnFlexibleName, methodName);
        // unreachable
        return null;
    }
    try {
        return (ConditionValue) xhelpInvokingCQMethod(this, method, (Object[]) null);
    } catch (ReflectionFailureException e) {
        throwConditionInvokingGetReflectionFailureException(columnFlexibleName, methodName, e);
        // unreachable
        return null;
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ConditionValue(org.dbflute.cbean.cvalue.ConditionValue) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException)

Example 10 with ReflectionFailureException

use of org.dbflute.util.DfReflectionUtil.ReflectionFailureException in project dbflute-core by dbflute.

the class AbstractConditionQuery method doInvokeForeignCQ.

protected ConditionQuery doInvokeForeignCQ(ConditionQuery cq, String foreignPropertyName) {
    assertStringNotNullAndNotTrimmedEmpty("foreignPropertyName", foreignPropertyName);
    final String methodName = "query" + initCap(foreignPropertyName);
    final Method method = xhelpGettingCQMethod(cq, methodName, (Class<?>[]) null);
    if (method == null) {
        throwConditionInvokingForeignQueryMethodNotFoundException(cq, foreignPropertyName, methodName);
        // unreachable
        return null;
    }
    try {
        return (ConditionQuery) xhelpInvokingCQMethod(cq, method, (Object[]) null);
    } catch (ReflectionFailureException e) {
        throwConditionInvokingForeignQueryReflectionFailureException(cq, foreignPropertyName, methodName, e);
        // unreachable
        return null;
    }
}
Also used : Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException)

Aggregations

Method (java.lang.reflect.Method)10 ReflectionFailureException (org.dbflute.util.DfReflectionUtil.ReflectionFailureException)10 DBMeta (org.dbflute.dbmeta.DBMeta)3 ConditionInvokingFailureException (org.dbflute.exception.ConditionInvokingFailureException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HandyDate (org.dbflute.helper.HandyDate)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Map (java.util.Map)1 ConditionValue (org.dbflute.cbean.cvalue.ConditionValue)1 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)1 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)1 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)1 DfBeanDesc (org.dbflute.helper.beans.DfBeanDesc)1 DfPropertyDesc (org.dbflute.helper.beans.DfPropertyDesc)1 DfBeanIllegalPropertyException (org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException)1 DfBeanMethodNotFoundException (org.dbflute.helper.beans.exception.DfBeanMethodNotFoundException)1