Search in sources :

Example 66 with ColumnInfo

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

the class AbstractConditionBean method xcreateColQyClause.

// -----------------------------------------------------
// Create ColQyClause
// ------------------
protected <CB extends ConditionBean> QueryClause xcreateColQyClause(final String leftColumn, final String operand, final String rightColumn, final HpCalcSpecification<CB> rightCalcSp) {
    return new QueryClause() {

        @Override
        public String toString() {
            final String leftExp = resolveColumnExp(rightCalcSp.getLeftCalcSp(), leftColumn);
            final String rightExp = resolveColumnExp(rightCalcSp, rightColumn);
            return xbuildColQyClause(leftExp, operand, rightExp);
        }

        protected String resolveColumnExp(HpCalcSpecification<CB> calcSp, String columnExp) {
            final String resolvedExp;
            if (calcSp != null) {
                final String statement = calcSp.buildStatementToSpecifidName(columnExp);
                if (statement != null) {
                    // exists calculation
                    assertCalculationColumnType(calcSp);
                    // cipher already resolved
                    resolvedExp = statement;
                } else {
                    final ColumnInfo columnInfo = calcSp.getSpecifiedColumnInfo();
                    if (columnInfo != null) {
                        // means plain column
                        resolvedExp = decryptIfNeeds(columnInfo, columnExp);
                    } else {
                        // deriving sub-query
                        resolvedExp = columnExp;
                    }
                }
            } else {
                resolvedExp = columnExp;
            }
            return resolvedExp;
        }

        protected void assertCalculationColumnType(HpCalcSpecification<CB> calcSp) {
            if (calcSp.hasConvert()) {
                // because it may be Date type
                return;
            }
            final ColumnInfo columnInfo = calcSp.getResolvedSpecifiedColumnInfo();
            if (columnInfo != null) {
                // basically true but checked just in case
                if (!columnInfo.isObjectNativeTypeNumber()) {
                    // *simple message because other types may be supported at the future
                    String msg = "Not number column specified: " + columnInfo;
                    throw new ColumnQueryCalculationUnsupportedColumnTypeException(msg);
                }
            }
        }
    };
}
Also used : HpCalcSpecification(org.dbflute.cbean.chelper.HpCalcSpecification) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnQueryCalculationUnsupportedColumnTypeException(org.dbflute.exception.ColumnQueryCalculationUnsupportedColumnTypeException) QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause)

Example 67 with ColumnInfo

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

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

the class HpAbstractSpecification method doEveryColumn.

// ===================================================================================
// Theme Column
// ============
// -----------------------------------------------------
// Every Column
// ------------
protected void doEveryColumn() {
    if (hasSpecifiedColumn()) {
        throwSpecifyEveryColumnAlreadySpecifiedColumnException();
    }
    callQuery();
    final boolean specifiedUpdateUse = isSpecifiedUpdateUse();
    final List<ColumnInfo> columnInfoList = getColumnInfoList();
    for (ColumnInfo columnInfo : columnInfoList) {
        // primary key specification in BatchUpdate is not allowed
        if (!(specifiedUpdateUse && columnInfo.isPrimary())) {
            doColumn(columnInfo.getColumnDbName());
        }
    }
    _alreadySpecifiedEveryColumn = true;
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 69 with ColumnInfo

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

the class HpAbstractSpecification method doExceptRecordMetaColumn.

// -----------------------------------------------------
// Except Column
// -------------
protected void doExceptRecordMetaColumn() {
    if (hasSpecifiedColumn()) {
        throwSpecifyExceptColumnAlreadySpecifiedColumnException();
    }
    callQuery();
    final boolean specifiedUpdateUse = isSpecifiedUpdateUse();
    final List<ColumnInfo> columnInfoList = getColumnInfoList();
    for (ColumnInfo columnInfo : columnInfoList) {
        // this specification in BatchUpdate is non-sense but just in case
        if (!isRecordMetaColumn(columnInfo) && !(specifiedUpdateUse && columnInfo.isPrimary())) {
            doColumn(columnInfo.getColumnDbName());
        }
    }
    _alreadySpecifiedExceptColumn = true;
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 70 with ColumnInfo

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

the class MetaHandlingEntityToMapMapper method mappingToColumnValueMap.

// ===================================================================================
// Mapping
// =======
public Map<String, Object> mappingToColumnValueMap(List<ColumnInfo> columnInfoList) {
    final Map<String, Object> valueMap = newLinkedHashMapSized(columnInfoList.size());
    final Set<String> specifiedProperties = _entity.myspecifiedProperties();
    final boolean nonSpChecked = !specifiedProperties.isEmpty();
    for (ColumnInfo columnInfo : columnInfoList) {
        final String columnName = columnInfo.getColumnDbName();
        final Object value;
        if (nonSpChecked && !specifiedProperties.contains(columnInfo.getPropertyName())) {
            // non-specified column
            // to avoid non-specified check
            value = null;
        } else {
            value = columnInfo.read(_entity);
        }
        valueMap.put(columnName, value);
    }
    return valueMap;
}
Also used : 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