Search in sources :

Example 11 with ColumnRealName

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);
}
Also used : ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName) QueryClause(org.dbflute.cbean.sqlclause.query.QueryClause) OrScopeQueryAndPartQueryClause(org.dbflute.cbean.sqlclause.query.OrScopeQueryAndPartQueryClause) StringQueryClause(org.dbflute.cbean.sqlclause.query.StringQueryClause)

Example 12 with ColumnRealName

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;
}
Also used : ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 13 with ColumnRealName

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;
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 14 with ColumnRealName

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);
}
Also used : ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 15 with ColumnRealName

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);
}
Also used : ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Aggregations

ColumnRealName (org.dbflute.dbmeta.name.ColumnRealName)21 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)8 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)5 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)2 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)2 OrScopeQueryAndPartQueryClause (org.dbflute.cbean.sqlclause.query.OrScopeQueryAndPartQueryClause)2 QueryClause (org.dbflute.cbean.sqlclause.query.QueryClause)2 StringQueryClause (org.dbflute.cbean.sqlclause.query.StringQueryClause)2 DBMeta (org.dbflute.dbmeta.DBMeta)2 ArrayList (java.util.ArrayList)1 GearedCipherManager (org.dbflute.cbean.cipher.GearedCipherManager)1 QueryModeProvider (org.dbflute.cbean.cvalue.ConditionValue.QueryModeProvider)1 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)1 FixedConditionResolver (org.dbflute.cbean.sqlclause.join.FixedConditionResolver)1 OnQueryStringConnector (org.dbflute.dbway.OnQueryStringConnector)1 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)1