use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.
the class AbstractSqlClause method registerBaseTableInlineWhereClause.
// ===================================================================================
// In-line Where
// =============
// -----------------------------------------------------
// In-line for Base Table
// ----------------------
public // SQL name of column
void registerBaseTableInlineWhereClause(// SQL name of column
ColumnSqlName columnSqlName, // basic resources
ConditionKey key, // basic resources
ConditionValue value, ColumnFunctionCipher cipher, ConditionOption option) {
// optional resources
final List<QueryClause> clauseList = getBaseTableInlineWhereClauseList4Register();
final String inlineBaseAlias = getInlineViewBasePointAlias();
final ColumnRealName columnRealName = ColumnRealName.create(inlineBaseAlias, columnSqlName);
doRegisterWhereClause(clauseList, columnRealName, key, value, cipher, option, true, false);
}
use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.
the class ScalarCondition method buildUnionSubQuerySql.
// ===================================================================================
// Union Handling
// ==============
protected // basic
String buildUnionSubQuerySql(// basic
String function, // basic
String tableAliasName, // derived
ColumnSqlName derivedColumnSqlName, // derived
ColumnRealName derivedColumnRealName, // partition-by
ColumnRealName partitionByCorrelatedColumnRealName, // partition-by
ColumnSqlName partitionByRelatedColumnSqlName, ScalarConditionOption option) {
final String beginMark = resolveSubQueryBeginMark(_mainSubQueryIdentity) + ln();
final String endMark = resolveSubQueryEndMark(_mainSubQueryIdentity);
final String mainSql = buildUnionMainPartClause(partitionByRelatedColumnSqlName, tableAliasName, derivedColumnRealName, derivedColumnSqlName);
final String mainAlias = buildSubQueryMainAliasName();
String whereJoinCondition = "";
if (partitionByRelatedColumnSqlName != null) {
final ColumnRealName relatedColumnRealName = ColumnRealName.create(mainAlias, partitionByRelatedColumnSqlName);
final StringBuilder sb = new StringBuilder();
sb.append(ln()).append(" where ");
sb.append(relatedColumnRealName).append(" = ").append(partitionByCorrelatedColumnRealName);
// correlation
whereJoinCondition = sb.toString();
}
// before making scalar condition option
// {
// final ColumnSqlName pkSqlName = _subQueryDBMeta.getPrimaryInfo().getFirstColumn().getColumnSqlName();
// final ColumnRealName pkRealName = ColumnRealName.create(tableAliasName, pkSqlName);
// final String selectClause = "select " + pkRealName + ", " + derivedColumnRealName;
// final String fromWhereClause =
// buildFromWhereClause(selectClause, tableAliasName, partitionByCorrelatedColumnRealName, partitionByRelatedColumnSqlName);
// mainSql = selectClause + " " + fromWhereClause;
// }
final ColumnRealName mainDerivedColumnRealName = ColumnRealName.create(mainAlias, derivedColumnSqlName);
return // select
"select " + buildFunctionPart(function, mainDerivedColumnRealName, option, true) + ln() + " from (" + beginMark + mainSql + ln() + " ) " + mainAlias + // from
endMark + whereJoinCondition;
}
use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.
the class ScalarCondition method buildScalarCondition.
// ===================================================================================
// Build Clause
// ============
public String buildScalarCondition(String function, ScalarConditionOption option) {
setupOptionAttribute(option);
// get the specified column before it disappears at sub-query making.
final ColumnRealName columnRealName;
{
final String columnDbName = _subQuerySqlClause.getSpecifiedColumnDbNameAsOne();
if (columnDbName == null || columnDbName.trim().length() == 0) {
throwScalarConditionInvalidColumnSpecificationException(function);
}
columnRealName = _localRealNameProvider.provide(columnDbName);
}
final String subQueryClause = buildSubQueryClause(function, option);
final String beginMark = resolveSubQueryBeginMark(_subQueryIdentity) + ln();
final String endMark = resolveSubQueryEndMark(_subQueryIdentity);
final String endIndent = " ";
final ColumnInfo columnInfo = _subQuerySqlClause.getSpecifiedColumnInfoAsOne();
final String specifiedExp = decrypt(columnInfo, columnRealName.toString());
return // left and operand
specifiedExp + " " + _operand + " (" + beginMark + subQueryClause + ln() + endIndent + ") " + // right
endMark;
}
use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.
the class DerivedReferrer method buildUnionSubQueryClause.
// -----------------------------------------------------
// (Single PrimaryKey) Union Handling
// ----------------------------------
protected String buildUnionSubQueryClause(String function, ColumnRealName correlatedColumnRealName, ColumnSqlName relatedColumnSqlName, DerivedReferrerOption option, String tableAliasName, ColumnRealName derivedColumnRealName, ColumnSqlName derivedColumnSqlName, String correlatedFixedCondition) {
final String mainSql = buildUnionMainPartClause(relatedColumnSqlName, tableAliasName, derivedColumnRealName, derivedColumnSqlName, correlatedFixedCondition);
final String mainAlias = buildSubQueryMainAliasName();
final String whereJoinCondition;
if (option.isSuppressCorrelation()) {
// e.g. myselfDerived
whereJoinCondition = "";
} else {
// mainly here
final ColumnRealName relatedColumnRealName = ColumnRealName.create(mainAlias, relatedColumnSqlName);
final StringBuilder sb = new StringBuilder();
sb.append(ln()).append(" where ");
sb.append(relatedColumnRealName).append(" = ").append(correlatedColumnRealName);
if (isFixedCondition(correlatedFixedCondition)) {
sb.append(ln()).append(" and ");
sb.append(Srl.replace(correlatedFixedCondition, tableAliasName + ".", mainAlias + "."));
}
// correlation
whereJoinCondition = sb.toString();
}
final ColumnRealName mainDerivedColumnRealName = ColumnRealName.create(mainAlias, derivedColumnSqlName);
return doBuildUnionSubQueryClause(function, option, mainSql, mainAlias, whereJoinCondition, mainDerivedColumnRealName);
}
use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.
the class DerivedReferrer method buildUnionSubQueryClause.
// -----------------------------------------------------
// (Compound PrimaryKey) Union Handling
// ------------------------------------
protected String buildUnionSubQueryClause(String function, ColumnRealName[] correlatedColumnRealNames, ColumnSqlName[] relatedColumnSqlNames, DerivedReferrerOption option, String tableAliasName, ColumnRealName derivedColumnRealName, ColumnSqlName derivedColumnSqlName, String correlatedFixedCondition) {
final String mainSql = buildUnionMainPartClause(correlatedColumnRealNames, relatedColumnSqlNames, tableAliasName, derivedColumnRealName, derivedColumnSqlName, correlatedFixedCondition);
final String mainAlias = buildSubQueryMainAliasName();
final String whereJoinCondition;
if (option.isSuppressCorrelation()) {
// e.g. myselfDerived
whereJoinCondition = "";
} else {
// mainly here
final StringBuilder sb = new StringBuilder();
sb.append(ln()).append(" where ");
for (int i = 0; i < correlatedColumnRealNames.length; i++) {
if (i > 0) {
sb.append(ln()).append(" and ");
}
sb.append(ColumnRealName.create(mainAlias, relatedColumnSqlNames[i]));
sb.append(" = ").append(correlatedColumnRealNames[i]);
}
if (isFixedCondition(correlatedFixedCondition)) {
if (correlatedColumnRealNames.length > 0) {
// basically true (but just in case)
sb.append(ln()).append(" and ");
}
sb.append(Srl.replace(correlatedFixedCondition, tableAliasName + ".", mainAlias + "."));
}
// correlation
whereJoinCondition = sb.toString();
}
final ColumnRealName mainDerivedColumnRealName = ColumnRealName.create(mainAlias, derivedColumnSqlName);
return doBuildUnionSubQueryClause(function, option, mainSql, mainAlias, whereJoinCondition, mainDerivedColumnRealName);
}
Aggregations