Search in sources :

Example 61 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class AbstractConditionQuery method xcreateManualOrderSpecifiedColumn.

protected SpecifiedColumn xcreateManualOrderSpecifiedColumn(ConditionBean dreamCruiseCB) {
    final OrderByElement orderByLastElement = xgetSqlClause().getOrderByLastElement();
    final String aliasName = orderByLastElement.getAliasName();
    final String columnName = orderByLastElement.getColumnName();
    final ColumnInfo columnInfo = orderByLastElement.getColumnInfo();
    final boolean derived = orderByLastElement.isDerivedOrderBy();
    return new SpecifiedColumn(aliasName, columnInfo, dreamCruiseCB, columnName, derived);
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) OrderByElement(org.dbflute.cbean.sqlclause.orderby.OrderByElement) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 62 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo 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 63 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class HpCalcSpecification method prepareConvOption.

protected void prepareConvOption(ColumnConversionOption option, boolean removeCalcAlias) {
    if (removeCalcAlias) {
        option.xremoveCalcAlias();
    }
    option.xjudgeDatabase(_baseCB.getSqlClause());
    if (option.xgetTargetColumnInfo() == null) {
        // might be already set (e.g. HpSpecifiedColumn's convert(), see the comment)
        // DreamCruise specifies several columns so cannot get here so checked
        final ColumnInfo columnInfo = getResolvedSpecifiedColumnInfo();
        // can be set if specified once
        option.xsetTargetColumnInfo(columnInfo);
    }
    if (_mysticBindingSnapshot != null && option.xgetMysticBindingSnapshot() == null) {
        // can be set if specified once
        option.xsetMysticBindingSnapshot(_mysticBindingSnapshot);
    }
    _baseCB.localCQ().xregisterParameterOption(option);
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 64 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class UpdateOption method xcheckSpecifiedUpdateColumnPrimaryKey.

// -----------------------------------------------------
// Update Process
// --------------
public void xcheckSpecifiedUpdateColumnPrimaryKey() {
    // checked later by process if it needs
    if (_updateColumnSpecification == null) {
        return;
    }
    assertUpdateColumnSpecifiedCB();
    final CB cb = _updateColumnSpecifiedCB;
    final String basePointAliasName = cb.getSqlClause().getBasePointAliasName();
    final DBMeta dbmeta = cb.asDBMeta();
    if (dbmeta.hasPrimaryKey()) {
        final PrimaryInfo pkInfo = dbmeta.getPrimaryInfo();
        final List<ColumnInfo> pkList = pkInfo.getPrimaryColumnList();
        for (ColumnInfo pk : pkList) {
            final String columnDbName = pk.getColumnDbName();
            if (cb.getSqlClause().hasSpecifiedSelectColumn(basePointAliasName, columnDbName)) {
                String msg = "PK columns should not be allowed to specify as update columns: " + columnDbName;
                throw new SpecifyUpdateColumnInvalidException(msg);
            }
        }
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) SpecifyUpdateColumnInvalidException(org.dbflute.exception.SpecifyUpdateColumnInvalidException) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo)

Example 65 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class UpdateOption method xacceptUpdateColumnModifiedPropertiesIfNeeds.

// -----------------------------------------------------
// Modified Properties
// -------------------
// for BatchUpdate
public void xacceptUpdateColumnModifiedPropertiesIfNeeds(List<? extends Entity> entityList) {
    // internal
    if (entityList == null) {
        throw new IllegalArgumentException("The argument 'entityList' should not be null.");
    }
    if (_updateColumnSpecification != null) {
        // already specified
        return;
    }
    if (entityList.isEmpty()) {
        // do nothing
        return;
    }
    if (xisCompatibleBatchUpdateDefaultEveryColumn()) {
        // every column for compatible
        return;
    }
    final Entity firstEntity = entityList.get(0);
    final Set<String> targetProps = xgatherUpdateColumnModifiedProperties(entityList, firstEntity);
    final DBMeta dbmeta = firstEntity.asDBMeta();
    specify(new SpecifyQuery<CB>() {

        public void specify(CB cb) {
            // you don't need to specify primary key because primary key has special handling
            for (String prop : targetProps) {
                final ColumnInfo info = dbmeta.findColumnInfo(prop);
                if (!info.isPrimary()) {
                    // except PK
                    cb.localSp().xspecifyColumn(info.getColumnDbName());
                }
            }
        }
    });
}
Also used : Entity(org.dbflute.Entity) DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Aggregations

ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)73 DBMeta (org.dbflute.dbmeta.DBMeta)27 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)14 Entity (org.dbflute.Entity)8 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)7 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)7 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)5 PrimaryInfo (org.dbflute.dbmeta.info.PrimaryInfo)5 ColumnRealName (org.dbflute.dbmeta.name.ColumnRealName)5 List (java.util.List)4 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)4 HashSet (java.util.HashSet)3 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)3 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)3 Method (java.lang.reflect.Method)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 Collection (java.util.Collection)2 Date (java.util.Date)2