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);
}
}
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;
}
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;
}
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 + ")");
}
}
}
Aggregations