Search in sources :

Example 1 with SelectedRelationColumn

use of org.dbflute.cbean.sqlclause.select.SelectedRelationColumn in project dbflute-core by dbflute.

the class HpSpecifyColumnRequiredChecker method checkSpecifyColumnRequiredIfNeeds.

public void checkSpecifyColumnRequiredIfNeeds(ConditionBean cb, Consumer<Set<String>> thrower) {
    // cannot embed this to SQL clause because of too complex
    // so simple implementation like this:
    final SqlClause sqlClause = cb.getSqlClause();
    final String basePointAliasName = sqlClause.getBasePointAliasName();
    final Set<String> nonSpecifiedAliasSet = new LinkedHashSet<>();
    if (!sqlClause.hasSpecifiedSelectColumn(basePointAliasName)) {
        // local table without SpecifyColumn
        nonSpecifiedAliasSet.add(cb.asDBMeta().getTableDispName() + " (" + basePointAliasName + ")");
    }
    for (Entry<String, Map<String, SelectedRelationColumn>> entry : sqlClause.getSelectedRelationColumnMap().entrySet()) {
        final String tableAliasName = entry.getKey();
        if (!sqlClause.hasSpecifiedSelectColumn(tableAliasName)) {
            // relation table without SpecifyColumn
            final Collection<SelectedRelationColumn> values = entry.getValue().values();
            final String dispName;
            if (!values.isEmpty()) {
                final SelectedRelationColumn firstColumn = values.iterator().next();
                dispName = sqlClause.translateSelectedRelationPathToPropName(firstColumn.getRelationNoSuffix());
            } else {
                // no way, just in case
                dispName = "*no name";
            }
            nonSpecifiedAliasSet.add(dispName + " (" + tableAliasName + ")");
        }
    }
    if (!nonSpecifiedAliasSet.isEmpty()) {
        thrower.accept(nonSpecifiedAliasSet);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) SelectedRelationColumn(org.dbflute.cbean.sqlclause.select.SelectedRelationColumn) Map(java.util.Map)

Example 2 with SelectedRelationColumn

use of org.dbflute.cbean.sqlclause.select.SelectedRelationColumn in project dbflute-core by dbflute.

the class AbstractSqlClause method createSelectedSelectColumnInfo.

protected Map<String, SelectedRelationColumn> createSelectedSelectColumnInfo(String foreignTableAliasName, String localTableDbName, String foreignPropertyName, String localRelationPath) {
    final DBMeta dbmeta = findDBMeta(localTableDbName);
    final ForeignInfo foreignInfo = dbmeta.findForeignInfo(foreignPropertyName);
    final int relationNo = foreignInfo.getRelationNo();
    String nextRelationPath = RELATION_PATH_DELIMITER + relationNo;
    if (localRelationPath != null) {
        nextRelationPath = localRelationPath + nextRelationPath;
    }
    final Map<String, SelectedRelationColumn> resultMap = new LinkedHashMap<String, SelectedRelationColumn>();
    final DBMeta foreignDBMeta = foreignInfo.getForeignDBMeta();
    final List<ColumnInfo> columnInfoList = foreignDBMeta.getColumnInfoList();
    for (ColumnInfo columnInfo : columnInfoList) {
        final String columnDbName = columnInfo.getColumnDbName();
        final SelectedRelationColumn selectColumnInfo = new SelectedRelationColumn();
        selectColumnInfo.setTableAliasName(foreignTableAliasName);
        selectColumnInfo.setColumnInfo(columnInfo);
        selectColumnInfo.setRelationNoSuffix(nextRelationPath);
        resultMap.put(columnDbName, selectColumnInfo);
    }
    return resultMap;
}
Also used : ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) DBMeta(org.dbflute.dbmeta.DBMeta) SelectedRelationColumn(org.dbflute.cbean.sqlclause.select.SelectedRelationColumn) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with SelectedRelationColumn

use of org.dbflute.cbean.sqlclause.select.SelectedRelationColumn in project dbflute-core by dbflute.

the class AbstractSqlClause method processSelectClauseRelation.

protected int processSelectClauseRelation(StringBuilder sb, int selectIndex) {
    if (_pkOnlySelectForcedlyEnabled) {
        return selectIndex;
    }
    for (Entry<String, Map<String, SelectedRelationColumn>> entry : getSelectedRelationColumnMap().entrySet()) {
        final String tableAliasName = entry.getKey();
        final Map<String, SelectedRelationColumn> relationColumnMap = entry.getValue();
        Map<String, SpecifiedColumn> foreginSpecifiedMap = null;
        if (_specifiedSelectColumnMap != null) {
            foreginSpecifiedMap = _specifiedSelectColumnMap.get(tableAliasName);
        }
        final boolean validSpecifiedForeign = foreginSpecifiedMap != null && !foreginSpecifiedMap.isEmpty();
        boolean finishedForeignIndent = false;
        for (SelectedRelationColumn selectColumnInfo : relationColumnMap.values()) {
            final ColumnInfo columnInfo = selectColumnInfo.getColumnInfo();
            final String columnDbName = columnInfo.getColumnDbName();
            if (validSpecifiedForeign && !foreginSpecifiedMap.containsKey(columnDbName)) {
                continue;
            }
            if (canBeNullObjectSpecifiedColumn(columnInfo)) {
                registerColumnNullObject(tableAliasName, columnInfo);
                continue;
            }
            final String realColumnName = selectColumnInfo.buildRealColumnSqlName();
            final String columnAliasName = selectColumnInfo.buildColumnAliasName();
            final String relationNoSuffix = selectColumnInfo.getRelationNoSuffix();
            final String onQueryName;
            ++selectIndex;
            if (_useSelectIndex) {
                final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
                onQueryName = buildSelectIndexAlias(columnSqlName, columnAliasName, selectIndex, relationNoSuffix);
                registerSelectIndex(relationNoSuffix, columnAliasName, onQueryName, selectIndex);
            } else {
                onQueryName = columnAliasName;
            }
            if (!finishedForeignIndent) {
                sb.append(ln()).append("     ");
                finishedForeignIndent = true;
            }
            sb.append(", ");
            sb.append(decryptSelectColumnIfNeeds(columnInfo, realColumnName)).append(" as ").append(onQueryName);
            getSelectClauseRealColumnAliasMap().put(realColumnName, onQueryName);
            if (validSpecifiedForeign && foreginSpecifiedMap.containsKey(columnDbName)) {
                final SpecifiedColumn specifiedColumn = foreginSpecifiedMap.get(columnDbName);
                // basically for queryInsert()
                specifiedColumn.setOnQueryName(onQueryName);
            }
        }
    }
    return selectIndex;
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) SelectedRelationColumn(org.dbflute.cbean.sqlclause.select.SelectedRelationColumn) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StringKeyMap(org.dbflute.helper.StringKeyMap) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 4 with SelectedRelationColumn

use of org.dbflute.cbean.sqlclause.select.SelectedRelationColumn in project dbflute-core by dbflute.

the class SpecifyColumnRequiredChecker method doCheckRelationTable.

protected void doCheckRelationTable(SqlClause sqlClause, Set<String> nonSpecifiedAliasSet) {
    for (Entry<String, Map<String, SelectedRelationColumn>> entry : sqlClause.getSelectedRelationColumnMap().entrySet()) {
        final String tableAliasName = entry.getKey();
        if (!sqlClause.hasSpecifiedSelectColumn(tableAliasName)) {
            // relation table without SpecifyColumn
            final Collection<SelectedRelationColumn> values = entry.getValue().values();
            final String dispName;
            if (!values.isEmpty()) {
                final SelectedRelationColumn firstColumn = values.iterator().next();
                dispName = sqlClause.translateSelectedRelationPathToPropName(firstColumn.getRelationNoSuffix());
            } else {
                // no way, just in case
                dispName = "*no name";
            }
            nonSpecifiedAliasSet.add(dispName + " (" + tableAliasName + ")");
        }
    }
}
Also used : SelectedRelationColumn(org.dbflute.cbean.sqlclause.select.SelectedRelationColumn) Map(java.util.Map)

Aggregations

SelectedRelationColumn (org.dbflute.cbean.sqlclause.select.SelectedRelationColumn)4 Map (java.util.Map)3 LinkedHashMap (java.util.LinkedHashMap)2 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)1 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)1 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)1 StringKeyMap (org.dbflute.helper.StringKeyMap)1