Search in sources :

Example 11 with ColumnInfo

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

the class ScalarCondition method assertScalarConditionColumnType.

protected void assertScalarConditionColumnType(String function, String derivedColumnDbName) {
    if ("sum".equalsIgnoreCase(function) || "avg".equalsIgnoreCase(function)) {
        final ColumnInfo columnInfo = _subQueryDBMeta.findColumnInfo(derivedColumnDbName);
        final Class<?> deriveColumnType = columnInfo.getObjectNativeType();
        if (!columnInfo.isObjectNativeTypeNumber()) {
            throwScalarConditionUnmatchedColumnTypeException(function, derivedColumnDbName, deriveColumnType);
        }
    }
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 12 with ColumnInfo

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

the class AbstractDBMeta method doConvertToColumnValueMap.

protected Map<String, Object> doConvertToColumnValueMap(Entity entity, boolean pkOnly) {
    final List<ColumnInfo> columnInfoList = pkOnly ? getPrimaryInfo().getPrimaryColumnList() : getColumnInfoList();
    final MetaHandlingEntityToMapMapper mapper = createMetaHandlingEntityToMapMapper(entity);
    return mapper.mappingToColumnValueMap(columnInfoList);
}
Also used : MetaHandlingEntityToMapMapper(org.dbflute.dbmeta.valuemap.MetaHandlingEntityToMapMapper) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 13 with ColumnInfo

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

the class AbstractSqlClause method getClauseQueryInsert.

// ===================================================================================
// Query Update
// ============
// -----------------------------------------------------
// Query Insert
// ------------
public String getClauseQueryInsert(Map<String, String> fixedValueQueryExpMap, SqlClause resourceSqlClause) {
    // at first, this should be called (before on-query name handling)
    // because an on-query name of mapped info are set in this process
    final String resourceViewClause = resourceSqlClause.getClause();
    if (_specifiedSelectColumnMap == null) {
        String msg = "The specified columns for query-insert are required.";
        throw new IllegalConditionBeanOperationException(msg);
    }
    final Map<String, SpecifiedColumn> elementMap = _specifiedSelectColumnMap.get(getBasePointAliasName());
    if (elementMap == null || elementMap.isEmpty()) {
        String msg = "The specified columns of inserted table for query-insert are required.";
        throw new IllegalConditionBeanOperationException(msg);
    }
    final DBMeta dbmeta = getDBMeta();
    final StringBuilder intoSb = new StringBuilder();
    final StringBuilder selectSb = new StringBuilder();
    final String resourceAlias = "dfres";
    int index = 0;
    final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
    for (ColumnInfo columnInfo : columnInfoList) {
        final String columnDbName = columnInfo.getColumnDbName();
        final SpecifiedColumn specifiedColumn = elementMap.get(columnDbName);
        final String onQueryName;
        if (specifiedColumn != null) {
            onQueryName = specifiedColumn.getValidMappedOnQueryName();
        } else if (fixedValueQueryExpMap.containsKey(columnDbName)) {
            final String fixedValueQueryExp = fixedValueQueryExpMap.get(columnDbName);
            if (fixedValueQueryExp != null) {
                onQueryName = encryptIfNeeds(columnInfo, fixedValueQueryExp);
            } else {
                // it uses null literal on query
                // because the SQL analyzer blocks null parameters
                // (the analyzer should do it for condition-bean)
                onQueryName = "null";
            }
        } else {
            continue;
        }
        if (onQueryName == null || onQueryName.trim().length() == 0) {
            // no way
            String msg = "The on-query name for query-insert is required: " + specifiedColumn;
            throw new IllegalConditionBeanOperationException(msg);
        }
        final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
        if (index > 0) {
            intoSb.append(", ");
            selectSb.append(", ");
        }
        intoSb.append(columnSqlName);
        if (specifiedColumn != null) {
            selectSb.append(resourceAlias).append(".");
        }
        selectSb.append(onQueryName);
        ++index;
    }
    final String subQueryIdentity = "queryInsertResource";
    final String subQueryBeginMark = resolveSubQueryBeginMark(subQueryIdentity);
    final String subQueryEndMark = resolveSubQueryEndMark(subQueryIdentity);
    final StringBuilder mainSb = new StringBuilder();
    mainSb.append("insert into ").append(dbmeta.getTableSqlName());
    mainSb.append(" (").append(intoSb).append(")").append(ln());
    mainSb.append("select ").append(selectSb).append(ln());
    mainSb.append("  from (").append(subQueryBeginMark).append(ln());
    mainSb.append(resourceViewClause).append(ln());
    mainSb.append("       ) ").append(resourceAlias).append(subQueryEndMark);
    final String sql = mainSb.toString();
    return processSubQueryIndent(sql);
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) DBMeta(org.dbflute.dbmeta.DBMeta) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 14 with ColumnInfo

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

the class DerivedReferrer method setupOptionAttribute.

protected void setupOptionAttribute(DerivedReferrerOption option) {
    ColumnInfo columnInfo = _subQuerySqlClause.getSpecifiedColumnInfoAsOne();
    if (columnInfo == null) {
        columnInfo = _subQuerySqlClause.getSpecifiedDerivingColumnInfoAsOne();
    }
    // basically not null (checked before)
    option.xsetTargetColumnInfo(columnInfo);
    option.xjudgeDatabase(_subQuerySqlClause);
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 15 with ColumnInfo

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

the class SqlClauseMySql method buildMatchCondition.

// [DBFlute-0.9.5]
// ===================================================================================
// Full-Text Search
// ================
/**
 * Build a condition string of match statement for full-text search. <br>
 * Bind variable is unused because the condition value should be literal in MySQL.
 * @param textColumnList The list of text column. (NotNull, NotEmpty, StringColumn, TargetTableColumn)
 * @param conditionValue The condition value embedded without binding (by MySQL restriction) but escaped. (NotNull)
 * @param modifier The modifier of full-text search. (NullAllowed: If the value is null, No modifier specified)
 * @param tableDbName The DB name of the target table. (NotNull)
 * @param aliasName The alias name of the target table. (NotNull)
 * @return The condition string of match statement. (NotNull)
 */
public String buildMatchCondition(List<ColumnInfo> textColumnList, String conditionValue, FullTextSearchModifier modifier, String tableDbName, String aliasName) {
    assertTextColumnList(textColumnList);
    assertVariousTextSearchResource(conditionValue, modifier, tableDbName, aliasName);
    final StringBuilder sb = new StringBuilder();
    int index = 0;
    for (ColumnInfo columnInfo : textColumnList) {
        if (columnInfo == null) {
            continue;
        }
        assertTextColumnTable(tableDbName, columnInfo);
        assertTextColumnType(tableDbName, columnInfo);
        final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
        if (index > 0) {
            sb.append(",");
        }
        sb.append(aliasName).append(".").append(columnSqlName);
        ++index;
    }
    sb.insert(0, "match(").append(") against ('");
    sb.append(escapeMatchConditionValue(conditionValue)).append("'");
    if (modifier != null) {
        sb.append(" ").append(modifier.code());
    }
    sb.append(")");
    return sb.toString();
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) 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