Search in sources :

Example 16 with SpecifiedColumn

use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.

the class HpCalcSpecification method getResolvedSpecifiedTableAliasName.

// -----------------------------------------------------
// Table Alias
// -----------
public String getResolvedSpecifiedTableAliasName() {
    // resolved plain or deriving sub-query
    checkSpecifiedCB();
    if (_specifedCB.xhasDreamCruiseTicket()) {
        final SpecifiedColumn ticket = _specifedCB.xshowDreamCruiseTicket();
        return ticket.getTableAliasName();
    }
    final ColumnRealName columnRealName = _specifedCB.getSqlClause().getSpecifiedColumnRealNameAsOne();
    if (columnRealName != null) {
        return columnRealName.getTableAliasName();
    }
    return _specifedCB.getSqlClause().getSpecifiedDerivingAliasNameAsOne();
}
Also used : SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 17 with SpecifiedColumn

use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.

the class HpCalcSpecification method buildCalculationExp.

/**
 * @param targetExp The expression of target column already handled cipher. (NotNull)
 * @param columnAliasMap The map of column alias. (NullAllowed)
 * @param calculation The element of calculation. (NotNull)
 * @param removeCalcAlias Does it remove alias of calculation column.
 * @return The expression of calculation statement. (NotNull)
 */
protected String buildCalculationExp(String targetExp, Map<String, String> columnAliasMap, HpCalcElement calculation, boolean removeCalcAlias) {
    final CalculationType calculationType = calculation.getCalculationType();
    if (calculationType.equals(CalculationType.CONV)) {
        // convert
        final ColumnConversionOption columnConversionOption = calculation.getColumnConversionOption();
        return columnConversionOption.filterFunction(targetExp);
    }
    // number value or number column here
    final Object calcValueExp;
    if (calculation.hasCalculationValue()) {
        // number value
        calcValueExp = calculation.getCalculationValue();
    } else if (calculation.hasCalculationColumn()) {
        // number column
        final SpecifiedColumn calculationColumn = calculation.getCalculationColumn();
        final String columnExp;
        if (removeCalcAlias) {
            // means e.g. plain update
            final String basePointAliasName = _baseCB.getSqlClause().getBasePointAliasName();
            if (!basePointAliasName.equals(calculationColumn.getTableAliasName())) {
                // may be relation column
                throwCalculationColumnRelationUnresolvedException(targetExp, calculationColumn);
            }
            columnExp = calculationColumn.toColumnSqlName().toString();
        } else {
            columnExp = calculationColumn.toColumnRealName().toString();
        }
        final Object baseExp;
        if (columnAliasMap != null) {
            // e.g. ManualOrder on union
            final String mappedAlias = columnAliasMap.get(columnExp);
            baseExp = mappedAlias != null ? mappedAlias : columnExp;
        } else {
            // e.g. ColumnQuery, UpdateOption, non-union ManualOrder, DerivedReferrer
            final ColumnInfo columnInfo = calculationColumn.getColumnInfo();
            baseExp = !calculationColumn.isDerived() ? decryptIfNeeds(columnInfo, columnExp) : columnExp;
        }
        calcValueExp = filterNestedCalculation(baseExp, calculationColumn);
    } else {
        throwCalculationElementIllegalStateException(targetExp);
        // unreachable
        return null;
    }
    return targetExp + " " + calculationType.operand() + " " + calcValueExp;
}
Also used : ColumnConversionOption(org.dbflute.cbean.coption.ColumnConversionOption) CalculationType(org.dbflute.cbean.chelper.HpCalcElement.CalculationType) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 18 with SpecifiedColumn

use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.

the class UpdateOption method doBuildStatement.

protected String doBuildStatement(String columnDbName, String aliasName) {
    final HpCalcSpecification<CB> calcSp = findStatementSpecification(columnDbName);
    if (calcSp == null) {
        return null;
    }
    final SpecifiedColumn specifiedColumn = calcSp.getResolvedSpecifiedColumn();
    if (specifiedColumn != null && specifiedColumn.hasSpecifyCalculation()) {
        throwVaryingUpdateSpecifyCalculatonUnsupportedException(columnDbName);
    }
    final String statement = calcSp.buildStatementAsSqlName(aliasName);
    if (statement == null) {
        // means non-calculation
        throwVaryingUpdateNotFoundCalculationException(columnDbName);
    }
    return statement;
}
Also used : SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 19 with SpecifiedColumn

use of org.dbflute.cbean.dream.SpecifiedColumn in project dbflute-core by dbflute.

the class AbstractConditionBean method inviteDerivedToDreamCruise.

/**
 * {@inheritDoc}
 */
public SpecifiedColumn inviteDerivedToDreamCruise(String derivedAlias) {
    if (!xisDreamCruiseShip()) {
        String msg = "This invitation is only allowed by Dream Cruise Ship: " + derivedAlias;
        throw new IllegalConditionBeanOperationException(msg);
    }
    final SqlClause portClause = xgetDreamCruiseDeparturePort().getSqlClause();
    if (!portClause.hasSpecifiedDerivingSubQuery(derivedAlias)) {
        String msg = "Not found the derived info by the argument 'derivedAlias': " + derivedAlias;
        throw new IllegalArgumentException(msg);
    }
    final ColumnInfo columnInfo = portClause.getSpecifiedDerivingColumnInfo(derivedAlias);
    if (columnInfo == null) {
        String msg = "Not found the derived column by the argument 'derivedAlias': " + derivedAlias;
        throw new IllegalArgumentException(msg);
    }
    return new SpecifiedColumn(null, columnInfo, this, derivedAlias, true);
}
Also used : IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 20 with SpecifiedColumn

use of org.dbflute.cbean.dream.SpecifiedColumn 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)

Aggregations

SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)20 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)7 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)4 ConditionBean (org.dbflute.cbean.ConditionBean)3 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)3 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)3 DBMeta (org.dbflute.dbmeta.DBMeta)2 ColumnRealName (org.dbflute.dbmeta.name.ColumnRealName)2 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)2 Method (java.lang.reflect.Method)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CalculationType (org.dbflute.cbean.chelper.HpCalcElement.CalculationType)1 ColumnConversionOption (org.dbflute.cbean.coption.ColumnConversionOption)1 LikeSearchOption (org.dbflute.cbean.coption.LikeSearchOption)1 OrderByElement (org.dbflute.cbean.sqlclause.orderby.OrderByElement)1