Search in sources :

Example 16 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class DerivedReferrer method setupUnionMainForFixedCondition.

protected void setupUnionMainForFixedCondition(StringBuilder keySb, String tableAliasName, ColumnSqlName derivedColumnSqlName) {
    // all columns because fixed condition might contain them
    final List<ColumnInfo> columnInfoList = _subQueryDBMeta.getColumnInfoList();
    for (ColumnInfo columnInfo : columnInfoList) {
        final ColumnSqlName sqlName = columnInfo.getColumnSqlName();
        if (sqlName.equals(derivedColumnSqlName)) {
            // to suppress same columns selected
            continue;
        }
        final ColumnRealName realName = ColumnRealName.create(tableAliasName, columnInfo.getColumnSqlName());
        keySb.append(keySb.length() > 0 ? ", " : "");
        keySb.append(realName);
    }
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 17 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class DerivedReferrer method buildSubQueryClause.

// ===================================================================================
// (Single PrimaryKey) SubQuery Clause
// ===================================
/**
 * Build the clause of sub-query by single primary key.
 * @param function The expression for deriving function. (NotNull)
 * @param correlatedColumnRealName The real names of correlated column that is main-query table's column. (NotNull)
 * @param relatedColumnSqlName The real names of related column that is sub-query table's column. (NotNull)
 * @param correlatedFixedCondition The fixed condition as correlated condition. (NullAllowed)
 * @param option The option of DerivedReferrer. (NotNull)
 * @return The clause of sub-query. (NotNull)
 */
protected String buildSubQueryClause(String function, ColumnRealName correlatedColumnRealName, ColumnSqlName relatedColumnSqlName, String correlatedFixedCondition, DerivedReferrerOption option) {
    final String tableAliasName = getSubQueryLocalAliasName();
    final ColumnSqlName derivedColumnSqlName = getDerivedColumnSqlName();
    if (derivedColumnSqlName == null) {
        throwDerivedReferrerInvalidColumnSpecificationException(function);
    }
    final ColumnRealName derivedColumnRealName = getDerivedColumnRealName();
    final String subQueryClause;
    if (_subQuerySqlClause.hasUnionQuery()) {
        subQueryClause = buildUnionSubQueryClause(function, correlatedColumnRealName, relatedColumnSqlName, option, tableAliasName, derivedColumnRealName, derivedColumnSqlName, correlatedFixedCondition);
    } else {
        final String selectClause = "select " + buildFunctionPart(function, derivedColumnRealName, option, false);
        final String fromWhereClause;
        if (option.isSuppressCorrelation()) {
            // e.g. myselfDerived
            fromWhereClause = buildPlainFromWhereClause(selectClause, tableAliasName, correlatedFixedCondition);
        } else {
            // basically here
            fromWhereClause = buildCorrelationFromWhereClause(selectClause, tableAliasName, correlatedColumnRealName, relatedColumnSqlName, correlatedFixedCondition);
        }
        subQueryClause = selectClause + " " + fromWhereClause;
    }
    return resolveSubQueryLevelVariable(subQueryClause);
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 18 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class AbstractConditionQuery method registerOrderBy.

// ===================================================================================
// Order By
// ========
// -----------------------------------------------------
// Basic
// -----
protected void registerOrderBy(String columnDbName, boolean ascOrDesc) {
    final DBMeta dbmeta = xgetLocalDBMeta();
    final ColumnInfo columnInfo = dbmeta.findColumnInfo(columnDbName);
    final ColumnRealName columnRealName = toColumnRealName(columnInfo);
    xgetSqlClause().registerOrderBy(columnRealName.toString(), ascOrDesc, columnInfo);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName)

Example 19 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class AbstractConditionQuery method setupConditionValueAndRegisterWhereClause.

protected void setupConditionValueAndRegisterWhereClause(ConditionKey key, Object value, ConditionValue cvalue, String columnDbName, ConditionOption option) {
    final DBMeta dbmeta = xgetLocalDBMeta();
    final ColumnInfo columnInfo = dbmeta.findColumnInfo(columnDbName);
    final QueryModeProvider queryModeProvider = xcreateQueryModeProvider();
    final Object filtered = filterConditionValueIfNeeds(key, value, cvalue, columnDbName, option, columnInfo);
    final String propertyName = columnInfo.getPropertyName();
    final String uncapPropName = initUncap(propertyName);
    // if Java, it is necessary to use uncapPropName
    final String location = xgetLocation(uncapPropName);
    key.setupConditionValue(queryModeProvider, cvalue, filtered, location, option);
    final ColumnRealName columnRealName = toColumnRealName(columnDbName);
    final ColumnFunctionCipher cipher = xgetSqlClause().findColumnFunctionCipher(columnInfo);
    final String usedAliasName = xgetAliasName();
    xgetSqlClause().registerWhereClause(columnRealName, key, cvalue, cipher, option, usedAliasName);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnFunctionCipher(org.dbflute.cbean.cipher.ColumnFunctionCipher) ColumnRealName(org.dbflute.dbmeta.name.ColumnRealName) QueryModeProvider(org.dbflute.cbean.cvalue.ConditionValue.QueryModeProvider)

Example 20 with ColumnRealName

use of org.dbflute.dbmeta.name.ColumnRealName in project dbflute-core by dbflute.

the class AbstractConditionQuery method doRegisterOuterJoin.

protected void doRegisterOuterJoin(ConditionQuery foreignCQ, Map<String, String> joinOnResourceMap, final String foreignPropertyName, ForeignInfo foreignInfo) {
    // translate join-on map using column real name
    final Map<ColumnRealName, ColumnRealName> joinOnMap = newLinkedHashMap();
    for (Entry<String, String> entry : joinOnResourceMap.entrySet()) {
        final String local = entry.getKey();
        final String foreign = entry.getValue();
        joinOnMap.put(toColumnRealName(local), foreignCQ.toColumnRealName(foreign));
    }
    final String foreignAlias = foreignCQ.xgetAliasName();
    final String foreignTable = foreignCQ.asTableDbName();
    final String localAlias = xgetAliasName();
    final String localTable = asTableDbName();
    final String fixedCondition = foreignInfo.getFixedCondition();
    final boolean fixedInline = foreignInfo.isFixedInline();
    final FixedConditionResolver resolver = createForeignFixedConditionResolver(foreignCQ);
    final String relationPath = foreignCQ.xgetRelationPath();
    if (fixedInline) {
        // basic
        xgetSqlClause().registerOuterJoinFixedInline(// basic
        foreignAlias, // basic
        foreignTable, // basic
        localAlias, // basic
        localTable, // join objects
        joinOnMap, // join objects
        relationPath, // join objects
        foreignInfo, fixedCondition, // fixed condition (to in-line view)
        resolver);
    } else {
        // normally here
        // basic
        xgetSqlClause().registerOuterJoin(// basic
        foreignAlias, // basic
        foreignTable, // basic
        localAlias, // basic
        localTable, // join objects
        joinOnMap, // join objects
        relationPath, // join objects
        foreignInfo, fixedCondition, // fixed condition (to on-clause)
        resolver);
    }
    xprepareFixedConditionDynamicParameterLazyChecker(foreignPropertyName, foreignInfo);
}
Also used : FixedConditionResolver(org.dbflute.cbean.sqlclause.join.FixedConditionResolver) 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